Input Select for scripts

Hello,

New to Home Assistant and really loving it. Have a question regarding input selects and scripts. I’m attempting to use an input select to call a hue scene which is a script, but the automation portion of this process is failing. Could anyone help me out? I spent an entire night troubleshooting this, lol.

  • alias: Scene Basement
    trigger:
    platform: state
    entity_id: input_select.scene_basement
    action:
    • service: script.turn_on
      data_template:
      entity_id: >
      {% if is_state( ‘input_select.scene_basement’, ‘Concentrate’ ) %}
      script.basement_concentrate
      {%-elif is_state( ‘input_select.scene_basement’, ‘Energize’ ) %}
      script.basement_energize
      {%-elif is_state( ‘input_select.scene_basement’, ‘Read’ ) %}
      script.basement_read
      {%-elif is_state( ‘input_select.scene_basement’, ‘Relax’ ) %}
      script.basement_relax
      {%-elif is_state( ‘input_select.scene_basement’, ‘Christmas’ ) %}
      script.basement_christmas
      {%-elif is_state( ‘input_select.scene_basement’, ‘Movie’ ) %}
      script.basement_movie
      {%-elif is_state( ‘input_select.scene_basement’, ‘Sunset’ ) %}
      script.basement_sunset
      {% endif %}
    • service: input_select.select_option
      data:
      entity_id: input_select.scene_basement
      option: “-”

Try using trigger.to_state (take a look here), and if you use more than one action, use a list (note the dashes).

- alias: Scene Basement
  trigger:
    platform: state
    entity_id: input_select.scene_basement
  action:
    - service: script.turn_on
      data_template:
        entity_id: >
          {% if trigger.to_state.state == 'Concentrate' %}
            script.basement_concentrate
          {%-elif trigger.to_state.state == 'Energize' %}
            script.basement_energize
          {%-elif trigger.to_state.state == 'Read' %}
            script.basement_read
          #your other options...
    - service: input_select.select_option
      data:
        entity_id: input_select.scene_basement
        option: "-"
1 Like

Thanks for the reply. I just tried you suggestion and it didn’t work. I’ve search quite a bit on this and have come up empty handed.

Please post your corrected automation again, using the preformated text tool (this --> < / >) from the toolbar.

Also, do you get any error on your log?

service: input_select.select_option
data:
  entity_id: input_select.scene_basement
  option: "-"

This is the reason why it won’t work, I think.
Show your input_select config.

This is my automation for an input_select

alias: 'Harmony'
trigger:
  - platform: state
    entity_id: input_select.harmony_comedor
    from: 'Seleccionar'
action:
  - service: remote.turn_on
    data_template:
      entity_id: remote.comedor
      activity: >
        {% if trigger.to_state.state == 'TV' %}
          13218560
        {% elif trigger.to_state.state == 'PLEX' %}
          16533666
        {% elif trigger.to_state.state == 'RADIO' %}
          11073575
        {% elif trigger.to_state.state == 'OFF' %}
          -1
        {% endif %}
  - service: input_select.select_option
    data:
      entity_id: input_select.harmony_comedor
      option: 'Seleccionar'
1 Like
alias: Scene Basement
trigger:
  platform: state
  entity_id: input_select.scene_basement
action:
  - service: script.turn_on
    data_template:
      entity_id: >
        {% if trigger.to_state.state == 'Concentrate' %}
          script.basement_concentrate
        {% elif trigger.to_state.state == 'Energize' %}
          script.basement_energize
        {% elif trigger.to_state.state == 'Read' %}
          script.basement_read
        {% elif trigger.to_state.state == 'Relax' %}
          script.basement_relax
        {% elif trigger.to_state.state == 'Christmas' %}
          script.basement_christmas
        {% elif trigger.to_state.state == 'Movie' %}
          script.basement_movie
        {% elif trigger.to_state.state == 'Sunset' %}
          script.basement_sunset
  - service: input_select.select_option
    data:
      entity_id: input_select.scene_basement
      option: "-"

I removed the option ‘-’ and still didn’t work. I have a logitech harmony hub with an input_select working just fine. I only encountered issues when referencing scripts. Thanks to everyone for your help so far.

scene_basement:
name: Scene
options:
- Select
- Concentrate
- Energize
- Reading
- Relax
- Christmas
- Movie
- Sunset
initial: ‘Select’
icon: mdi:lightbulb

The formatting tool was doing some weird things here so I didn’t use it. The input select seems to be working correctly. It’s the automation portion of the code that isn’t sending the script.turn_on cmd to the lights.

I notice there is no ‘endif’ statement at the end of ‘if’ … OR was it there but not shown here…?

Did you get this working?
used this and made a test, it works but i got an error every time getting this:
Invalid service data for script.turn_on: Entity ID is an invalid entity id for dictionary value @ data[‘entity_id’]. Got’ ’

works fine, but why this error :confused:

here are my automation

`- alias: House Mode
trigger:
platform: state
entity_id: input_select.home_preset
id: ‘’
action:

  • service: script.turn_on
    data_template:
    entity_id: >
    {% if trigger.to_state.state == ‘Softlights’ %}
    script.indoor_dimmed_light
    {% elif trigger.to_state.state == ‘Plugga’ %}
    script.hadashlocks
    {% elif trigger.to_state.state == ‘Party’ %}
    script.hadashscenes
    {% elif trigger.to_state.state == ‘Middag’ %}
    script.hadashoutside
    {% elif trigger.to_state.state == ‘Fullt Ljus’ %}
    script.indoor_light_full_on
    {% endif %}
  • service: input_select.select_option
    data:
    entity_id: input_select.home_preset
    option: Välj`

Did executing scripts thru an input_select ever get resolved? I’m struggling with this exact same thing in another thread and now wondering if there is an inherit issue with this approach?

his issue has nothing to do with yours. His syntax is wrong and he’s missing an else like you are. But I can’t tell if that’s your problem because you didn’t post your code in the other thread. Instead you came here to get help where there is miss direction. So, if you simply post your code you’ll get help… or you can continue to search the forums for some magical solution.

Just searching and found something similar. Sure, you want me to post ALL my code? I posted everything tied to the input_select other than the scripts and those work fine by themself but just wanted to make sure as my customizations are fairly decent and to your post, I don’t really keep anything in my configuration file.