From 410e5182932353b496f81486df808f52a528ab3c Mon Sep 17 00:00:00 2001 From: joBr99 <29555657+joBr99@users.noreply.github.com> Date: Sat, 2 Apr 2022 19:43:09 +0200 Subject: [PATCH] alternaitve layout screensaver --- README.md | 39 +++++++++-- appdaemon/apps.yaml | 41 +++++++++-- apps/nspanel-lovelace-ui/luibackend/config.py | 5 +- .../luibackend/controller.py | 10 +-- apps/nspanel-lovelace-ui/luibackend/pages.py | 24 ++++--- info.md | 70 +------------------ 6 files changed, 94 insertions(+), 95 deletions(-) diff --git a/README.md b/README.md index 4ebdab2a..06339a3d 100644 --- a/README.md +++ b/README.md @@ -250,7 +250,7 @@ Please see [appdaemon.yaml](appdaemon/appdaemon.yaml) as an exmaple. ### Configure your NSPanel in AppDaemon Confiure your NSPanel as you like, you need to edit the `apps.yaml` inside of your Appdaemon config folder. -You can have multiple nspanel sections. +You can have multiple nspanel sections. There are some more exmaples in the appdaemon folder of this repo. ```yaml --- @@ -270,19 +270,45 @@ nspanel-1: value: 0 locale: "de_DE" # used for translations in translations.py and for localized date if babel python package is installed screensaver: - weather: weather.k3ll3r + entity: weather.k3ll3r cards: - type: cardEntities entities: - - entity: light.example_item + - entity: switch.example_item name: NameOverride + icon: lightbulb - entity: light.example_item - title: Example Entities + - entity: cover.example_item + - entity: input_boolean.example_item + title: Example Entities 1 + - type: cardEntities + entities: + - entity: switch.example_item + - entity: delete + - entity: cover.example_item + - entity: input_boolean.example_item + title: Example Entities 2 + - type: cardEntities + entities: + - entity: binary_sensor.example_item + - entity: sensor.example_item + - entity: button.example_item + - entity: number.example_item + title: Example Entities 3 + - type: cardEntities + entities: + - entity: scenes.example_item + - entity: script.example_item + - entity: button.example_item + - entity: input_button.example_item + title: Example Entities 4 - type: cardGrid entities: - - entity: select.example_item - - entity: select.example_item - entity: light.example_item + - entity: switch.example_item + - entity: delete + - entity: button.example_item + - entity: cover.example_item title: Exmaple Gird - type: cardThermo entity: climate.example_item @@ -338,6 +364,7 @@ key | optional | type | default | description `weatherOverrideForecast3` | True | string | `None` | sensor entity from home assistant here to override the third weather forecast item on the screensaver `weatherOverrideForecast4` | True | string | `None` | sensor entity from home assistant here to override the forth weather forecast item on the screensaver `doubleTapToUnlock` | True | boolean | `False` | requires to tap screensaver two times +`alternativeLayout` | True | boolean | `False` | alternative layout with humidity `key` | True | string | `None` | Used by navigate items #### Schedule sleep brightness diff --git a/appdaemon/apps.yaml b/appdaemon/apps.yaml index 312ce1d3..5fd53fff 100644 --- a/appdaemon/apps.yaml +++ b/appdaemon/apps.yaml @@ -15,19 +15,50 @@ nspanel-1: value: 0 locale: "de_DE" # used for translations in translations.py and for localized date if babel python package is installed screensaver: - weather: weather.k3ll3r + entity: weather.k3ll3r + weatherOverrideForecast4: + entity: sensor.example_item + name: name + icon: lightbulb + alternativeLayout: True cards: - type: cardEntities entities: - - entity: light.example_item + - entity: switch.example_item name: NameOverride + icon: lightbulb - entity: light.example_item - title: Example Entities + - entity: cover.example_item + - entity: input_boolean.example_item + title: Example Entities 1 + - type: cardEntities + entities: + - entity: switch.example_item + - entity: delete + - entity: cover.example_item + - entity: input_boolean.example_item + title: Example Entities 2 + - type: cardEntities + entities: + - entity: binary_sensor.example_item + - entity: sensor.example_item + - entity: button.example_item + - entity: number.example_item + title: Example Entities 3 + - type: cardEntities + entities: + - entity: scenes.example_item + - entity: script.example_item + - entity: button.example_item + - entity: input_button.example_item + title: Example Entities 4 - type: cardGrid entities: - - entity: select.example_item - - entity: select.example_item - entity: light.example_item + - entity: switch.example_item + - entity: delete + - entity: button.example_item + - entity: cover.example_item title: Exmaple Gird - type: cardThermo entity: climate.example_item diff --git a/apps/nspanel-lovelace-ui/luibackend/config.py b/apps/nspanel-lovelace-ui/luibackend/config.py index f60ff83a..ef841f26 100644 --- a/apps/nspanel-lovelace-ui/luibackend/config.py +++ b/apps/nspanel-lovelace-ui/luibackend/config.py @@ -77,13 +77,14 @@ class LuiBackendConfig(object): }], 'screensaver': { 'type': 'screensaver', - 'weather': 'weather.example', + 'entity': 'weather.example', 'weatherUnit': 'celsius', 'weatherOverrideForecast1': None, 'weatherOverrideForecast2': None, 'weatherOverrideForecast3': None, 'weatherOverrideForecast4': None, - 'doubleTapToUnlock': False + 'doubleTapToUnlock': False, + 'alternativeLayout': False }, 'hiddenCards': [] } diff --git a/apps/nspanel-lovelace-ui/luibackend/controller.py b/apps/nspanel-lovelace-ui/luibackend/controller.py index 2c262fba..3a9f6994 100644 --- a/apps/nspanel-lovelace-ui/luibackend/controller.py +++ b/apps/nspanel-lovelace-ui/luibackend/controller.py @@ -36,14 +36,14 @@ class LuiController(object): self.register_callbacks() # register callbacks for each time - if type(self._config.get("brightnessScreensaver")) == list: - for index, timeset in enumerate(self._config.get("brightnessScreensaver")): + if type(self._config.get("sleepBrightness")) == list: + for index, timeset in enumerate(self._config.get("sleepBrightness")): self._ha_api.run_daily(self.update_screensaver_brightness, timeset["time"], value=timeset["value"]) # calculate current brightness self.current_screensaver_brightness = self.calc_current_screensaver_brightness() # call update_screensaver_brightness on changes of entity configured in brightnessScreensaverTracking - bst = self._config.get("brightnessScreensaverTracking") + bst = self._config.get("sleepTracking") if bst is not None and self._ha_api.entity_exists(bst): self._ha_api.listen_state(self.update_screensaver_brightness_state_callback, entity_id=bst) @@ -54,7 +54,7 @@ class LuiController(object): self._pages_gen.update_date("") # set screensaver timeout - timeout = self._config.get("timeoutScreensaver") + timeout = self._config.get("sleepTimeout") self._send_mqtt_msg(f"timeout~{timeout}") # set current screensaver brightness @@ -142,7 +142,7 @@ class LuiController(object): self._pages_gen.generate_screensaver_page() return - if button_type in ["bExit", "bUp"]: + if button_type in ["bExit", "bUp"]: self._pages_gen.render_card(self._current_card) if button_type == "bNext": diff --git a/apps/nspanel-lovelace-ui/luibackend/pages.py b/apps/nspanel-lovelace-ui/luibackend/pages.py index 62e2d19d..9dfd169f 100644 --- a/apps/nspanel-lovelace-ui/luibackend/pages.py +++ b/apps/nspanel-lovelace-ui/luibackend/pages.py @@ -61,8 +61,9 @@ class LuiPagesGen(object): def update_screensaver_weather(self): global babel_spec - we_name = self._config.get("screensaver.weather") - unit = self._config.get("screensaver.weatherUnit") + screensaver_config = self._config._config_screensaver + we_name = self._config._config_screensaver.entity.entityId + unit = self._config._config_screensaver.raw_config.get("weatherUnit", "celsius") if self._ha_api.entity_exists(we_name): we = self._ha_api.get_entity(we_name) @@ -75,7 +76,7 @@ class LuiPagesGen(object): weather_res = "" for i in range(1,5): - wOF = self._config.get(f"screensaver.weatherOverrideForecast{i}") + wOF = self._config._config_screensaver.raw_config.get(f"weatherOverrideForecast{i}") if wOF is None: up = we.attributes.forecast[i-1]['datetime'] up = datetime.datetime.fromisoformat(up) @@ -87,16 +88,20 @@ class LuiPagesGen(object): down = convert_temperature(we.attributes.forecast[i-1]['temperature'], unit) else: LOGGER.info(f"Forecast {i} is overriden with {wOF}") - icon = wOF.iconOverride - name = wOF.nameOverride - entity = self._ha_api.get_entity(wOF.entityId) + icon = wOF.get("icon") + name = wOF.get("name") + entity = self._ha_api.get_entity(wOF.get("entity")) up = name if name is not None else entity.attributes.friendly_name icon = get_icon_id_ha("sensor", state=entity.state, device_class=entity.attributes.get("device_class", ""), overwrite=icon) unit_of_measurement = entity.attributes.get("unit_of_measurement", "") down = f"{entity.state} {unit_of_measurement}" weather_res+=f"~{up}~{icon}~{down}" - self._send_mqtt_msg(f"weatherUpdate~{icon_cur}~{text_cur}{weather_res}") + altLayout = "" + if self._config._config_screensaver.raw_config.get("alternativeLayout", False) is True: + altLayout = f"~26~{we.attributes.humidity} %" + + self._send_mqtt_msg(f"weatherUpdate~{icon_cur}~{text_cur}{weather_res}{altLayout}") def generate_entities_item(self, entity): entityId = entity.entityId @@ -326,7 +331,10 @@ class LuiPagesGen(object): def render_card(self, card, send_page_type=True): LOGGER.info(f"Started rendering of page {card.pos} with type {card.cardType}") - navigation = "1|1" + if len(self._config._config_cards) == 1: + navigation = "0|0" + else: + navigation = "1|1" if card.pos is None: navigation = "2|0" # Switch to page diff --git a/info.md b/info.md index ac599812..1486e7c0 100644 --- a/info.md +++ b/info.md @@ -2,72 +2,4 @@ Checkout [README](https://github.com/joBr99/nspanel-lovelace-ui/blob/main/README.md) for detailed Instructions. -### App Configuration - -```yaml ---- -nspanel-1: - module: nspanel-lovelace-ui - class: NsPanelLovelaceUIManager - config: - panelRecvTopic: "tele/tasmota_your_mqtt_topic/RESULT" - panelSendTopic: "cmnd/tasmota_your_mqtt_topic/CustomSend" - updateMode: "auto-notify" - timeoutScreensaver: 20 - #brightnessScreensaver: 10 - brightnessScreensaver: - - time: "7:00:00" - value: 10 - - time: "23:00:00" - value: 0 - locale: "de_DE" # only used if babel python package is installed - dateFormatBabel: "full" # only used if babel python package is installed - # 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 - weather: weather.example - pages: - - type: cardEntities - heading: Example Page 1 - items: - - cover.example_cover - - switch.example_switch - - input_boolean.example_input_boolean - - sensor.example_sensor - - type: cardEntities - heading: Example Page 2 - items: - - button.example_button - - input_button.example_input_button - - light.light_example - - delete # (read this as 'empty') - - type: cardEntities - heading: Example Page 3 - items: - - scene.example_scene - - delete - - delete - - delete - - type: cardGrid - heading: Example Page 4 - items: - - light.light_example - - button.example_button - - cover.example_cover - - scene.example_scene - - switch.example_switch - - delete - - type: cardThermo - heading: Exmaple Thermostat - item: climate.example_climate - - type: cardMedia - item: media_player.spotify_user - - type: cardAlarm - item: alarm_control_panel.alarmo -``` - -key | optional | type | default | description --- | -- | -- | -- | -- -`module` | False | string | | The module name of the app. -`class` | False | string | | The name of the Class. -`config` | False | complex | | Config/Mapping between Homeassistant and your NsPanel +![screens](doc-pics/screens.png) \ No newline at end of file