Automation to update input_number with entity sometimes works

I have an automation configured to trigger when a sensor entity goes above an input number helper. Sometimes it does work, sometimes it does nothing, even though the trigger conditions have been met.

alias: track_max_solar
description: Maximum all-time instantaneous production
triggers:
  - trigger: numeric_state
    entity_id: sensor.hoymiles_pv_pv_power
    above: input_number.max_solar_power
conditions: []
actions:
  - action: input_number.set_value
    target:
      entity_id: input_number.max_solar_power
    data:
      value: "{{ states('sensor.hoymiles_pv_pv_power') }}"
  - action: input_datetime.set_datetime
    metadata: {}
    data:
      datetime: >-
        {{
        as_datetime(states.sensor.hoymiles_pv_pv_power.last_changed).astimezone()
        }}
    target:
      entity_id: input_datetime.max_solar_power_datetime
mode: single

In the log, I see that it worked a few minutes ago:

But it should have worked again since, because the entity value is above the input number’s value - 8.85 is greater than 8.8362.

Is it something to do with string vs. float?

Instead of numeric state trigger, you might trigger anytime the value changes, and then condition if it is above the max value.

I think that trigger should work in theory, but maybe rounding issues is making it not retrigger the second time. Since numeric_state only triggers when the trigger goes from not_above the value to above the value. If you’re setting them exactly equal maybe it gets rounded in such a way that it doesn’t see the trigger as going from true → false → true.

No, it’s to do with a quirk of how Numeric state triggers work. If the state value of the entity used to define the threshold changes and the value of the trigger entity is already past that value it won’t trigger immediately… it takes another state change to a value above the threshold to fire again. In cases where the sensor’s value can have quick spikes, this can cause the peak to be missed.

As @karwosts stated, you would be better served with a State trigger.

alias: track_max_solar
description: Maximum all-time instantaneous production
triggers:
  - trigger: state
    entity_id: sensor.hoymiles_pv_pv_power
    not_to:
      - unknown
      - unavailable
    variables:
      now: "{{ now() }}"
conditions:
  - "{{ trigger.to_state.state | float > states('input_number.max_solar_power') | float }}"
actions:
  - action: input_number.set_value
    target:
      entity_id: input_number.max_solar_power
    data:
      value: "{{ trigger.to_state.state }}"
  - action: input_datetime.set_datetime
    metadata: {}
    data:
      datetime: "{{ now }}"
    target:
      entity_id: input_datetime.max_solar_power_datetime
mode: single

You may also want to consider using queued mode.

1 Like