Can't use input_text value to set climate.mode (value is not allowed for dictionary value @ data[‘hvac_mode’])

I’m trying to read the previous value of my climate integration from an input_text field and I keep getting an error. Not sure why it isn’t working as everything seems to line up.

I have an input_text defined and I’m currently setting the value of it from the current HVAC mode. That’s all working great. The problem is that when I call the service to set the state back (by pulling it from the input_text) I am getting the following error:

[homeassistant.components.automation.home_ecobee_turn_on_when_doors_closed] While executing automation automation.home_ecobee_turn_on_when_doors_closed
value is not allowed for dictionary value @ data[‘hvac_mode’]

When I use the value “cool” without the template everything works fine and when I test the template it returns the value “cool” so I don’t know what’s going wrong. My failing service call looks like this:

entity_id: climate.home
service: climate.set_hvac_mode
data:
  hvac_mode: {{states('input_text.previous_hvac_state')}}

With the working call looking like this:

entity_id: climate.home
service: climate.set_hvac_mode
data:
  hvac_mode: cool

What the HECK am I doing wrong?

I tried to call the service on its own (without the automation) and it still didn’t work. Same error. It’s as though the template isn’t passing “cool” as the value. Maybe I’m doing it wrong?

Classic HA newbie error. You need data_template instead of data. But, luckily, that’s changing, so data should work in future releases.

EDIT: See:

And, especially, the link at the end to the duplicate topic where the change is talked about.

So like this?


entity_id: climate.home
data_template: 
  hvac_mode: {{states('input_text.previous_hvac_state')}}

Close, but you need to quote the template:

service: climate.set_hvac_mode
entity_id: climate.home
data_template: 
  hvac_mode: "{{states('input_text.previous_hvac_state')}}"

So strange as I’m still getting the same error in the services panel.

Well it worked in the automation so I guess I’ll just leave it there. So glad this is “fixed” in 0.115. Can’t wait to upgrade!

Thank you so much for the help. I feel really silly (since this is documented).

Not strange at all. First, you’d have to enter the service data like this:

entity_id: climate.home
hvac_mode: "{{states('input_text.previous_hvac_state')}}"

I.e., not with data_template (or data, for that matter.)

Second, the services panel doesn’t render templates.

So, no, unfortunately, not strange.

HA HA HA. Well that makes so much more sense then! Seems odd that the services panel doesn’t support the various ways to call the service…perhaps a good “WTH”?