Struggling with input_select

I’m trying to create an automation that turns on one of three automations and the other two are turned off on a button press, cycling to the next at each button press.

Button pushed: once automation 1 is on, automations 2 and 3 are turned off
Button pushed again : automation 2 is turned on on and 1 and 3 are turned off

And then it cycles round.

I know that it’ll involve input_select.select_next. But I’m a bit confused about how to use it in an automation.

It’s basically to get multiple uses out of a single button.

What is the purpose of turning these three automations on/off?

I have an IKEA rotary switch that I want to have triple duty as two separate light dimmers and a volume control for my amplifier.

So the goal is to make the rotary switch serve three separate functions?

The input_select has three options where each option represents one of the rotary switch’s three functions?

Pressing the button steps through the input_select’s options?

If the answer is ‘Yes’ to all three questions then your requirements can be easily achieved without turning automations on/off. One automation can be used to step through the input_select’s options whenever the button is pressed. Another automation is triggered by the rotary switch and controls the appropriate device depending on the input_select’s current selection.

That’s two automations and neither are turned on/off to achieve the goal.

Let me know if that interests you.

That would be perfect and much cleaner than my solution, I was just grasping at straws to how I could do it and landed on turning automations on and off.

Which Zigbee integration are you using to receive data from the IKEA Rotary Switch? ZHA, deCONZ, or Zigbee2MQTT?

The one you use will determine the configuration of the Event Trigger in each of the two automations.

I assume that when you press the IKEA Rotary Switch, it should step from one operating mode to another? Or will you be using another kind of switch to do that?

Operating modes:

  1. Amplifier volume control
  2. Light dimmer #1
  3. Light dimmer #2

Another switch, the IKEA is purely rotary with no button function. Zigbee2MQTT

Trigger for a single function is currently this :

  trigger:
    platform: state
    entity_id: sensor.ikeaswitch_brightness

What is the model? I had assumed it was the IKEA E1744 SYMFONISK Rotary Remote (which supports button presses).

ICTC-G-1

I don’t have either of those rotary devices so the following automation is only meant to be a starting point and not a fully-completed solution.

alias: rotary control
id: rotary_control
mode: queued
trigger:
- platform: event
  event_type: state_changed
  event_data:
    entity_id: sensor.your_ikea_rotary
action:
- variables:
    event: "{{ trigger.event.data.new_state.state }}"
    mode: "{{ states('input_select.modes') }}"
- choose:
  - conditions: "{{ event == 'brightness_move_down' }}"
    sequence:
    - choose:
      - conditions: "{{ mode == 'Amplifier' }}"
        sequence:
        - service: media_player.volume_down
          target:
            entity_id: media_player.your_amplifier
      - conditions: "{{ mode == 'Kitchen Light' or mode == 'Living Room Light' }}"
        sequence:
        - service: light.turn_on
          target:
            entity_id: "light.{{ 'kitchen' if mode == 'Kitchen Light' else 'living_room' }}"
          data:
            brightness_step: -25
  - conditions: "{{ event == 'brightness_move_up' }}"
    sequence:
    - choose:
      - conditions: "{{ mode == 'Amplifier' }}"
        sequence:
        - service: media_player.volume_up
          target:
            entity_id: media_player.your_amplifier
      - conditions: "{{ mode == 'Kitchen Light' or mode == 'Living Room Light' }}"
        sequence:
        - service: light.turn_on
          target:
            entity_id: "light.{{ 'kitchen' if mode == 'Kitchen Light' else 'living_room' }}"
          data:
            brightness_step: 25

You will need to modify the names of its entities to match the ones you have.

  1. sensor.your_ikea_rotary
  2. input_select.modes
  3. media_player.amplifier
  4. light.kitchen
  5. light.living_room

It also requires you create an input_select with three options:

  1. Amplifier
  2. Kitchen Light
  3. Living Room Light

You will need to modify the option names to what you prefer (and update the names used in the automation accordingly).

For now, you can manually change the input_select to test the automation. After the automation is modified, tested, and confirmed to work properly, we can create the second automation to make a button-press step through the input_select’s options.


NOTE

In case the automation’s operation is unclear, here’s is pseudo-code explaining how it works:

trigger:
  When the rotary switch is rotated
action:
  Choose which direction it rotated:
    1. It rotated left (decreased)
       Choose which entity to control:
         1. input_select is set to Amplifier
            Decrease amplifier's volume
         2. input_select is set to one of the two lights:
            Decrease the light's brightness

    2. It rotated right (increased)
       Choose which entity to control:
         1. input_select is set to Amplifier
            Increase amplifier's volume
         2. input_select is set to one of the two lights
            Increase the light's brightness

Yup that’s clear. I am getting an error

Invalid config for [automation]: not a valid value for dictionary value @ data[‘action’][1][‘choose’][0][‘sequence’][0][‘choose’][1][‘sequence’][0][‘target’][‘entity_id’]. Got None. (See /config/configuration.yaml, line 35).

But I assume that’s because the option setup is not done yet.

My input_select is set up as :

input_select: 
  modes: 
    name: modes
    options:
      - amplifier
      - living room light
      - kitchen light

I can change names later when I get a hang on how input_select works. Is my config correct in relation to your automation because I’m still getting an error when I manually set the state.

Also, I’m not sure if brightness_move_up/down are used. This is the log entry when I rotate the switch :

Zigbee2MQTT:info 2021-05-02 20:18:29: MQTT publish: topic ‘zigbee2mqtt/ikeadimmer’, payload ‘{“action”:null,“battery”:74,“brightness”:40,“level”:255,“linkquality”:105,“rate”:195,“update”:{“state”:“idle”},“update_available”:false}’

This is how my automations.yaml looks now.

- id: rotary_control
  alias: rotary control
  mode: queued
  trigger:
  - platform: event
    event_type: state_changed
    event_data:
      entity_id: sensor.ikeaswitch_brightness
  action:
  - variables:
      event: "{{ trigger.event.data.new_state.state }}"
      mode: "{{ states('input_select.modes') }}"
  - choose:
    - conditions: "{{ event == 'brightness_move_down' }}"
      sequence:
      - choose:
        - conditions: "{{ mode == 'Amplifier' }}"
          sequence:
          - service: media_player.volume_down
            target:
              entity_id: media_player.room1_main
        - conditions: "{{ mode == 'Kitchen Light' or mode == 'Living Room Light' }}"
          sequence:
          - service: light.turn_on
            target:
              entity_id: "light.{{ 'front' if mode == 'Kitchen Light' else 'back' }}"
            data:
              brightness_step: -25
    - conditions: "{{ event == 'brightness_move_up' }}"
      sequence:
      - choose:
        - conditions: "{{ mode == 'Amplifier' }}"
          sequence:
          - service: media_player.volume_up
            target:
              entity_id: media_player.room1_main
        - conditions: "{{ mode == 'Kitchen Light' or mode == 'Living Room Light' }}"
          sequence:
          - service: light.turn_on 
            target:
              entity_id: "light.{{ 'front' if mode == 'Kitchen Light' else 'back' }}"
            data:
              brightness_step: 25

Am getting all sorts of syntax errors and can’t get your code through without errors no matter what I do to indentation or formatting, I think it’s related to you not using a hyphen on your code (- id) where mine is indented and the syntax of the conditions and formatting is too complicated for me to get my head around to fix.

I had assumed you were using the “simulated_brightness” feature described in the documentation. However, your configuration publishes the payload in JSON format with a brightness value so that will require a different approach to receive it.

If you have a sensor.ikeaswitch_brightness already then I believe the automation will simply need to use a State Trigger (instead of an Event Trigger). In addition, only one choose is required.

- id: rotary_control
  alias: rotary control
  mode: queued
  trigger:
    - platform: state
      entity_id: sensor.ikeaswitch_brightness
  action:
  - variables:
      val: "{{ trigger.to_state.state | int }}"
      mode: "{{ states('input_select.modes') }}"
  - choose:
    - conditions: "{{ mode == 'amplifier' }}"
      sequence:
        - service: media_player.volume_set
          target:
            entity_id: media_player.room1_main
          data:
            volume_level: "{{ val / 100 }}"
    - conditions: "{{ mode == 'kitchen light' or mode == 'living room light' }}"
      sequence:
        - service: light.turn_on
          target:
            entity_id: "light.{{ 'front' if mode == 'kitchen light' else 'back' }}"
          data:
            brightness_pct: "{{ val }}"

It’s difficult for me to determine why you’re experiencing that. The revised automation I just posted passes Check Configuration on my system and executes without generating errors.

The original version I posted was meant to be pasted into the Automation Editor in YAML mode. If you create your automations with a text editor then, yes, you must include a hyphen on the automation’s first line. That’s what I’ve done in the revised version of the automation.

I am using simulated brightness since that is the only way to get smooth operation of the dimmer, I assumed that I’d need to use the same entity_id here that I was referencing in my simple on mode dimmer operation since that worked.

I’ve pasted the above in text editor and since you kindly changed the entities for me I’ve made no changes. Unfortunately I’m still getting the automation error :

Invalid config for [automation]: not a valid value for dictionary value @ data[‘action’][1][‘choose’][1][‘sequence’][0][‘target’][‘entity_id’]. Got None. (See /config/configuration.yaml, line 35).

That’s a syntax error right?

Is this related to my input_select configuration? I was unsure whether mode: “{{ states(‘input_select.modes’) }}” refers to the name with the colon (modes:) or the name after name.

  modes: #< here
    name: modes #< or here
    options:
      - Amplifier
      - Living room light
      - Kitchen light

Not exactly. It’s referring to this line:

entity_id: "light.{{ 'front' if mode == 'kitchen light' else 'back' }}"

Unless you actually have light.front and light.back entities, it’s the likely cause of the error message.

Also, the values of the options in your input_select must exactly match the strings used in the template. For example, the template looks for “amplifier” (all lowercase):

conditions: "{{ mode == 'amplifier' }}"

However, in your latest post, you have defined it as “Amplifier” in the input_select. In your previous post, you defined it as “amplifier”. Whichever way you want it, you will have to ensure the template uses the correct spelling.


  modes: #< here <<<<------- Always this one when referring to it in a template.
    name: modes #< or here.  <<<<------ This is just for display in the Lovelace UI.
    options:
      - Amplifier
      - Living room light
      - Kitchen light

I’ve checked capitalisations and they’re the same now, Amplifier lost its capital somewhere along the way, light.front and light.back are the correct names for two of my bulbs.

The same error is appearing.

As mentioned previously, I tested the automation and it works. I cannot replicate the failure you have reported.

Post the automation here, exactly as it appears in your file, and I will review it.

It’s this line : entity_id: “light.{{ ‘front’ if mode == ‘Kitchen light’ else ‘back’ }}”

when I chop the code out and make it
entity_id: "light.front”

It passes with no errors, light.back passes without errors too.

- id: rotary_control
  alias: rotary control
  mode: queued
  trigger:
    - platform: state
      entity_id: sensor.ikeaswitch_brightness
  action:
  - variables:
      val: "{{ trigger.to_state.state | int }}"
      mode: "{{ states('input_select.switchoption') }}"
  - choose:
    - conditions: "{{ switchoption == 'amplifier' }}"
      sequence:
        - service: media_player.volume_set
          target:
            entity_id: media_player.room1_main
          data:
            volume_level: "{{ val / 100 }}"
    - conditions: "{{ switchoption == 'kitchen light' or switchoption == 'living room light' }}"
      sequence:
        - service: light.turn_on
          target:
            entity_id: "light.{{ 'front' if switchoption == 'kitchen light' else 'back' }}"
          data:
            brightness_pct: "{{ val }}"

I’ve uncapitalised everything and changed the input_select name to switchoption :

    
  switchoption: 
    name: switchoption_modes
    options:
      - amplifier
      - living room light
      - kitchen light

Now I know why I could not replicate the problem and why it doesn’t work for you:

  • You changed the automation and introduced an error.

Question: Where in your automation is the variable switchoption defined?
Answer: Nowhere and that’s why your modified automation fails.

You have to understand the increased difficulty of providing assistance when you make changes that you don’t reveal publicly. That’s why I asked you to post your automation because I suspected as much.

In this line:

mode: "{{ states('input_select.switchoption') }}"

Replace the word “mode” with “switchoption” so that the variable is defined for use elsewhere in the template.