How do I reveal a state value in a template

I have a custom entity named FanSpeed currently set to the value 3.0
If I inspect the state of this entity using Developer Tools --> STATES I get the expected result:


But if I try to retrieve this state value using a template, it fails. This is how it looks in Developer Tools --> TEMPLATE:

What am I doing wrong since the value comes back as unknown when it clearly has the value 3.0 ?

{{ states(‘sensor.fanspeed’) }}
you have to add the type alike sensor, light switch etc. which you can find in the states tab

You can thank the developers for this confusion.
By some reason they believe we don’t need to see the entity names, even though entity names are used everywhere and especially in templates.

What you see as “fanspeed” is the friendly name, you need to get the entity name. Perhaps it’s called sensor.fanspeed.
You can find it in the list below this set state window in the developer tools.

1 Like

might it be fan_speed? What does the sensor look like in States tab? in the table, not the one you showed above

Ok, I see now - @Hellis81 is right, this was my friendly name. The true entity name is:


This brings med back to my actual problem; I’m trying to create a template to build a new string value from the combination: "speed_" + input_number.speed_value and at the same time converting the number value 3.0 to the string “3” so that the final result becomes “speed_3”

Any ideas?
I tried this:

{{ (states("input_number.speed_value") | round ) }}

and it gives correctly the number 3, but then what ?
This fails:

{{ "speed_" + (states("input_number.speed_value") | round ) }}

Ehmm… You named it like that yourself.
Maybe you should have a meeting with yourself to come up with a naming convention :wink:

1 Like

You are trying to add a string and a number which fails. Convert the number to a string, after the round add in |str or |string

use ~ instead of +, it ensures everything is a string

{{ "speed_" ~ states("input_number.speed_value") | int }}

OMG, that worked! Thank you so much!! :+1: I would never have guessed that…