Bug causing quotes to apear around template sensor value

I got this weird bug with a template sensor, my state value has “quotes” around it

value_template: "{{()}}" it won’t work without quotes

the issues is when i take that value and try to compute with it i can’t have quotes around it

> 
>     - platform: template
>        sensors:
>          ctemp:
>            value_template: “{{((states.sensor.temp.state|float - 32)*5/9)}}”

in HA the value ends up being “25” for example instead of 25

1 Like

I think it will end up not making any difference in your calculation if it has quotes but so it can be worked out can you give the code you’re using for a calculation as an example?

I think your issue is you’re using the wrong kind of double-quote characters. You need to use ", but you’re using and .

1 Like

this must be it! so i use 2 single quotes ‘’ instead of double quotes "?

I ended up fixing this last last night with a > and using multiple lines, had a realization at 3am while in bed lol

No. You use the correct double-quote character: ". Not two single quotes: ''. Or you could have quoted it using single-quote characters: '. So either of these would have worked:

value_template: "{{((states.sensor.temp.state|float - 32)*5/9)}}"
value_template: '{{((states.sensor.temp.state|float - 32)*5/9)}}'

but not:

value_template: “{{((states.sensor.temp.state|float - 32)*5/9)}}”

You have to be careful of editors that change the correct double-quotes "x" into fancy, curly double-quotes “x”.

Or, like you did, you could avoid the outside quotes altogether by using multi-line YAML. But even with multi-line, there are times where you need to use quotes, so always remember you need the simple quotes, not the fancy, curly quotes.

1 Like

Ahh i understand now… Honestly i didn’t know there was a difference between curly and straight double quotes I thought it had to do with the font. These are little tidbits that hard to learn for beginners… I’m using the default apple TextEdit. Thanks!

Hi I have a similar problem creating a power sensor (W) from another already in W.
If the value is positive it returns me the value, if it is negative it returns me 0
It works, but I see the "in the output and then I can’t use it in the automations.
Advice?

  • platform: template
    sensors:
    energia_immessa:
    friendly_name: “Energia immessa”
    value_template: >-
    {% if states(‘sensor.energia_scambio_sul_posto’) | float > 0 %}
    {{states(‘sensor.energia_scambio_sul_posto’)|float|int}}
    {% else %}
    {{0|float|int}}
    {% endif %}"
    unit_of_measurement: “W”
    icon_template: mdi:flash

The " is at the end of your template, after the endif, so it’s added to the sensor value string when your template is finished.

I can’t believe it, I’ve watched it 10 times
thanks
:man_facepalming:t4:

1 Like