Possible to use 2 input types for automation?

Hi there.

I have a bunch of different scripts in my scripts.yaml, and would like to have on the lovelace front-end, input.select to choose among them and input.datetime to execute that chosen script at the selected time.

Specifically, it’s different scripts to control my air conditioner, one for each kind of mode+degree+fan speed.

Here’s an example for manual control using an input select, it uses shell commands but is just as valid for scripts.

- alias: 'Lounge Room Aircon'
  trigger:
    platform: state
    entity_id: input_select.lounge_ac_mode
  action:
  - service: >
      {% if is_state('input_select.lounge_ac_mode', 'Powerful Heat') %} shell_command.lounge_ac_powerful_heat
      {% elif is_state('input_select.lounge_ac_mode', 'Normal Heat') %} shell_command.lounge_ac_normal_heat
      {% elif is_state('input_select.lounge_ac_mode', 'Silent Heat') %} shell_command.lounge_ac_silent_heat
      {% elif is_state('input_select.lounge_ac_mode', 'Powerful Cool') %} shell_command.lounge_ac_powerful_cool
      {% elif is_state('input_select.lounge_ac_mode', 'Normal Cool') %} shell_command.lounge_ac_normal_cool
      {% elif is_state('input_select.lounge_ac_mode', 'Silent Cool') %} shell_command.lounge_ac_silent_cool
      {% elif is_state('input_select.lounge_ac_mode', 'Dry') %} shell_command.lounge_ac_dry
      {% elif is_state('input_select.lounge_ac_mode', 'Off') %} shell_command.lounge_ac_off
      {% endif %}

Because of the naming convention I’ve used I just noticed it could actually be simplified to:

- alias: 'Lounge Room Aircon'
  trigger:
    platform: state
    entity_id: input_select.lounge_ac_mode
  action:
  - service: "shell_command.lounge_ac_{{ states('input_select.lounge_ac_mode')|lower|replace(' ', '_') }}"

This takes the input select value, converts it to lowercase, replaces spaces with underscores and appends it to the shell command to be called.

For automatic control with an input date time add a time trigger instead of monitoring the input select for changes:

- alias: 'Lounge Room Aircon'
  trigger:
  - platform: time
    at: input_datetime.your_input_datetime_here
  action:
  - service: "shell_command.lounge_ac_{{ states('input_select.lounge_ac_mode')|lower|replace(' ', '_') }}"

So if you make sure your input select options are named with words matching the last part of your scripts - then yes this is do-able in a compact way.

1 Like

Thank you Tom, helpful as always!
I’ll give it a try and see how I go.

My original thoughts were to split the automation into 2 with a time trigger automation enabling a second automation for triggering the AC mode somehow.

But your way looks more elegant.