I have this water meter I use to turn on a switch when whist there is water consumption. I created a switch and I used a 10 second delay so it stays on 10 more seconds after the water consumption stops. However, how do I reset the timer if in those 10 seconds there is water consumption again. The purpose is to avoid turning the switch on and off very often.
Pleaae post your code so it is easier to give you relevant suggestions.
Could probably do something similar to this.
on_turn_on:
then:
- script.stop: mytimer
- script.execute: mytimer
script:
- id: mytimer
then:
- delay: 10s
- switch.turn_off: my_switch
I tried putting a delay in the turn off condition, but that turns out it gets stuck on forever. It probably detects value change even when both the previous and the new value is still 0. In the current form it turns of the relay instantly after I turn off the water. Also, from my understanding, the restart mode is similar to stopping the script before running it again.
I suppose it can work with a delay before the turn off switch if I can make a condition that sounds like this:
if value_change
not_from 0
to 0
Then
Delay 10s
turn_off
…but I don’t know how to do that here
[...]
on_value:
then:
#- script.stop: uv_lamp_trigger
# - delay: 0.1s
- script.execute: uv_lamp_script
[...]
script:
- id: uv_lamp_script
mode: restart
then:
- if:
condition:
lambda: 'return id(water_per_hour_m3).state > 0;'
then:
- logger.log: "The sensor value is above 0 m3!"
- switch.turn_on: uv_lamp_relay
- delay: 10s
- if:
condition:
lambda: 'return id(water_per_hour_m3).state == 0;'
then:
- logger.log: "The sensor value is 0 m3!"
#- delay: 10s
- switch.turn_off: uv_lamp_relay
I think a binary template sensor with a filter could be used to get the desired behavior. I didn’t test this but when water is flowing, sensor would trigger and turn uv light on right away. Once water stops the 10s filter would start to count down and turn off uv light unless water started to flow again, which would reset the 10s filter.
binary_sensor:
- platform: template
name: timer_10s
internal: true
filters:
- delayed_off: 10s
lambda: 'return id(water_per_hour_m3).state > 0.0;'
on_release:
- switch.turn_off: uv_lamp_relay
on_press:
- switch.turn_on: uv_lamp_relay
This must be it!
delayed_off¶
(Required, Time): When a signal OFF is received, wait for the specified time period until publishing an OFF state. If an ON value is received while waiting, the OFF action is discarded. Or in other words: Only send an OFF value if the binary sensor has stayed OFF for at least the specified time period. Useful for debouncing push buttons
I will test this when I get home and confirm it it works. Thank you all!