#Error using variable based on "hvac_mode" for a thermostat

23 messages · Page 1 of 1 (latest)

vital pond
#

I am trying to make a simple script that:

  • stores the current mode and temperature of a smart thermostat
  • then changes those to "auto" and 24 degrees
  • after an amount of time, returns them to their previous state.

I have the following script:

sequence:
  - variables:
      previous_mode: "{{ state_attr('climate.office', 'hvac_mode') }}"
      previous_temperature: "{{ state_attr('climate.office', 'temperature') }}"
  - target:
      entity_id: climate.office
    data:
      hvac_mode: heat
    action: climate.set_hvac_mode
  - target:
      entity_id: climate.office
    data:
      temperature: 24
    action: climate.set_temperature
  - delay: "00:01:00"
  - target:
      entity_id: climate.office
    data:
      hvac_mode: previous_mode
    action: climate.set_hvac_mode
  - target:
      entity_id: climate.office
    data:
      temperature: previous_temperature
    action: climate.set_temperature```

But when running, the actions after the delay do not happen. Looking at the trace, there is the error:

`Error: expected HVACMode or one of 'off', 'heat', 'cool', 'heat_cool', 'auto', 'dry', 'fan_only' for dictionary value @ data['hvac_mode']`

I don't quite follow what this error means. My understanding was that `previous_mode: "{{ state_attr('climate.office', 'hvac_mods') }}"` should store previous mode as (usually) `auto` or `off` and then give that mode back to the script. But it seems not to be happening here?
karmic seal
#

hvac_mode: "{{ previous_mode }}"
It's variable, needs template.

#

Same with temp

vital pond
#

Well that was stupid of me! But I'm still getting the same thing

Result:
params:
  domain: climate
  service: set_hvac_mode
  service_data:
    hvac_mode: null
    entity_id:
      - climate.office
  target:
    entity_id:
      - climate.office
running_script: false```
karmic seal
#

You have it null there. Trace the automation and check what is your variable

violet cove
#

Many climate entities return their active hvac mode as their state, rather than have an attribute "hvac_mode"

#

check the state explorer in developer tools

ionic gust
#

You can probably do this much simpler with scenes.

  • Call scene.create with your climate entity.
  • Change it to whatever
  • delay
  • Call scene.turn_on to restore
karmic seal
#

If you actually want to apply old settings to thermostat, why not doing it with scene?

#

@ionic gust beat me to it 🙂

#

@ionic gust but you forgot to call scene.delete after 🙂

ionic gust
#

afaik it's not really necessary

#

but sure you could do it

vital pond
#

I understand that I could do it with scenes but I'd like to try and make this work with a script that I could then reuse and adapt for different entities, other variables, etc

vital pond
violet cove
vital pond
#

How can I check that?

violet cove
#

do you have developer tools on the left hand side?

#

if so click on that, then go to template and paste it in on the LHS and see what it outputs

#

i think it's likely what you actually want is just {{ states('climate.office') }} - that's what all of mine report the hvac mode as

vital pond
#

Ahh thank you, that's right

hollow solar
violet cove