Run specific script based on drop down menu?

Hi,

I just added Broadlink RM-4 mini IR remote and over 100 IR commands to HA. Each command is a specific script, which sends corresponding IR command to selected device. e.q. "amplifier_input_dvd".

I just learned how to make drop-down list for Lovelace UI, via configuration.yaml - let’s call it “input_select.amp_mode”. I also tried to automation with trigger states - input_select.amp_mode

  • But how to form action, based on input selector, to fire corresponding script? If user select amplifier as input, it should fire amplifier_input_dvd script.

My Google skills didn’t bring any solutions.

/ Simo

Here’s what you need:

- alias: "Netflix"
  initial_state: true
  trigger:
    platform: state
    entity_id: input_select.lounge_tv_amp
    to: 'Netflix'
  action:
    service: script.turn_on
    entity_id: script.netflix

Clearly, you’ll need to substitute your own input_select options and repeat the automation for each one, but I’m sure you get the idea.

Hey thanks Ash! Tested and working.

So basically I need as many automation scripts as I have items in drop down menu?

I’m going to implement this into AC controls as well and his has much more possibilities = much more automation scripts required. For development purposes I’m also looking a solution, where the “action” command is build using template (or smth) from drop down selection.

You need a script for each action, but only one automation to run any selection:

- id: b45469a5-05f1-40c7-90ad-9bd2b5a0f208
  alias: Automation Mode Select
  trigger:
    platform: state
    entity_id: input_select.automation_mode # trigger on any state change
  action:
    service: >
      {% if is_state('input_select.automation_mode', 'Away') %} script.away_mode
      {% elif is_state('input_select.automation_mode', 'Guest Away') %} script.guest_away_mode
      {% elif is_state('input_select.automation_mode', 'Guest Home') %} script.guest_home_mode
      {% elif is_state('input_select.automation_mode', 'Off') %} script.off_mode
      {% else %} script.normal_mode
      {% endif %}
2 Likes

That is, of course, a far more elegant way!