Numeric state trigger automation

This automation is intended to work out the battery charge time required (in hours) to boost the batteries by a certain percentage (input_number.battery_topup_level) and update the entity (input_number.batery_topup_to_charge_time) with this number. So, in the automation below, if the battery charge percentage required is between 19% and 36%, the entity (input_number.batery_topup_to_charge_time) should be updated to 1. Except that it doesn’t do this. (input_number.battery_topup_level) is 26% at the moment. Is the percentage causing the problem?

alias: Batt_topup_between_19_and_36_percent
description: ""
trigger:
  - platform: numeric_state
    entity_id: input_number.battery_topup_level
    attribute: initial
    above: 18
    below: 37
condition: []
action:
  - service: input_number.set_value
    data:
      value: 1
    target:
      entity_id: input_number.batery_topup_to_charge_time
mode: single

A Numeric State Trigger is triggered exclusively when the value crosses the threshold.

In your example, it can cross the threshold twice:

  • When the Input Number’s value increases from below 18 to above 18.
  • When the Input Number’s value decreases from above 37 to below 37.

References:
Numeric State Trigger

Plus you have constrained the Numeric State Trigger to monitor a specific attribute of the Input Number called initial. Is that really what you want it to monitor? Because I think you want it to monitor the Input Number’s state value in which case you should remove attribute: initial

If you want to act on all values between 18 and 37, use a State Trigger with a Numeric State Condition.

alias: Batt_topup_between_19_and_36_percent
description: ""
trigger:
  - platform: state
    entity_id: input_number.battery_topup_level
    to:
condition:
  - condition: numeric_state
    entity_id: input_number.battery_topup_level
    above: 18
    below: 37
action:
  - service: input_number.set_value
    data:
      value: 1
    target:
      entity_id: input_number.batery_topup_to_charge_time
mode: single

Thank you. That’s fixed it and I’ve learnt a little more!

1 Like