I have a door sensor on my home office door. I tried to use the sensor to turn the lights on when I entered and off upon exit. I was able to achieve success with the help of the Counter, which is incremented every time the state is opened.
I wanted to use the counter’s count to determine if the lights should be turned on (upon entry) or off (upon exit). To do this I created an automation and used the Template as the trigger. In the template I coded:
{% if (states('counter.dad_office_door_counter') | int is odd) %}
true
{%endif%}
On this automation, I used to turn the lights on. I replaced “odd” with “even” for the exit automation.
My assumptions are
- When entering the counter goes from 0 to 1 (odd) and that is the start of the day. That’s when I want the lights on.
- When exiting, the counter goes from 1 to 2 (even) and means that I’m opening the door to leave and the lights should be turned off.
I know I’m not factoring in the office visitor. Who comes in, but this satisfies my needs to about 90%.
I’m sure there might be another way to accomplish this, if you have any ideas let me know what you think.