Keep input_select status synced

Hi there,

I’m new to Home Assistant, and I’m having some difficulties with my first project’s configuration.
I’m using an input_select in Home Assistant to control my home cinema’s state.
How can I use the status returned by a Shell script to switch the input_select’s position?

Context:
There’s an input_select for the mode (off / Playstation / Apple TV / …) that calls a Python script I wrote. The script then takes care of turning on / off the devices, and set the right inputs. It can also read the home cinema’s status and returns the current status. I wired it to a Home Assistant sensor, which displays the home cinema’s status - so far, so good.
Now I need to use the value returned by my script to keep the input_select in the actual position the home cinema is.
Let’s say I turn it on with Home Assistant, set it to Playstation Mode, then turn it off using the IR remote. How can I have the input_select go back to the “off” state?

Thanks in advance for the help :slight_smile:

Jeremy

Take a look at Template Switch - it should do what you want.

Ok, if you have a sensor that has the current state of your home cinema, and you want to keep your input_select synced with that state, use an automation with a trigger on the state changing, and an action that calls the input_select.select_option service with the triggered state.

Automation trigger: https://home-assistant.io/getting-started/automation-trigger/
Automation action: https://home-assistant.io/getting-started/automation-action/
Using value in service call: https://home-assistant.io/getting-started/scripts-service-calls/#use-templates-to-determine-the-attributes

Thanks guys!

Found this thread and thought of an input select automation I’ve been meaning to update. Thought I’d share my example in case anyone else needs it. sensor.ecobee_hvac references a thermostat attribute. service input_select.select_option requires entity_id and option.

- alias: Thermostat - Select
  trigger:
    - platform: state
      entity_id: sensor.ecobee_hvac
      state: 'cool'
    - platform: state
      entity_id: sensor.ecobee_hvac
      state: 'heat'
    - platform: state
      entity_id: sensor.ecobee_hvac
      state: 'auto'
    - platform: state
      entity_id: sensor.ecobee_hvac
      state: 'off' 
  action:
    service: input_select.select_option
    entity_id: input_select.thermo_hvac
    data_template:
      option: >
        {% if is_state('sensor.ecobee_hvac', 'auto') %}
          Auto
        {% elif is_state('sensor.ecobee_hvac', 'cool') %}
          Cool
        {% elif is_state('sensor.ecobee_hvac', 'heat') %}
          Heat
        {% elif is_state('sensor.ecobee_hvac', 'off') %}
          Off
        {% else %}
        {% endif %}
1 Like

Here is the inverse of the previous automation using the input_select as the trigger:

- alias: Thermostat - Select Input
  trigger:
    - platform: state
      entity_id: input_select.thermo_hvac
      state: 'Auto'
    - platform: state
      entity_id: input_select.thermo_hvac
      state: 'Cool'
    - platform: state
      entity_id: input_select.thermo_hvac
      state: 'Heat'
    - platform: state
      entity_id: input_select.thermo_hvac
      state: 'Off'
  action:
    service: thermostat.set_hvac_mode
    entity_id: thermostat.ecobee
    data_template:
      hvac_mode: >
        {% if is_state('input_select.thermo_hvac', 'Auto') %}
          auto
        {% elif is_state('input_select.thermo_hvac', 'Cool') %}
          cool
        {% elif is_state('input_select.thermo_hvac', 'Heat') %}
          heat
        {% elif is_state('input_select.thermo_hvac', 'Off') %}
          off
        {% else %}
        {% endif %}

Also examples for input_boolean:

- alias: Thermostat - Away Input
  trigger:
    - platform: state
      entity_id: sensor.ecobee_away
      state: 'on'
    - platform: state
      entity_id: sensor.ecobee_away
      state: 'off'
  action:
    service_template: >
      {% if is_state('sensor.ecobee_away', 'off') %}
        homeassistant.turn_off
      {% elif is_state('sensor.ecobee_away', 'on') %}
        homeassistant.turn_on
      {% else %}
      {% endif %}
    entity_id: input_boolean.thermo_away

and

- alias: Thermostat - Input Away
  trigger:
    - platform: state
      entity_id: input_boolean.thermo_away
      state: 'on'
    - platform: state
      entity_id: input_boolean.thermo_away
      state: 'off'
  action:
    service: thermostat.set_away_mode
    entity_id: thermostat.ecobee
    data_template:
      away_mode: >
        {% if is_state('input_boolean.thermo_away', 'off') %}
          off
        {% elif is_state('input_boolean.thermo_away', 'on') %}
          on
        {% else %}
        {% endif %}
3 Likes