How to tie together: input_select trigger scene automation?

HI,
i’m stuck and running in circles here.
I’ve got several switches, in various states combined into a few scenes. Automations to call those scenes. I’ve got all these automations lined up in a group, and they work quite nicely. very simple.

Next I’ve declared an input-select, to set those scenes. And then the confusion starts. How do i call these automations with the input_select. Do i need an intermediate automation for that, or is my original automation superfluous.

check along please:
some scenes:
##########################################################################################
# Scenes
##########################################################################################

- name: Opstaan
  entities:
    switch.sw_espresso_keuken_cl:
      state: on

- name: Aan de slag
  entities:
    switch.sw_office_cl:
      state: on
    switch.sw_tester_cl:
      state: on
    switch.sw_audio_auditorium_cl:
      state: off

- name: Tv kijken
  entities:
    switch.sw_audio_auditorium_cl:
      state: on
    switch.sw_office_cl:
      state: off
    switch.sw_tester_cl:
      state: off  

several automations:
- alias: Opstaan
id: ‘1511601478446’
trigger:
platform: state
entity_id: input_select.scenes
to: Opstaan
condition: []
action:
service: scene.turn_on
entity_id: scene.opstaan

- alias: Aan de slag
  id: '1511601478447'
  trigger:
    platform: state
    entity_id: input_select.scenes
    to: Aan de slag
  condition: []
  action:
    service: scene.turn_on
    entity_id: scene.aan_de_slag

- alias: Tv kijken
  id: '1511601478448'
  trigger:
    platform: state
    entity_id: input_select.scenes
    to: Tv kijken
  condition: []
  action:
    service: scene.turn_on
    entity_id: scene.tv_kijken

and my input-selector:

wat_te_doen:
  name: Wat te doen?
  icon: mdi:home
  options:
    - Opstaan
    - Aan de slag
    - Uit Huis
    - Tv Kijken
    - Naar bed
  initial: Aan de slag

Excellent timing, I’ve literally just done this with my master bedroom scenes, edit it to suit your entity_id’s and input_select options and you’re done :wink:

link removed

cool, thank you!

i’ve made it into this, but it doesn’t do its magic yet…
i don’t have scripts yet, so I’ve called the scenes directly, hope thats the right syntax.

Strange thing is in my <> theres only a input_select.wat_te_doen entity, no input_select.scenes. I don’t get any syntax error and have a green light for the configuration ;-

- alias: Opstaan
  id: '1511601478446'
  trigger:
    platform: state
    entity_id: input_select.scenes
    to: Opstaan
  condition: []
  action:
    service: scene.turn_on
    entity_id: scene.opstaan

- alias: Aan de slag
  id: '1511601478447'
  trigger:
    platform: state
    entity_id: input_select.scenes
    to: Aan de slag
  condition: []
  action:
    service: scene.turn_on
    entity_id: scene.aan_de_slag

- alias: Tv kijken
  id: '1511601478448'
  trigger:
    platform: state
    entity_id: input_select.scenes
    to: Tv kijken
  condition: []
  action:
    service: scene.turn_on
    entity_id: scene.tv_kijken

- alias: Uit huis
  id: '1511601478449'
  trigger:
    platform: state
    entity_id: input_select.scenes
    to: Uit huis
  condition: []
  action:
    service: scene.turn_on
    entity_id: scene.uit_huis

- alias: Naar bed
  id: '1511601478450'
  trigger:
    platform: state
    entity_id: input_select.scenes
    to: Naar bed
  condition: []
  action:
    service: scene.turn_on
    entity_id: scene.naar_bed

- alias: Trigger scene wat te doen
  trigger:
    platform: state
    entity_id: input_select.scenes
  action:
    service_template: >
      {% if is_state ('input_select.scenes' ,'Aan de slag') %} scene.turn_on.scene.aan_de_slag
      {% elif is_state ('input_select.scenes , Tv kijken') %} scene.turn_on.scene.tv_kijken
      {% elif is_state ('input_select.scenes , Uit huis') %} scene.turn_on.scene.uit_huis
      {% elif is_state ('input_select.scenes , Naar bed') %} scene.turn_on.scene.naar_bed
      {% elif is_state ('input_select.scenes , Opstaan') %} scene.turn_on.scene.opstaan
      {% endif %}

You can’t launch scenes like that, you’ll either have to do a script to activate the scene or modify the template to activate the scenes.

Did you define an input_select called scenes? If so, any errors, and have you put it in a group?

well, yes i had defined an input_select, posted in my starting message. Ive renamed them a bit, and it seems to be working now. Not sure if thats correct but this is what i have defined:

several scenes:

- name: Opstaan
  entities:
    switch.sw_espresso_keuken_cl:
      state: on

- name: Aan de slag
  entities:
    switch.sw_office_cl:
      state: on
    switch.sw_tester_cl:
      state: on
    switch.sw_audio_auditorium_cl:
      state: off

- name: Tv kijken
  entities:
    switch.sw_audio_auditorium_cl:
      state: on
    switch.sw_office_cl:
      state: off
    switch.sw_tester_cl:
      state: off  

several automations:

- alias: Tv kijken
  id: '1511601478448'
  trigger:
    platform: state
    entity_id: input_select.wat_te_doen
    to: Tv kijken
  condition: []
  action:
    service: scene.turn_on
    entity_id: scene.tv_kijken

my input_select:

wat_te_doen:
  name: Wat te doen?
  icon: mdi:home
  options:
    - Opstaan
    - Aan de slag
    - Uit huis
    - Tv kijken
    - Naar bed
  initial: Aan de slag

the automation for linking the input_select to the actual scenes:

- alias: Trigger scene wat te doen
  id: '1511601478451'
  trigger:
    platform: state
    entity_id: input_select.wat_te_doen
  action:
    service_template: >
      {% if is_state ('input_select.wat_te_doen' ,'Aan de slag') %} scene.turn_on.scene.aan_de_slag
      {% elif is_state ('input_select.wat_te_doen , Tv kijken') %} scene.turn_on.scene.tv_kijken
      {% elif is_state ('input_select.wat_te_doen , Uit huis') %} scene.turn_on.scene.uit_huis
      {% elif is_state ('input_select.wat_te_doen , Naar bed') %} scene.turn_on.scene.naar_bed
      {% elif is_state ('input_select.wat_te_doen , Opstaan') %} scene.turn_on.scene.opstaan
      {% endif %}

when i look at this last linking automation i wonder whether things could be defined more efficiently. I now have an input selector calling an automation calling a scene calling an automation calling switches… this is bound to go astray isn’t it?

And i havent even defined a script. although the whole sequence might be called a script…
Marius

Remove all the automations except the one that triggers from the input_select, and convert all the scenes to scripts, example:

Opstaan:
  sequence:
    - service: homeassistant.turn_on 
      entity_id: switch.sw_espresso_keuken_cl

Then call the script from the automation in the template I gave you earlier :+1:

cool. ill try that.
ill be back reporting :wink:

I’ve managed this but get invalid errors (did change the homeassistant.turn_on into switch.turn_on, to no avail, still invalid)
Yamllint is green…

And, most of all, the selector seems to be working alright.it turns on/off the scenes and switches.

aan_de_slag:
  alias: Aan de slag
  sequence:
    - service: switch.turn_on
      entity_id:
        switch.sw_office_cl
        switch.sw_tester_cl
    - service: switch.turn_off
      entity_id:
        switch.sw_audio_auditorium_cl

and scripting automation:

- alias: Trigger scene wat te doen
  id: '1511601478451'
  trigger:
    platform: state
    entity_id: input_select.wat_te_doen
  action:
    service_template: >
      {% if is_state ('input_select.wat_te_doen' ,'Aan de slag') %} script.aan_de_slag
      {% elif is_state ('input_select.wat_te_doen , Tv kijken') %} script.tv_kijken
      {% elif is_state ('input_select.wat_te_doen , Uit huis') %} script.uit_huis
      {% elif is_state ('input_select.wat_te_doen , Naar bed') %} script.naar_bed
      {% elif is_state ('input_select.wat_te_doen , Opstaan') %} script.opstaan
      {% endif %}

just to be complete, this is how my command line switches are declared. Hope this is correct for calling the service switch.turn_on and switch.turn_off:

sw_office_cl:
      friendly_name: 6 - Office
      command_on: >-
        curl -X POST -d '{"seq":1, "method":"object_prop_set", "arguments":{"oid":"430ba8cf", "prop":"command", "value":"on"}}' http://ip/iungo/api_request
      command_off: >-
        curl -X POST -d '{"seq":1, "method":"object_prop_set", "arguments":{"oid":"430ba8cf", "prop":"command", "value":"off"}}' http://ip/iungo/api_request
      command_state: >-
        curl -X POST -d '{"seq":1, "method":"object_prop_get", "arguments":{"oid":"430ba8cf", "prop":"state"}}' http://ip/iungo/api_request
      value_template: >-
        {%- if value_json.rv.value == 'on' -%}
        {{ true }}
        {%- else -%}
        {{ false }}
        {%- endif -%}

log error message:

Invalid config for [script]: Entity ID switch.sw_espresso_keuken_cl switch.sw_office_cl switch.sw_audio_auditorium_cl switch.sw_tester_cl is an invalid entity id for dictionary value @ data['script']['naar_bed']['sequence'][0]['entity_id']. Got 'switch.sw_espresso_keuken_cl switch.sw_office_cl switch.sw_audio_auditorium_cl switch.sw_tester_cl'
Entity ID switch.sw_office_cl switch.sw_tester_cl is an invalid entity id for dictionary value @ data['script']['aan_de_slag']['sequence'][0]['entity_id']. Got 'switch.sw_office_cl switch.sw_tester_cl'
Entity ID switch.sw_office_cl switch.sw_tester_cl is an invalid entity id for dictionary value @ data['script']['tv_kijken']['sequence'][1]['entity_id']. Got 'switch.sw_office_cl switch.sw_tester_cl'
Entity ID switch.sw_office_cl switch.sw_tester_cl is an invalid entity id for dictionary value @ data['script']['uit_huis']['sequence'][0]['entity_id']. Got 'switch.sw_office_cl switch.sw_tester_cl'. (See /config/configuration.yaml, line 76). Please check the docs at https://home-assistant.io/components/script/
1 Like

Try…

aan_de_slag:
  sequence:
    - service: switch.turn_on
      entity_id: switch.sw_office_cl
    - service: switch.turn_on
      entity_id: switch.sw_tester_cl
    - service: switch.turn_off
      entity_id: switch.sw_audio_auditorium_cl

bingo!
here we are:

39

on the left Wat gaan we doen, which are all scenes in a group, to the right of that, obviously the scripts, and below the input_selector.
Maybe some dressing up now, and my first scripts are a fact. Thank you @anon43302295!

still, im a bit puzzled what the benefit of these scripts are, since the end effect is the same as before, when I called the scenes in the service template:

service_template: >
          {% if is_state ('input_select.wat_te_doen' ,'Aan de slag') %} scene.turn_on.scene.aan_de_slag
          {% elif is_state ('input_select.wat_te_doen , Tv kijken') %} scene.turn_on.scene.tv_kijken
          {% elif is_state ('input_select.wat_te_doen , Uit huis') %} scene.turn_on.scene.uit_huis
          {% elif is_state ('input_select.wat_te_doen , Naar bed') %} scene.turn_on.scene.naar_bed
          {% elif is_state ('input_select.wat_te_doen , Opstaan') %} scene.turn_on.scene.opstaan
          {% endif %}

and now the scripts in the scrimping automation:

service_template: >
      {% if is_state ('input_select.wat_te_doen' ,'Aan de slag') %} script.aan_de_slag
      {% elif is_state ('input_select.wat_te_doen , Tv kijken') %} script.tv_kijken
      {% elif is_state ('input_select.wat_te_doen , Uit huis') %} script.uit_huis
      {% elif is_state ('input_select.wat_te_doen , Naar bed') %} script.naar_bed
      {% elif is_state ('input_select.wat_te_doen , Opstaan') %} script.opstaan
      {% endif %}

the scripts look rather clean but are not much smaller than the previously declared automations?

will have to re-read this to fully comprehend i guess.
cheers, and thanks again,
Marius

1 Like