Extra characters in operating_state string

Hello all,

Trying to finish up my thermostat configuration and getting an odd display issue with the operating state. I have a (’ at the beginning and a ',) at the end:

As you can see the fan state doesn’t have the same issue. Here are both of them in the states page:

And here is the relevant config for the display:

sensor:
  - platform: template
    sensors:
      climate_main_operating_state:
        friendly_name: 'Operating State'
        value_template: '{{ states.climate["2gig_technologies_ct100_thermostat_usa_heating_1_8_1"].attributes.operating_state }}'
      climate_main_fan_state:
        friendly_name: 'Fan State'
        value_template: '{{ states.climate["2gig_technologies_ct100_thermostat_usa_heating_1_8_1"].attributes.fan_state }}'

And for the group:

group:
   hvac_main:
     name: 'Main Thermostat'
     entities:
       - sensor.climate_main_fan_state
       - sensor.climate_main_operating_state

Thanks so much for your assistance!

That’s strange - I can’t reproduce that for my thermostat. What if you change up the value template for “Operating State” and use something like:

states.climate.2gig_technologies_ct100_thermostat_usa_heating_1_8_1.attributes.operating_state

It blows up:

16-12-09 18:37:23 homeassistant.bootstrap: Invalid config for [sensor.template]: invalid template (TemplateSyntaxError: expected token ‘end of print statement’, got ‘gig_technologies_ct100_thermostat_usa_heating_1_8_1’) for dictionary value @ data[‘sensors’][‘climate_main_operating_state’][‘value_template’]. Got ‘{{ states.climate.2gig_technologies_ct100_thermostat_usa_heating_1_8_1.attributes.operating_state }}’. (See ?:?). Please check the docs at Template - Home Assistant

Seems to be a known bug for devices that start with a number: template broken for zwave sensor name that starts with a number.. · Issue #2826 · home-assistant/core · GitHub

Ah. Why don’t you change the name in Open Zwave Control Panel?

Gave that a shot and same thing. Updated config (pic looks the same):

sensor:
  - platform: template
    sensors:
      climate_main_operating_state:
        friendly_name: 'Operating State'
        value_template: '{{ states.climate.main_thermostat_heating_1_8_1.attributes.operating_state }}'
      climate_main_fan_state:
        friendly_name: 'Fan State'
        value_template: '{{ states.climate.main_thermostat_heating_1_8_1.attributes.fan_state }}'

group:
   hvac_main:
     name: 'Main Thermostat'
     entities:
       - sensor.climate_main_fan_state
       - sensor.climate_main_operating_state

When you put that expression in the template dev tool, do you get the parentheses and comma, too?

Yup:

Ok. The good news then is that it’s not a prob with your template.

Looks like there’s a problem with the code for that device. Weird that it doesn’t show up that way in the states dev tool.

As a duct-tape fix, you could use:

{{ states.climate.main_thermostat_heating_1_8_1.attributes.operating_state | replace("(","") | replace(")","") | replace(",","") }}

Close:

Sigh… Pretty sure you could’a figured that out…

{{ states.climate.main_thermostat_heating_1_8_1.attributes.operating_state | replace("(","") | replace(")","") | replace(",","") | replace(","’"") }}

Probably, but it doesn’t seem to like that:

pi@raspberrypi:/home/hass/.homeassistant $ tail home-assistant.log
16-12-10 00:43:57 homeassistant.util.yaml: while parsing a block mapping
  in "/home/hass/.homeassistant/configuration.yaml", line 111, column 9
expected <block end>, but found '<scalar>'
  in "/home/hass/.homeassistant/configuration.yaml", line 113, column 169

That one I don’t have a clue about. :confused:

right. I replaced the wrong ’

try:
{{ states.climate.main_thermostat_heating_1_8_1.attributes.operating_state | replace(“(”,“”) | replace(“)”,“”) | replace(“,”,“”) | replace(“'”,“”) }}

I had actually caught that and tried it but I get the same error:

pi@raspberrypi:/home/hass/.homeassistant $ tail home-assistant.log
16-12-10 15:49:46 homeassistant.util.yaml: while parsing a block mapping
  in "/home/hass/.homeassistant/configuration.yaml", line 112, column 9
expected <block end>, but found '<scalar>'
  in "/home/hass/.homeassistant/configuration.yaml", line 114, column 167

Are you sure? I just tested and it worked for me. Plug it into your template dev tool and tweak till it works. You’ve got enough there to figure out the syntax for a replace filter.

Yeah, and here’s the super goofy thing. It works fine in the dev tool:

But as soon as I plug it into my yaml file:

sensor:
  - platform: template
    sensors:
      climate_main_operating_state:
        friendly_name: 'Operating State'
        value_template: '{{ states.climate.main_thermostat_heating_1_8_1.attributes.operating_state | replace("(","") | replace(")","") | replace(",","") | replace("'","") }}'

And restart HASS it errors out:

pi@raspberrypi:/home/hass/.homeassistant $ tail home-assistant.log
16-12-10 15:58:01 homeassistant.util.yaml: while parsing a block mapping
  in "/home/hass/.homeassistant/configuration.yaml", line 112, column 9
expected <block end>, but found '<scalar>'
  in "/home/hass/.homeassistant/configuration.yaml", line 115, column 167

So it worked until you added that last replace? So 3 replace filters work, 4 doesn’t? That’s weird.

Does anyone know if there’s a Jinja filter for regex replaces?

Yes, it works fine just still has the single quotes on either end. Once I add in the 4th replace it dies - even though the dev tools show it as working as expected. :confused:

ah - that’s the problem. The single quotes!

Work on it using the template tool. You’ll need to do some trial and error.
Here’s how you escape a character:

{{ “’” }}

(basically {{ “CHAR” }} )

Strike that. Just do this:

value_template: >
  {{ states.climate.main_thermostat_heating_1_8_1.attributes.operating_state | replace("(","") | replace(")","") | replace(",","") | replace("'","") }}

That removes the need for single quotes in your YAML

1 Like

Ahh beautiful!

Thanks so much for your assistance and patience with me! I’m still very much a n00b.