I am planning to add a horizonal banner (picture-element) above my floorplan in my lovelace UI. The banner shall change background depending of time of day.
See the example below, which is the start of my code. I would like to change “image:/local/timeofday/day.png” to another png-file depending on the state of a sensor which will have the states (sunrise, morning, day, sunset, evening, night), just like the “state_image”, but state_image only works for elements, not the background itself.
I have manged to come half way with picture-glance. I shift picture depending on time of day, but of course I cannot add any elements, just entities. Anyone know of a way to mix these two?
Ok, I think I have solved it, since someone might wanna do this, I thought it would be good to post the solution.
The soultion is to use picture-elements with a image elements state_image with the tap and hold action turned off. By turning it off the state-image becomes more or less a dead background, but can be changed with the sensor state.
Can you share the config of your sensor.timeofday?
I am looking to put together a sleep clock for my kiddos. The basic idea is that the background picture on a picture-element card changes colors based on what time of the night it is. Yellow would be the turn down time where they get ready for bed by reading / relaxing. Red would mean its time for bed and to stay in bed. Green would be time to get up or its ok to come to our bed.
It should be pretty simple to put this together but i am struggling getting a sensor that I can set the labels and associated time ranges that i can reference to change the backgrounds.
For any of you who have smallish kids getting them to stay in their beds can be a challenge.
Thanks for sharing your code.
May I suggest a slightly optimised equivalent?
{% set time = states.sensor.time.state %}
{% set elevation = states.sun.sun.attributes.elevation %}
{% set night_from = '23:00' %}
{% if -2 < elevation < 4 %}
{{ 'sunrise' if time < '12:00' else 'sunset' }}
{% elif time < '06:00' or time > night_from %} night
{% elif time < '09:00' %} morning
{% elif time < '19:00' %} day
{% elif time < night_from %} evening
{% else %} night
{% endif %}