I understand that. And it is a good solution. What I mean is how are you going to ignore the brief changes using a template?
Iâve confirmed my solution works â going from OFF to OFF doesnât seem to be reflected in the history nor in updates to anything else. Itâs as if it didnât happen. Itâs really just taking advantage of an optimization in HA (which in other cases can be pretty bad, e.g. when you are trying to compute derivative of a sensor w.r.t. time and the value of that sensor has not changed).
You still have not answered my question.
How are you ignoring the brief states in the template sensor?
What method are you using?
sorry - family time
triggers
template sensors support the triggers platform
the difference between doing that directly in an automation vs passing it through a template sensor first is that the template sensor automatically deduplicates repeat values, so the double OFF triggered isnât an issue (since it goes from OFF to OFF, see our examples above)
No it does not. Thatâs the problem. It goes on briefly between the the off states.
At 11 sec in your diagram above.
You will have exactly the same issue as using the automation.
Would it maybe help if you explained in what real life situation youâre going to use said automation? This reminds me of something I set up recently where a button press turns a light on 10%. If I press it again withing 2sec, it goes to 20%, within 2sec again 30% and so on. If the button is not pressed for >2sec, then the button acts like an âoffâ switch.
As I mentioned earlier, using the delay_on
and delay_off
options in a template binary sensor could be a way around this.
template:
- binary_sensor:
- name: Debounced
state: >
{% if has_value('binary_sensor.some_data') %}
{{ states('binary_sensor.some_data')|bool }}"
{% else %}
{{ this.state }}
{% endif %}
delay_on: 10
delay_off: 10
That binary sensor wonât change for states shorter than 10 seconds. It will also ignore the unavailable and unknown states (due to the has_value()
test).
binary_sensor.some_data
0 off
11 on
12 off
13 on
Produces:
binary_sensor.debounced
0 off
11 off
12 off
13 off
23 on
Likewise for the opposite states of the source sensor.
nice! that should work. is the same concept but more elegant.
As you can see in the diagram it doesnât trigger because of the duration clause (for: etc)
Maybe Iâm being stupid but Iâve tested and it works fine.
I never see an on state at all in that case, and importantly the second triggered OFF isnât actually reflected as an update to the template sensor by HA because the value is the same as the previous one.
Iâll test your delay option as well once Iâm home. Maybe Iâm just missing something fundamental
Apologies @tom_l I havenât had a chance to test the delay solution since the one I did with the template trigger platform sensor works for me and solved my problem. However, based on your confirmation above I will mark it as the solution. Thanks for your help and time investment to help solve this!