Hi, I have a watermeter counting litres and providing value in 20 secs interval via MQTT, the interval might be adjusted. Sensor value is increasing. I want to use it as a “flow meter” for indication that any valve or faucet in the house is opened.
My idea is to compare consecutive values and if value trigger.to_state == trigger.from_state
then input_boolean or binary_sensor will indicate “close” and “open” otherwise
I tried this automation
- alias: "flow_active"
mode: restart
trigger:
platform: numeric_state
entity_id: sensor.watermeter_main_lt
above: '0'
action:
- service: >
{% if trigger.to_state != trigger.from_state %}
input_boolean.turn_on
{% else %}
input_boolean.turn_off
{% endif %}
target:
entity_id: input_boolean.flow_active
and this
{% if trigger.to_state == trigger.from_state %}
input_boolean.turn_off
{% else %}
input_boolean.turn_on
{% endif %}
or
{% if trigger.to_state.state == trigger.from_state.state %}
but none of them is working
Any advice please - proper syntax or better solution?