Input boolean based on trigger.to_state and trigger.from_state comparing

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 :roll_eyes:
Any advice please - proper syntax or better solution?

Your automation’s Numeric State Trigger will trigger at the moment when the sensor’s value crosses the threshold value. In other words, at the moment when it increases from below 0 to above 0.

It won’t trigger again until the sensor’s value first decreases below 0 then rises above it.

When it does trigger, the value of trigger.to_state.state will be above 0 and the value of trigger.from_state.state will be below 0. The two variables can never be equal because that arrangement can never serve to trigger the Numeric State Trigger.

Uh, I see.
Sorry for my misunderstandig of trigger.
Thank you