State condition - using an input_number against an integer state?

I’m trying to use an input_number as the test state for a condition in an automation I’m writing, as per the docs. The problem I’m hitting is that input_number seems to always be a float (even when step is 1) and the number entity I’m comparing against is an int.

- condition: state
  entity_id: number.tesla_charge_limit
  state: input_number.tesla_home_charge_limit_high

Fails to compare with:

Result:
result: false
state: '100'
wanted_state: '100.0'

Is there anyway to make this work without having to resort to a template? I much prefer the visibility that directly using the helper entity gives in traces vs a template (that’s the entire reason I’m using automations over NodeRed after all :sweat_smile:).

Actually, the state value for all entities is a string. In other words, the 100.0 you’re seeing is a string value. It’s a characteristic of an Input Number to represent integers as floats but ultimately the value is a string. I am unaware of a way to instruct an Input Number to represent whole numbers without a decimal portion (i.e. as an integer).

The State Condition is comparing two strings, so the Number entity’s 100 doesn’t match the Input Numbers entity’s 100.0.

The simplest solution is to use a Template Condition. Convert the values of both entities to integers and compare them. Easy-peasy … but you will have to use what you don’t want to use, namely a template.

1 Like

Thanks for your help. I got this working by changing to using an input_text instead. Frustrating that an input_number seems unfit for purpose in this manner, but at least I was able to constrain the input_text with a regex.

I didn’t realize your application allowed for using a different kind of entity (replacing an Input Number with an Input Text). The frontend appearance and behavior are quite different. However, if that’s an acceptable trade-off, in order to avoid using a Template Condition, so be it. :slightly_smiling_face:

I considered also creating an input_number and another automation that hard linked it to the input_text … but I’ve ended up deciding to forget about helper entities and just do everything as a blueprint so it can be easily be configured on the automation if the parameters change.

Thanks again for the input, it helped me understand some of the underpinnings of HA state that I was missing.