From 40a8384e1ed7b7af237c7963813642dbb033368f Mon Sep 17 00:00:00 2001 From: joBr99 <29555657+joBr99@users.noreply.github.com> Date: Wed, 23 Mar 2022 11:25:21 +0100 Subject: [PATCH 01/11] Migrate to new buttonPress cmd format --- ioBroker/NsPanelTs.ts | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/ioBroker/NsPanelTs.ts b/ioBroker/NsPanelTs.ts index 7447448c..1c4e207f 100644 --- a/ioBroker/NsPanelTs.ts +++ b/ioBroker/NsPanelTs.ts @@ -161,7 +161,7 @@ function HandleMessage(typ: string, method: string, page: number, words: Array Date: Wed, 23 Mar 2022 22:08:25 +0100 Subject: [PATCH 02/11] Update NsPanelTs.ts Update HandleMessage function to switch Fix tempupd --- ioBroker/NsPanelTs.ts | 62 +++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/ioBroker/NsPanelTs.ts b/ioBroker/NsPanelTs.ts index 1c4e207f..d83ee005 100644 --- a/ioBroker/NsPanelTs.ts +++ b/ioBroker/NsPanelTs.ts @@ -92,8 +92,6 @@ export const config: Config = { button2Page: button2Page }; - - var subscriptions: any = {}; var pageId = 0; @@ -149,28 +147,29 @@ function SendToPanel(val: Payload | Payload[]): void { function HandleMessage(typ: string, method: string, page: number, words: Array): void { if (typ == "event") { - var pageNum = (page % config.pages.length); - pageId = Math.abs(pageNum); - if (method == 'pageOpen' || method == 'startup') { - UnsubscribeWatcher(); - - if (method == 'startup') + switch (method) { + case "pageOpen": + var pageNum = (page % config.pages.length); + pageId = Math.abs(pageNum); + UnsubscribeWatcher(); + GeneratePage(config.pages[pageId]); + break; + case "startup": + UnsubscribeWatcher(); HandleStartupProcess(); - - GeneratePage(config.pages[pageId]); - } - - if (method == 'buttonPress2') { - HandleButtonEvent(words) - } - - if (method == 'screensaverOpen') { - HandleScreensaver() - } - - if (method == 'button1' || method == 'button2') { - HandleHardwareButton(method); + break; + case "buttonPress2": + HandleButtonEvent(words); + break; + case "screensaverOpen": + HandleScreensaver(); + break; + case "button1": + case "button2": + HandleHardwareButton(method); + default: + break; } } } @@ -276,11 +275,11 @@ function CreateEntity(pageItem: PageItem, placeId: number, useColors: boolean = if (existsState(pageItem.id + ".GET")) { val = getState(pageItem.id + ".GET").val; - RegisterEntityWatcher(pageItem.id + ".GET", pageItem.id, placeId); + RegisterEntityWatcher(pageItem.id + ".GET"); } else if (existsState(pageItem.id + ".SET")) { val = getState(pageItem.id + ".SET").val; - RegisterEntityWatcher(pageItem.id + ".SET", pageItem.id, placeId); + RegisterEntityWatcher(pageItem.id + ".SET"); } var iconColor = rgb_dec565(config.defaultColor); @@ -303,11 +302,11 @@ function CreateEntity(pageItem: PageItem, placeId: number, useColors: boolean = var optVal = "0" if (existsState(pageItem.id + ".ON_ACTUAL")) { val = getState(pageItem.id + ".ON_ACTUAL").val; - RegisterEntityWatcher(pageItem.id + ".ON_ACTUAL", pageItem.id, placeId); + RegisterEntityWatcher(pageItem.id + ".ON_ACTUAL"); } else if (existsState(pageItem.id + ".ON_SET")) { val = getState(pageItem.id + ".ON_SET").val; - RegisterEntityWatcher(pageItem.id + ".ON_SET", pageItem.id, placeId); + RegisterEntityWatcher(pageItem.id + ".ON_SET"); } if (val === true || val === "true") { optVal = "1" @@ -331,12 +330,12 @@ function CreateEntity(pageItem: PageItem, placeId: number, useColors: boolean = if (existsState(pageItem.id + ".ON_ACTUAL")) { optVal = getState(pageItem.id + ".ON_ACTUAL").val; unit = GetUnitOfMeasurement(pageItem.id + ".ON_ACTUAL"); - RegisterEntityWatcher(pageItem.id + ".ON_ACTUAL", pageItem.id, placeId); + RegisterEntityWatcher(pageItem.id + ".ON_ACTUAL"); } else if (existsState(pageItem.id + ".ACTUAL")) { optVal = getState(pageItem.id + ".ACTUAL").val; unit = GetUnitOfMeasurement(pageItem.id + ".ACTUAL"); - RegisterEntityWatcher(pageItem.id + ".ACTUAL", pageItem.id, placeId); + RegisterEntityWatcher(pageItem.id + ".ACTUAL"); } if (o.common.role == "value.temperature") { @@ -384,11 +383,12 @@ function GetIconColor(pageItem: PageItem, value: (boolean | number), useColors: return rgb_dec565(pageItem.offColor !== undefined ? pageItem.offColor : config.defaultOffColor); } -function RegisterEntityWatcher(id: string, entityId: string, placeId: number): void { +function RegisterEntityWatcher(id: string): void { if (subscriptions.hasOwnProperty(id)) { return; } subscriptions[id] = (on({ id: id, change: 'any' }, function (data) { + log("RegisterEntityWatcher PageId:" + pageId.toString()) GeneratePage(config.pages[pageId]); })) } @@ -517,7 +517,7 @@ function HandleButtonEvent(words): void { // if (words[6] == "colorTempSlider") // out_msgs.push({ payload: id, action: "turn_on", domain: "lightTemperature", temperature: parseInt(words[7]) }) if (words[3] == "tempUpd") { - setState(words[3] + ".SET", parseInt(words[4]) / 10) + setState(id + ".SET", parseInt(words[4]) / 10) } } @@ -808,4 +808,4 @@ type Config = { pages: (PageThermo | PageEntities | PageGrid)[], button1Page: (PageThermo | PageEntities | PageGrid | null), button2Page: (PageThermo | PageEntities | PageGrid | null), -}; +}; \ No newline at end of file From 0603e26dae66cc996ce91926f4ab00dbd66ce83b Mon Sep 17 00:00:00 2001 From: joBr99 <29555657+joBr99@users.noreply.github.com> Date: Thu, 24 Mar 2022 14:56:48 +0100 Subject: [PATCH 03/11] Update README.md --- HMI/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HMI/README.md b/HMI/README.md index 6be70ec0..749540e0 100644 --- a/HMI/README.md +++ b/HMI/README.md @@ -117,7 +117,7 @@ The following message can be used to update the content on the cardEntities Page `entityUpdateDetail,*internalName*,*tHeading*,*tHeadingColor*,*b1*,*tB1Color*,*b2*,*tB2Color*,*tText*,*tTextColor*,*sleepTimeout*` -`popupExit` +`exitPopup` ### cardThermo Page From d3f0a3a5bc48ebe0bef26a8220e0d15cdb187a58 Mon Sep 17 00:00:00 2001 From: Gerard Date: Thu, 24 Mar 2022 16:08:21 +0100 Subject: [PATCH 04/11] Add name as config item See FR #58 --- apps/nspanel-lovelace-ui/nspanel-lovelace-ui.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/nspanel-lovelace-ui/nspanel-lovelace-ui.py b/apps/nspanel-lovelace-ui/nspanel-lovelace-ui.py index 93f24efb..bbcdb0c8 100644 --- a/apps/nspanel-lovelace-ui/nspanel-lovelace-ui.py +++ b/apps/nspanel-lovelace-ui/nspanel-lovelace-ui.py @@ -433,8 +433,10 @@ class LovelaceUIPanel: def generate_entities_item(self, item): icon = None + name = None if type(item) is dict: - icon = next(iter(item.items()))[1]['icon'] + icon = next(iter(item.items()))[1].get('icon') + name = next(iter(item.items()))[1].get('name') item = next(iter(item.items()))[0] # type of the item is the string before the "." in the item name @@ -449,7 +451,7 @@ class LovelaceUIPanel: return f",text,{item},{get_icon_id('alert-circle-outline')},17299,Not found check, apps.yaml" entity = self.api.get_entity(item) - name = entity.attributes.friendly_name + name = name if name is not None else entity.attributes.friendly_name if item_type == "cover": icon_id = get_icon_id_ha("cover", state=entity.state, overwrite=icon) From 3c2f5646c93e5bb44137eee69ba45fee98e89f93 Mon Sep 17 00:00:00 2001 From: Gerard Date: Thu, 24 Mar 2022 16:10:06 +0100 Subject: [PATCH 05/11] Update README.md --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6942c5f6..bb3a4fdb 100644 --- a/README.md +++ b/README.md @@ -309,9 +309,9 @@ key | optional | type | default | description `class` | False | string | | The name of the Class. `config` | False | complex | | Config/Mapping between Homeassistant and your NsPanel -### Override Icons +### Override Icons or Names -To override Icons of entities you can configure an icon name in your configuration, please see the following example. +To override Icons or Names of entities you can configure an icon or name in your configuration, please see the following example. Only the icons listed in the [Icon Table](HMI#icons-ids) are useable. ```yaml @@ -322,6 +322,7 @@ Only the icons listed in the [Icon Table](HMI#icons-ids) are useable. - light.schreibtischlampe - switch.deckenbeleuchtung_hinten: icon: lightbulb + name: Lampe - delete - delete - type: cardMedia From 4464736b478719eccffac5e599a62d21226d31bc Mon Sep 17 00:00:00 2001 From: Gerard Date: Thu, 24 Mar 2022 16:11:06 +0100 Subject: [PATCH 06/11] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bb3a4fdb..9a620bff 100644 --- a/README.md +++ b/README.md @@ -311,7 +311,7 @@ key | optional | type | default | description ### Override Icons or Names -To override Icons or Names of entities you can configure an icon or name in your configuration, please see the following example. +To override Icons or Names of entities you can configure an icon and/or name in your configuration, please see the following example. Only the icons listed in the [Icon Table](HMI#icons-ids) are useable. ```yaml From b0937d0ba73b166612cb3dc73ea5e276621558e9 Mon Sep 17 00:00:00 2001 From: joBr99 <29555657+joBr99@users.noreply.github.com> Date: Thu, 24 Mar 2022 17:24:47 +0100 Subject: [PATCH 07/11] fixes #61 --- apps/nspanel-lovelace-ui/nspanel-lovelace-ui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/nspanel-lovelace-ui/nspanel-lovelace-ui.py b/apps/nspanel-lovelace-ui/nspanel-lovelace-ui.py index bbcdb0c8..cc6f83f5 100644 --- a/apps/nspanel-lovelace-ui/nspanel-lovelace-ui.py +++ b/apps/nspanel-lovelace-ui/nspanel-lovelace-ui.py @@ -412,7 +412,7 @@ class LovelaceUIPanel: if btype == "tempUpd": temp = int(optVal)/10 - self.api.get_entity(msg[3]).call_service("set_temperature", temperature=temp) + self.api.get_entity(entity_id).call_service("set_temperature", temperature=temp) def generate_page(self, page_number): # get type of page From db50f94fb44d94871a64678566111034cd1057e2 Mon Sep 17 00:00:00 2001 From: Gerard Date: Thu, 24 Mar 2022 19:42:48 +0100 Subject: [PATCH 08/11] Add language settings Make `PRESS` and `ACTIVATE` text configurable --- apps/nspanel-lovelace-ui/nspanel-lovelace-ui.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/apps/nspanel-lovelace-ui/nspanel-lovelace-ui.py b/apps/nspanel-lovelace-ui/nspanel-lovelace-ui.py index cc6f83f5..4bb096d7 100644 --- a/apps/nspanel-lovelace-ui/nspanel-lovelace-ui.py +++ b/apps/nspanel-lovelace-ui/nspanel-lovelace-ui.py @@ -84,7 +84,10 @@ class LovelaceUIPanel: self.config = config self.current_page_nr = 0 self.current_screensaver_brightness = 10 - + + self.button_text = self.config.get("buttonText", "PRESS") + self.scene_text = self.config.get("sceneText", "ACTIVATE") + # check configured items self.check_items() @@ -478,11 +481,11 @@ class LovelaceUIPanel: if item_type in ["button", "input_button"]: icon_id = get_icon_id_ha("button", overwrite=icon) - return f",button,{item},{icon_id},17299,{name},PRESS" + return f",button,{item},{icon_id},17299,{name},{self.button_text}" if item_type == "scene": icon_id = get_icon_id_ha("scene", overwrite=icon) - return f",button,{item},{icon_id},17299,{name},ACTIVATE" + return f",button,{item},{icon_id},17299,{name},{self.scene_text}" def generate_entities_page(self, items): # Set Heading of Page From 9584261021a351f0e445ee0a0046e34670eb0ed7 Mon Sep 17 00:00:00 2001 From: Gerard Date: Thu, 24 Mar 2022 19:45:18 +0100 Subject: [PATCH 09/11] Add config options for buttons and scenes --- appdaemon/apps.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/appdaemon/apps.yaml b/appdaemon/apps.yaml index 629e2f8a..be26ca3c 100644 --- a/appdaemon/apps.yaml +++ b/appdaemon/apps.yaml @@ -18,6 +18,8 @@ nspanel: # formatting options on https://babel.pocoo.org/en/latest/dates.html?highlight=name%20of%20day#date-fields timeFormat: "%H:%M" dateFormat: "%A, %d. %B %Y" # ignored if babel python package is installed + buttonText: KLICKEN + sceneText: ACTIVIEREN weatherEntity: weather.example pages: - type: cardEntities From 7d85e139c8134cdb7f320038b31c2aa28a11864a Mon Sep 17 00:00:00 2001 From: Gerard Date: Thu, 24 Mar 2022 20:07:36 +0100 Subject: [PATCH 10/11] Add icon_color for binary sensor Blue when `off` and yellow when `on` Not sure about the colors though, but at least it's nice to show different icon colors based on the state --- apps/nspanel-lovelace-ui/nspanel-lovelace-ui.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/nspanel-lovelace-ui/nspanel-lovelace-ui.py b/apps/nspanel-lovelace-ui/nspanel-lovelace-ui.py index cc6f83f5..aa6bf842 100644 --- a/apps/nspanel-lovelace-ui/nspanel-lovelace-ui.py +++ b/apps/nspanel-lovelace-ui/nspanel-lovelace-ui.py @@ -463,7 +463,7 @@ class LovelaceUIPanel: icon_id = get_icon_id_ha("light", overwrite=icon) return f",{item_type},{item},{icon_id},{icon_color},{name},{switch_val}" - if item_type == "switch" or item_type == "input_boolean": + if item_type in ["switch", "input_boolean"]: icon_id = get_icon_id_ha(item_type, state=entity.state, overwrite=icon) switch_val = 1 if entity.state == "on" else 0 icon_color = self.getEntityColor(entity) @@ -474,7 +474,8 @@ class LovelaceUIPanel: icon_id = get_icon_id_ha("sensor", state=entity.state, device_class=device_class, overwrite=icon) unit_of_measurement = self.get_safe_ha_attribute(entity.attributes, "unit_of_measurement", "") value = entity.state + " " + unit_of_measurement - return f",text,{item},{icon_id},17299,{name},{value}" + icon_color = self.getEntityColor(entity) + return f",text,{item},{icon_id},{icon_color},{name},{value}" if item_type in ["button", "input_button"]: icon_id = get_icon_id_ha("button", overwrite=icon) From 67bc30f090bb48ef4c715f761799c91d2257f025 Mon Sep 17 00:00:00 2001 From: Gerard Date: Thu, 24 Mar 2022 20:20:14 +0100 Subject: [PATCH 11/11] Show alert icon instead of shutter icon When no mediaplayer is found --- apps/nspanel-lovelace-ui/nspanel-lovelace-ui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/nspanel-lovelace-ui/nspanel-lovelace-ui.py b/apps/nspanel-lovelace-ui/nspanel-lovelace-ui.py index 2b75be1e..b4156658 100644 --- a/apps/nspanel-lovelace-ui/nspanel-lovelace-ui.py +++ b/apps/nspanel-lovelace-ui/nspanel-lovelace-ui.py @@ -560,7 +560,7 @@ class LovelaceUIPanel: def generate_media_page(self, item): if not self.api.entity_exists(item): - command = f"entityUpd,|{item}|Not found|{get_icon_id('alert-circle-outline')}|Please check your|apps.yaml in AppDaemon|50|11" + command = f"entityUpd,|{item}|Not found|{get_icon_id('alert-circle-outline')}|Please check your|apps.yaml in AppDaemon|50|{get_icon_id('alert-circle-outline')}" else: entity = self.api.get_entity(item) heading = entity.attributes.friendly_name