Need help setting input_select value in automation

I have an ‘away’ automation that turns the thermostat off when I leave. I want it to store the mode the thermostat was in (heat, cool, etc) so that when I return, it can set it back to that mode. I currently have the following:

configuration.yaml:

input_select: !include input_select.yaml

input_select.yaml:

prior_nest_mode:
  initial: na
  name: Prior Mode
  options:
    - na
    - off
    - heat
    - cool
    - auto
    - eco

And the in my away automation I have:

- alias: Away
  trigger:
    - platform: state
      entity_id: device_tracker.redacted
      from: 'home'
      to: 'not_home'
    - platform: zone
      event: leave
      zone: zone.home
      entity_id: device_tracker.redacted
  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: device_tracker.redacted
        state: not_home
      - condition: state
        entity_id: input_boolean.doug_home
        state: 'on'
      - condition: zone
        entity_id: device_tracker.redacted
        zone: zone.not_home
  action:
    - service: alarm_control_panel.alarm_arm_away
      entity_id: alarm_control_panel.redacted_home
    - service: media_player.turn_off
      entity_id:
        - media_player.everywhere
        - media_player.bathroom
        - media_player.bedroom
        - media_player.livingroom
    - service: input_select.select_option
      data_template:
        entity_id: input_select.prior_nest_mode
        option: {{ states('climate.living_room') }}
    - service: nest.set_operation_mode
      data:
        operation_mode: 'eco'
    - service: nest.set_away_mode
      data:
        away_mode: 'away'
    - service: input_boolean.turn_off
      data:
        entity_id: input_boolean.doug_home
    - service: shell_command.pushover
      data:
        msg: 'The apartment has been set to AWAY MODE'

Running hassio homeassistant check returns:

    ERROR:homeassistant.util.yaml:invalid key: "OrderedDict([("states('climate.living_room')", None)])"
      in "/config/automations/away.yaml", line 35, column 0
    Failed config
      General Errors:
        - Error loading /config/configuration.yaml: invalid key: "OrderedDict([("states('climate.living_room')", None)])"
      in "/config/automations/away.yaml", line 35, column 0

    Successful config (partial)

But it all looks sane to me? Why can’t it use the state as the selector value? Thanks

1 Like

Assuming that the state is in the option list for the input_select, it’s a single line template. Put it in quotes (rule 3).

    - service: input_select.select_option
      data_template:
        entity_id: input_select.prior_nest_mode
        option: "{{ states('climate.living_room') }}"
3 Likes

Also you may have trouble with off as an option in the input_select list. Put that in quotes too.

prior_nest_mode:
  initial: na
  name: Prior Mode
  options:
    - na
    - 'off'
    - heat
    - cool
    - auto
    - eco

on/off and true/false evaluate to 1/0 unless quoted.

1 Like

That appears to have done the trick. Thank you!

1 Like

I thought I was being clever using input_select to manually store states but this is brilliant! :+1: