Helpers type "Template"

Hi,

I am trying to create an Helpers type “Template” with the goal of converting a value from km/h to m/s, which means that I need to divide an entity with 3.6.

I am choosing “Template a sensor” and choosing/writting the following:
Name: Wind
State template: {{ states(‘sensor.are_wind_speed’ / 3.6) |round(1)}}
Unit of measurement: m/s
Device class: Wind speed
State class: Measurement

When I am ready and open my helpers “Wind”, I don’t get any value, just “Unavailable”.

Has anyone any idea about what I am doing wrong?
Thank’s!

Hi @rvqrat

Maybe try:

State template: {{ states(‘sensor.are_wind_speed’) | float(0) / 3.6 | round(1)}}

The main issue is that you had the division by 3.6 inside the states function.

Hi @templeton_nash,

Thank’s for your reply. I tried your code, but it generates the following error message:

invalid template (TemplateSyntaxError: unexpected char ‘‘’ at 10)

Any ideas what is the problem?
Thank’s!

This is the nasty smart quote feature some editors have (mac, ipad, etc.). They change plain quotes in curly ones. They look nice but don’t work in code. Change the qurly quotes to plain ’ quotes and you should be fine.

And check your keyboard settings where you edited the template, and turn the smart quotes feature off. It will bite you more then it will help you.

Hi @Edwin_D ,

You were right, it works now.

Thank’s to you and to @templeton_nash
:slight_smile:

1 Like

Just FYI, if your wind speed sensor has the correct state_class you can change this unit from the UI. No need for a template helper. Click on your entity then: