Daily max wind gust helper/automation

I’m trying to have one input number sensor that’s going to be the daily max wind gust, but somehow it stops after a few updates.
It compares the value of the helper with the actual wind gust value, if the wind gust value is larger, then the value of the helper becomes the actual wind gust value. It works, but after some time it stops getting the new values.
My automation looks like this →

alias: "[HELPER] Daily max wind gust"
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.ecowitt_wind_gust
condition:
  - condition: template
    value_template: >-
      {{ states('sensor.ecowitt_wind_gust') >
      states('input_number.daily_max_windgust')}}
action:
  - service: input_number.set_value
    data:
      value: "{{ (states('sensor.ecowitt_wind_gust')) }}"
    target:
      entity_id: input_number.daily_max_windgust
mode: single

My helper →

The wind gust sensor looks like this:

while my helper got stuck at 9kmh.

Could anyone help me out? What am I doing wrong?

You’ve got a couple possible sources of issues:

  1. Your template condition is comparing strings when you need to compare numbers. This would lead to a case like described, because {{ "16" > "9" }} would render as False.
  2. Your automation mode is set to ‘single’ which may lead to values being dropped if they are coming in rapidly.
  3. Since gusts are brief by definition, it might be better to get the value from the trigger variable rather than reevaluating the sensor’s state.
alias: "[HELPER] Daily max wind gust"
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.ecowitt_wind_gust
condition:
  - condition: template
    value_template: >-
      {{ trigger.to_state.state | float(0) >
      states('input_number.daily_max_windgust') | float(0) }}
action:
  - service: input_number.set_value
    data:
      value: "{{ trigger.to_state.state }}"
    target:
      entity_id: input_number.daily_max_windgust
mode: queued
1 Like

Thanks Drew for the code and explanation. I’m going to give it a try, and I’ll report back later with the findings.

After a few days, I can confirm that it is working.
Thank you.

1 Like