Calling Different Scripts for Different Options in a Select Template

How can I construct a select template to call associated scripts of the options. I have scripts with the following names:

  • Lower the Bed
  • Sleep in the Bed
  • Stop Bed Recording
  • Watch TV in Bed

I don’t understand how to construct the select_option block. Also I don’t see where the documentation for select_option is.

template:
  - select:
    - name: "Jay's Bed"
      state: "unknown"
      options: "Sleep, Watch TV, Flatten, Stop Recording"
      select_option:

thanks in advance

select_option is looking for an action. You can use any Action and it is constructed exactly like the action section in an automation or the sequence section of a script.

I’m going to start this with a disclaimer. I’ve only set up 4 template selects… and I’m not sure that they are much more useful than just using an input select and an automation for a basic select like this. For your situation I would use the following (you will need to set up an input text helper to make the state functional):

template:
  - select:
      - name: "Jay's Bed"
        state: "{{ states('input_text.jays_bed') }}"
        options: >
          {{ ['Sleep', 'Watch TV', 'Flatten', 'Stop Recording'] }}
        select_option:
          - service: input_text.set_value
            target:
              entity_id: input_text.jays_bed
            data:
              value: "{{ option }}"
          - service: script.turn_on
            target:
              entity_id: >
                {% set map = {
                'Sleep': 'sleep_in_the_bed', 
                'Watch TV': 'watch_tv_in_bed', 
                'Flatten': 'lower_the_bed', 
                'Stop Recording': 'stop_bed_recording'
                }%}
                script.{{ map.get(option) }}

That worked great. Thank you very much.

I was hoping that the select.jay_s_bed entity would be synced over to my Google Home through that integration. Is there a different way I should be thinking about this? I don’t see the entity in Google Home as I would a template switch.

1 Like