diff --git a/README.md b/README.md index f5cb0acc..8da370af 100644 --- a/README.md +++ b/README.md @@ -228,6 +228,7 @@ nspanel-1: locale: "de_DE" timeFormat: "%H:%M" dateFormat: "%A, %d. %B %Y" + weatherEntity: weather.example pages: - type: cardEntities heading: Example Page 1 diff --git a/apps/nspanel-lovelance-ui/nspanel-lovelance-ui.py b/apps/nspanel-lovelance-ui/nspanel-lovelance-ui.py index bbb0b802..fa102ea5 100644 --- a/apps/nspanel-lovelance-ui/nspanel-lovelance-ui.py +++ b/apps/nspanel-lovelance-ui/nspanel-lovelance-ui.py @@ -34,6 +34,12 @@ class NsPanelLovelanceUI: self.api.run_daily(self.update_date, time) self.update_date("") + # Setup weather callback # TODO: change to a less often callback + time = datetime.time(0, 0, 0) + self.api.run_minutely(self.update_screensaver_weather, time) + + self.update_screensaver_weather("") + # set brightness of screensaver if type(self.config["brightnessScreensaver"]) == int: self.current_screensaver_brightness = self.config["brightnessScreensaver"] @@ -164,6 +170,39 @@ class NsPanelLovelanceUI: self.current_screensaver_brightness = kwargs['value'] self.send_mqtt_msg(f"dimmode,{self.current_screensaver_brightness}") + def update_screensaver_weather(self, kwargs): + if not ("weatherEntity" in self.config and self.api.entity_exists(self.config["weatherEntity"])): + return + we = self.api.get_entity(self.config["weatherEntity"]) + unit = "°C" + + weathericons = { + 'clear-night': 17, + 'cloudy': 12, + 'exceptional': 11, + 'fog': 13, + 'hail': 14, + 'lightning': 15, + 'lightning-rainy': 16, + 'partlycloudy': 18, + 'pouring': 19, + 'rainy': 20, + 'snowy': 21, + 'snowy-rainy': 22, + 'sunny': 23, + 'windy': 24, + 'windy-variant': 25 + } + + # TODO: Weekday's instead of +1, +2 + o1 = "Day +1" + i1 = weathericons[we.attributes.forecast[0]['condition']] + u1 = we.attributes.forecast[0]['temperature'] + o2 = "Day +2" + i2 = weathericons[we.attributes.forecast[1]['condition']] + u2 = we.attributes.forecast[1]['temperature'] + self.send_mqtt_msg(f"weatherUpdate,?{weathericons[we.state]}?{we.attributes.temperature}{unit}?{26}?{we.attributes.humidity} %?{o1}?{i1}?{u1}?{o2}?{i2}?{u2}") + def scale(self, val, src, dst): """ Scale the given value from the scale of src to the scale of dst. diff --git a/info.md b/info.md index 78ccd9b0..39fd208c 100644 --- a/info.md +++ b/info.md @@ -21,6 +21,7 @@ nspanel-1: locale: "de_DE" timeFormat: "%H:%M" dateFormat: "%A, %d. %B %Y" + weatherEntity: weather.example pages: - type: cardEntities heading: Example Page 1