Comparing values in automation

Having problems comparing two states in condition section of an automation:
(left the actions part out)

alias: Battery_stop
description: Stop battery when setpoint reached
triggers:
  - entity_id:
      - sensor.solax_inverter_battery_capacity
    not_from:
      - unknown
      - unavailable
    not_to:
      - unknown
      - unavailable
    trigger: state
conditions:
  - alias: Are they Equal?
    condition: state
    entity_id: sensor.solax_inverter_battery_capacity
    state:
      - input_number.batterij_instelpunt
  - condition: state
    entity_id: input_boolean.battery_overset
    state:
      - "on"

After running the automation and switching to tracking, I get this:

result: false
state: ‘69’
wanted_state: ‘69.0’

It looks like HA compares strings, not numbers, So even if 69 and 69.0 have the same value, it compares false. Could it be because of the decimal?
Thanks for any help offered.

Yes, states are always strings and the State condition compares those strings literally. So “69” and “69.0” are not the same. To check mathematical equality you will need a template condition:

alias: Are they Equal?
condition: template
value_template: |
  {{ states('sensor.solax_inverter_battery_capacity')|float ==
  states('input_number.batterij_instelpunt')|float }}
1 Like

Thank you for the quick response. It works just fine!