I looks like it is not possible to directly use time of day as a condition in Lovelace. Any smart workarounds if I want the following condition: Current time is between 10PM and 06AM?
Thanks
I looks like it is not possible to directly use time of day as a condition in Lovelace. Any smart workarounds if I want the following condition: Current time is between 10PM and 06AM?
Thanks
Create a template sensor that is true when the time is between 10pm and 6am. Then use the sensor in your condition cards in Lovelace.
So something like this:
sensor:
- platform: template
sensors:
nighttime:
friendly_name: 'Between 10pm and 6am'
value_template: '{{now().hour >= 22 or now().hour < 6}}'
sensor.nighttime would be true between 10pm and 6am and false between 6am and 10pm.
Thank you I added the template sensor to the configuration.yaml, restarted, and added the sensor in lovelace, but it is not working. In the log I get this warning: āTemplate sensor nighttime has no entity ids configured to track nor were we able to extract the entities to track from the value template(s). This entity will only be able to be updated manually.ā
Any ideas?
Oh right, this is a change in a recent version of HA. Templates donāt always update automatically anymore by default. Hereās the instructions on fixing it:
I would add the sensor.time entity_id to your sensor so it calculates every minute or create an automation that runs every hour to call an update on the sensor.
Thanks, that solved the sensor. I can now show the status (true/false) of the sensor in UI, but I must be doing something wrong in the conditional card:
- type: conditional
conditions:
- entity: sensor.nighttime
state: "true"
If I change the condition entity to a light (on/off), it works, but it does not react when I use the sensor state.
Thanks But the sensor updates. In my Lovelace UI I show the sensor state:
entities:
- sensor.nighttime
And it always shows the correct state:
Or am I misunderstanding something?
Ah, sorry. This is what your conditional should look like.
- type: conditional
conditions:
- entity: sensor.nighttime
state: True
This will also work:
- type: conditional
conditions:
- entity: sensor.nighttime
state: 'on'