Lovelace Conditional Card - time of day

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 :slight_smile:

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.

1 Like

Thank you :slight_smile: 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.

Thatā€™s because the sensor doesnā€™t update as @bradyn12 said in his last post.

Thanks :slight_smile: But the sensor updates. In my Lovelace UI I show the sensor state:

entities:
      - sensor.nighttime

And it always shows the correct state:

image

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'

Finally the card was visible:

- type: conditional
  conditions:
    - entity: sensor.nighttime
      state: 'False'

False, false, ā€œfalseā€, ā€œFalseā€, ā€˜falseā€™ was not working, but ā€˜Falseā€™ is. So if I type ā€˜Trueā€™ the card should show at 10PM.

Thank you @petro and @bradyn12

1 Like