Need help formating state with "space"

Maybe it was already pushed here somewhere but i can’t point to the right solution.
I’m trying to configure a cost for grid electricity depending on the state of a sensor which contains a space as like this 'HC ROUGE". So price is different regarding to the colour. I use template sensor to get this but can’t have correct answer as I think due to the space. I tryed already something like /nbsp; but it’s not working. So I am here if someone can helped me.

{{ states('sensor.linky_tarif_actuel')}}
{{is_state("sensor.linky_tarif_actuel",['HP  ROUGE'])}}

It returns:

what happens if you try:

{{is_state("sensor.linky_tarif_actuel", "HP  ROUGE") }}

also I ust noticed there are actually two spaces in “HP ROUGE”. is that expected?

Thank you for your answer, today color is white so I change accordingly your proposition.

{{is_state("sensor.linky_tarif_actuel", "HP  BLANC") }}



I notified the three are two space between HP and BLANC. This information comes from my electricity counter so i can’t modify it.

I honestly don’t know why that isn’t working as it looks like it should from your posted return values.

unless there are hidden characters in the state that you aren’t accounting for in the template.

try this in the dev tool template editor:

{{"BLANC" in state("sensor.linky_tarif_actuel") }}
{{ "HP  BLANC" in state("sensor.linky_tarif_actuel" ) }}

Today is BLEU as color, this what it returns:

{{"BLEU" in states("sensor.linky_tarif_actuel") }}
{{ "HP  BLEU" in states("sensor.linky_tarif_actuel" ) }}

I think it can be a workarround for my problem so thank you for this!

1 Like