Cannot make scene activate on the basis of the current input select setting

All I want to do is to activate (in an automation) the scene indicated by the input select. Can you please help with the code? (I am getting an error about extra keys not allowed at @ data[‘data_template’])

Many thanks!

- id: MasterScenesDown2

  alias: Master Scene Down2

  trigger:

    platform: state

    entity_id: input_select.master_scene_select

  action:

    - service: scene.turn_on

      data:

        data_template:

          entity_id: "{ { states('input_select.master_scene_select') } }"
1 Like

If the state of your input select is actually the entity_id of the scene (i.e. scene.your_scene) you can just use:

- id: MasterScenesDown2
  alias: Master Scene Down2
  trigger:
    platform: state
    entity_id: input_select.master_scene_select
  action:
    - scene: "{{ states('input_select.master_scene_select') }}"

Many thanks! tried this and the visual studio editor says that string does not match the pattern of "^scene etc. Also the automation appears unavailable… :frowning: any ideas what I could be doing wrong? many thanks!

edit: this seems the error from the log:

Logger: homeassistant.config
Source: config.py:445
First occurred: September 2, 2021, 10:52:38 PM (7 occurrences)
Last logged: 1:22:59 AM

Invalid config for [automation]: expected dict for dictionary value @ data[‘action’][0][‘data_template’]. Got None. (See /config/configuration.yaml, line 1165).
Invalid config for [automation]: Entity ID {{ states(‘input_select.master_scene_select’) }} is an invalid entity ID for dictionary value @ data[‘action’][0][‘scene’]. Got None. (See /config/configuration.yaml, line 1165).
Invalid config for [automation]: Entity ID scene."{{ states(‘input_select.master_scene_select’) }}" is an invalid entity ID for dictionary value @ data[‘action’][0][‘scene’]. Got None. (See /config/configuration.yaml, line 1165).

2021-09-03 01:17:19 ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: Entity ID scene."{{ states('input_select.master_scene_select') }}" is an invalid entity ID for dictionary value @ data['action'][0]['scene']. Got None. (See /config/configuration.yaml, line 1165).

I don’t know why the shortcut version isn’t working in that specific case… probably something to do with “limited templates”.

I have checked the following, and it works on my system:

alias: ztest scene select w shortcut
trigger:
  platform: state
  entity_id: input_select.master_scene_select
action:
  - service: scene.turn_on
    target:
      entity_id: "{{states('input_select.master_scene_select')}}"
mode: single
1 Like

Thank you so much! it worked! :slight_smile: :slight_smile:

Code for anybody interested:

config.yaml

input_select:

  master_scene_select:

    options:

      - "scene.playroom_day"

      - "scene.playroom_night"

      - "scene.playroom_low"

      - "scene.playroom_ultra_low"

      - "scene.playroom_sleep"

      - "scene.playroom_off"

    initial: "scene.playroom_night"

automations.yaml

(you need 2 automations for each button - below code just for the down button)

- id: '1630606723125'

  alias: Master bedroom scene down triger

  description: ''

  trigger:

  - platform: state

    entity_id: binary_sensor.master_bedroom_scene_down

    to: 'on'

    from: 'off'

  condition: []

  action:

  - service: input_select.select_next

    target:

      entity_id: input_select.master_scene_select

  mode: single

- id: MasterScenesDown2

  alias: Master Scene Down2

  trigger:

  - platform: state

    entity_id: input_select.master_scene_select

  action:

  - service: scene.turn_on

    target:

      entity_id: '{{states(''input_select.master_scene_select'')}}'

  mode: single

If I understand what you are trying to do, you should be able combine your ‘up’ and ‘down’ automations into one automation using the “choose” action.

alias: Master bedroom scene combined
description: ''
trigger:
  - platform: state
    entity_id: binary_sensor.master_bedroom_scene_up
    from: 'off'
    to: 'on'
    id: Up
  - platform: state
    entity_id: binary_sensor.master_bedroom_scene_down
    to: 'on'
    from: 'off'
    id: Down
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: Up
        sequence:
          - service: input_select.select_previous
            target:
              entity_id: input_select.master_scene_select
      - conditions:
          - condition: trigger
            id: Down
        sequence:
          - service: input_select.select_next
            target:
              entity_id: input_select.master_scene_select
    default: []
mode: single

There is no reason to have a ‘MasterScenesDown2’ and a ‘MasterScenesUp2’… they would both be doing the exact same thing. You really only need 2 automations total, not 2 per button.