I’ve made an automation that turns on the closet light at 10 percent between 10pm and 7am, and it works like a champ until I add the condition to make sure the light is off before triggering the action. What have I done wrong here? I’ve tried it several different ways to no avail.
Although I am not sure it would cause the automation to not run so probably isn’t your fix, but for your reference conditions are always ‘and’ and therefore you should drop the ‘and’ and simply list the conditions as they all have to be true for the automation to pass.
I do not know why the condition fails to see the state is “off”, when it is. The only 2 suggestions I can offer are to try and build the automation from the GUI, and see if the trigger condition and action sections look the same as your YAML. Otherwise hopefully someone else with more experience will jump in.
HA understands condition will be true from 00:00 to 06:59.
When you set both like that
- condition: time
after: '22:00:00'
before: '06:59:00'
HA understands condition will only be true when time is between 22:00 - 00:00 AND between 00:00 - 06:59, which can never be true. Both conditions can’t be true at the same time.
Right way of doing it
condition:
- condition: or
conditions:
- condition: time
after: '22:00:00'
- condition: time
before: '06:59:00'
condition:
alias: "Time 15~02"
condition: time
# At least one of the following is required.
after: "15:00:00"
before: "02:00:00
Time condition windows can span across the midnight threshold if bothafter and before keys are used. In the example above, the condition window is from 3pm to 2am.
Again, this failed for the same reason. The light does not return ‘off’ as its status. I just tested it with a different entity being off, and the automation worked. I’ll try a factory reset on this dimmer and see if that solves the problem.
After all these posts, it turns out that a factory reset of the switch and then re-pairing it with the hub solved the problem. So, I’m back to my original automation.