UI changes int to string

I have two automations that take an int value as the input value but whenever i add the number it automatically changes it back to a string by adding the ’ ’ around it. Even if i go into the yaml and remove it, the next time i check the ’ ’ are back. How do i solve this?

You can’t. States are always strings. Only attributes can be different types.

If you need to use the state as a number you can use the |float or |int filters.

e.g. if the input number my_number contains 21.7

{{ states('input_number.my_number') }}  -> '21.7'

{{ states('input_number.my_number')|int }} -> 21

{{ states('input_number.my_number')|float }} -> 21.7

How do i do this in the UI?
Right now my automation looks like this

alias: Game Fan Off
description: Turns the fan off when PS5 or Xbox turns off
trigger:
  - platform: device
    type: turned_off
    device_id: f9a2f673e917868493fa7c314d9e4d0f
    entity_id: remote.vardagsrummets_xbox_remote
    domain: remote
  - platform: state
    entity_id: sensor.playstation
    from: 200
    to: '620'
    attribute: code
condition:
  - condition: device
    type: is_on
    device_id: ed496980cfea1612b838d70dd5cf264d
    entity_id: switch.053010302cf432ed324d
    domain: switch
action:
  - type: turn_off
    device_id: ed496980cfea1612b838d70dd5cf264d
    entity_id: switch.053010302cf432ed324d
    domain: switch
mode: single

And its the to: '620' that messes it up. If it could say to: 620 instead it would work.

That’s not your problem.

Assuming the sensor state is not going to change directly from 200 to 620 your state trigger will never happen.

You can use a numeric state trigger to check if the state is above or below a value.

The state is changing from exactly 200 to 620 and back again. The sensor reports back a number for the field code. If that number is 200 then the fan should turn on, if the number is 620 the fan should turn off.
Also i did get it to work when manually changing the yaml but the ui seems to change it back occasionally.

I have a question about the code you used for the trigger.

Why did you put the “attribute:” option in here?:

  - platform: state
    entity_id: sensor.playstation
    from: 200
    to: '620'
    attribute: code

either way that looks like a bug.

if the “code” attribute is really where you are pulling the numbers from then both should be numbers (int or float). If the state is where you are getting the numbers from then both of the numbers should always return as strings.

they should never (as far as I know…) be converted to a string in one option & then a number in the other.

Can you try to put quotes around the 200 and see if it will do a proper string comparison on both values?

Ok, you should log an issue - or stop using the god-awful IU.

Looks like someone forgot that attributes in state triggers need a type when setting up the UI for this. States are always strings, but attributes are not.

the sensor is reporting a number of field back but the important one is the code attribute. I changed to numeric state trigger and set the under to 201 and the over to 199 and got it to work! Doesn’t look as pretty but works which is the important parts!

2 Likes

I’m still pretty new to Home assistant so it’s nice to have the UI to help you get started. Maybe when i level up to advanced user i’ll start coding the automations etc from scratch =)

Yeah sure, it’s just my opinion. Others find it useful. Don’t get me started on device triggers…

Nice work around btw.

If you want the UI to be improved you should log this issue. Not sure if it goes in core issues or front end issues though.

1 Like

Better to just start now and dive right in the way the rest of us “Crusty Old Bast@&#'s” did it!

:laughing:

1 Like