Make the modification I suggested in my previous post. We need to see the actual value of sensor.kitchen_light_level in the trace so we can understand why the automation’s Template Condition considers it to be less than 6.
BTW, you overlooked to post a screenshot of sensor.kitchen_light_level that I had requested (the one you posted doesn’t show the entity’s entity_id only its friendly name) so I am assuming it is the correct name of an existing entity in your system. Because if it’s misspelled (i.e. doesn’t exist) then that would explain why the Template Condition always reports true.
You may have hit the nail on the head here. I’ve misnamed my sensor entity in the automation. It should be sensor.kitchen_sensor_light_level (sorry, can’t figure out how to add code quotes on the iPad as it doesn’t have back quotes)
I hadn’t renamed the entity in the state variable template but done that now and instead of ‘unknown’ it’s showing 0, so…progress.
It just triggered as expected, with a light level of 3, however, I’m finding it difficult to test now with no daylight. I will retest tomorrow and see how it goes.
Thank you for your help and time. I’ve definitely learned a lot tonight so hopefully this will work tomorrow.
I suspected that but didn’t want to second guess you (again) because earlier you said:
I’ve made the amendments and the variable
Anyway, the main mistake was supplying the template with a non-existent entity (like I explained several posts ago: “… or the specified sensor entity doesn’t exist”). The addition of the variable was just to confirm it and now it’s no longer needed given that the correct entity_id has been specified. I’m confident it will work properly tomorrow when you test it during daylight hours.
So, I’ve had chance to play about testing now that there is natural light going into the room and have managed to successfully get the automation working in various rooms.
Thank you for your help and time, it’s much appreciated.
One last question though, can the below be put in template form? If so what would the template format be?
- condition: time
after: '23:00:00'
before: '06:00:00'
Before you go, please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions.
For more information, refer to guideline 21 in the FAQ.
The or is correct. The template is checking if the current hour is less than 6 or equal to 23. The value cannot be a number less than 6 and equal to 23.