Cycle through scenes with a button?

Hi,

I cant this one to work…?

I want to cycle through different scenes with a press on one button. I have setup a input select with automations, and these work.
I am trying to use input_select.select_next but that is not working

This is what i have so far:

#input select

input_select:
   living_room_scenes:
     name: Scenes
     options:
       - Full Brighness
       - Late Evening
       - Dim to 50%
     initial: Full Brighness
     icon: mdi:lightbulb-on-outline

#Scenes
  - name: Full Brighness
    entities:
        light.stue_loft:
            state: on
            brightness: 254
            color_temp: 363

  - name: Late Evening
    entities:
        light.stue_loft:
            state: on
            brightness: 25
            color_temp: 363

  - name: Dim to 50
    entities:
         light.stue_loft:
            state: on
            brightness: 127 
            color_temp: 363   

#Automations
- action:
  - data:
      entity_id: scene.Late_Evening
    service: scene.turn_on
  alias: sent stue
  condition: []
  id: '1517247483895'
  trigger:
  - entity_id: input_select.living_room_scenes
    platform: state
    to: Late Evening

- action:
  - data:
      entity_id: scene.full_brighness
    service: scene.turn_on
  alias: full stue
  condition: []
  id: '1517165268340'
  trigger:
  - entity_id: input_select.living_room_scenes
    platform: state
    to: Full Brighness

- action:
  - data:
      entity_id: scene.Dim_to_50
    service: scene.turn_on
  alias: 50% stue
  condition: []
  id: '1517163787601'
  trigger:
  - entity_id: input_select.living_room_scenes
    platform: state
    to: Dim to 50%

- action:
  - alias: ''
    data:
      entity_id: input_select.living_room_scenes
    service: input_select.select_next
  alias: test
  condition: []
  id: '1517316749974'
  trigger:
  - entity_id: sensor.living_room_switch
    platform: state
    to: 4_click
1 Like

@Joachim_Ahm_Mortense
I’m also interest cycling through scenes with a button as I have Insteon keypad 6 and that will be great. Did you managed to get it working?

1 Like

Hi @Starwolf73,

I something similar with a Xiaomi Smart Button, you need to make sure your input select works with your automation’s then use the below code with your own entity id.

##Lounge Fan Wall Switch
  - alias: Lounge Wall Fan Switch
    trigger:
    - platform: event
      event_type: click
      event_data:
        click_type: single
        entity_id: binary_sensor.switch_158d000201ce4e
    action:
    - service: input_select.select_next
      data: 
        entity_id: input_select.lounge_fan

Complete config can be found here

5 Likes

Wow @jimpower that is quite impressive setup and documentation you did there. I will definitely take a deeper look at your “Kingia Castle” setup as it is exactly this kind of home automation I’m going toward. Big thanks for sharing!!

I’ll try your code this week-end.

@Joachim_Ahm_Mortense this should work if input_select.select_next isn’t working.

trigger:
  - platform: state
    entity_id: sensor.living_room_switch
    to: 4_click
action:
  - service: input_select.select_option
    entity_id: input_select.living_room_scenes
    data_template:
      option: >
        {% set options = state_attr('input_select.living_room_scenes','options') -%}
        {% set selection = options.index(states('input_select.living_room_scenes')) -%}
        {% if (selection + 1) >= options | length -%}
        {{ options[0] }}
        {% else %}
        {{ options[selection + 1] }}
        {% endif %}
4 Likes

also trying same setup, but cant get it work. This is in my automation yaml. What im doing wrong?

input_select:
  yeecolors:
    name: Color mode
    options:
      - dim    
      - bright
- name: dim
  entities:
  light.yeelight_rgb_7c49eb0ff332:
    state: on
    transition: 2
    brightness_pct: 10
    kelvin: 5000
    
- name: bright
  entities:
  light.yeelight_rgb_7c49eb0ff332:
    state: on
    transition: 2
    brightness_pct: 100
    kelvin: 5000
    
  ##Cycle yeelight colors
- alias: Change light scenes
  trigger:
platform: event
event_type: click
event_data:
  entity_id: binary_sensor.switch_158d0001d8ea53
  click_type: double
  action:
service: input_select.select_next
data:
  entity_id: input_select.yeecolors

Can you please format your code by highlighting it and selecting the </> option from your window so I can see indentation cheers

full automation.yaml. lights on/off works well, long click works well, cycling doesnt work. Please, give advise

- alias: Toggle dining light on single press
  trigger:
    platform: event
    event_type: click
    event_data:
      entity_id: binary_sensor.switch_158d0001d8ea53
      click_type: single
  action:
    service: light.toggle
    entity_id:
    - light.yeelight_rgb_7c49eb0ff332
    - light.yeelight_rgb_7c49eb1028fd
    
- alias: Turn on light scene long click
  trigger:
    platform: event
    event_type: click
    event_data:
      entity_id: binary_sensor.switch_158d0001d8ea53
      click_type: long_click_press
  action:
    service: light.turn_on
    entity_id:
    - light.yeelight_rgb_7c49eb0ff332
    - light.yeelight_rgb_7c49eb1028fd
    data:
        brightness: 255
        kelvin: 2700
        
    input_select:
      yeecolors:
        name: Color mode
        options:
          - dim    
          - bright
- name: dim
  entities:
      light.yeelight_rgb_7c49eb0ff332:
        state: on
        transition: 2
        brightness_pct: 10
        kelvin: 5000
        
- name: bright
  entities:
      light.yeelight_rgb_7c49eb0ff332:
        state: on
        transition: 2
        brightness_pct: 100
        kelvin: 5000
        
  ##Cycle yeelight colors
- alias: Change light scenes
  trigger:
    platform: event
    event_type: click
    event_data:
      entity_id: binary_sensor.switch_158d0001d8ea53
      click_type: double
  action:
    service: input_select.select_next
    data:
      entity_id: input_select.yeecolors

Try this

Put this into your input_select

input_select:
  yeecolours:
    name: Color Mode
    options:
      - dim
      - bright
    initial: bright

this in your scene

scene:
  - name: Dim
    entities:
      light.yeelight_rgb_7c49eb0ff332:
          state: on
          transition: 2
          brightness_pct: 10
          kelvin: 5000
		  
  - name: Bright
    entities:
      light.yeelight_rgb_7c49eb0ff332:
          state: on
          transition: 2
          brightness_pct: 100
          kelvin: 5000

This is your automations you will need to get your scene id from the states tab in HA and insert below where I have scene.yourscenehere

automation:
  - alias: Yeelight Dim
    trigger:
    - platform: state
      entity_id: input_select.yeecolors
      to: dim
    action:
    - service: scene.yoursceneidhere
	
  - alias: Yeelight Bright
    trigger:
    - platform: state
      entity_id: input_select.yeecolors
      to: bright
    action:
    - service: scene.yoursceneidhere
	
  - alias: Change light scenes
    trigger:
    - platform: event
      event_type: click
      event_data:
        click_type: double
        entity_id: binary_sensor.switch_158d0001d8ea53
    action:
    - service: input_select.select_next
      data: 
        entity_id: input_select.yeecolors
2 Likes

thanks for your time. Im new to home automation. Check config button gives error

Invalid config for [automation]: [input_select] is an invalid option for [automation]. Check: automation-&gt;action-&gt;0-&gt;input_select. (See /config/configuration.yaml, line 67). Please check the docs at https://home-assistant.io/components/automation/

can you explain which scene id from the states tab should i enter? Thank you

So you need to follow the steps I have provided above, the input_select does not go in the automation section.

Step One - Add input_select into your configuration.yaml file exactly as above.

Step Two - Add your scenes to your scene.yaml or configuration.yaml file depending on how you handle scenes, then reboot HA this will add the input_select & scenes and make them available for automations.

Step Three - Add automations to your automation.yaml and reboot.

Once HA Comes back up you can call your automations from the service button to ensure they work.

1 Like

thank you, now i understand hassio structure much better.
Still struggling with this. Light doesnt respond to double click if input select and scenes are not connected. But from webui i can activate scenes. Where is my mistake?

input_select:
  yeecolours:
    name: Color Mode
    options:
      - dim
      - bright
    initial: bright
    icon: mdi:palette

scene:
  - name: dim
    entities:
      light.yeelight_rgb_7c49eb0ff332:
          state: on
          transition: 1
          brightness_pct: 10
          kelvin: 5000

  - name: bright
    entities:
      light.yeelight_rgb_7c49eb0ff332:
          state: on
          transition: 1
          brightness_pct: 100
          kelvin: 5000

automations.yaml

  - alias: Yeelight Dim
    trigger:
    - platform: state
      entity_id: input_select.yeecolours
      to: dim
    action:
    - service: scene.dim

  - alias: Yeelight Bright
    trigger:
    - platform: state
      entity_id: input_select.yeecolours
      to: bright
    action:
    - service: scene.bright

  - alias: Change light scenes
    trigger:
    - platform: event
      event_type: click
      event_data:
        entity_id: binary_sensor.switch_158d0001d8ea53
        click_type: double
    action:
    - service: input_select.select_next
      data: 
        entity_id: input_select.yeecolours
1 Like

Thanks a lot! At last i got it working. Made some changes to automations.yaml

  - alias: Yeelight Dim
    trigger:
      platform: state
      entity_id: input_select.yeecolours
      to: dim
        action:
          service: scene.turn_on
          entity_id: scene.dim

  - alias: Yeelight Bright
    trigger:
      platform: state
      entity_id: input_select.yeecolours
      to: bright
    action:
      service: scene.turn_on
      entity_id: scene.bright

  - alias: Change light scenes
    trigger:
      platform: event
      event_type: click
      event_data:
        entity_id: binary_sensor.switch_158d0001d8ea53
        click_type: double
    action:
      service: input_select.select_next
      data: 
        entity_id: input_select.yeecolours
1 Like

Sorry didn’t see this until you had fixed it well done.

found good solution to reduce amount of code if you have many scenes.
Instead of commented block i used data_template. Works. Cheers

#   - alias: Yeelight Dim
#     trigger:
#       platform: state
#       entity_id: input_select.yeecolours
#       to: dim
#     action:
#       service: scene.turn_on
#       entity_id: scene.dim

#   - alias: Yeelight Bright
#     trigger:
#       platform: state
#       entity_id: input_select.yeecolours
#       to: bright
#     action:
#       service: scene.turn_on
#       entity_id: scene.bright

  - alias: Yeelight scenes
    trigger:
      platform: state
      entity_id: input_select.yeecolours
    action:
      service: scene.turn_on
      data_template:
        entity_id: scene.{{trigger.to_state.state}}
3 Likes

If you have spaces in your input_selects and scenes add these jinja2 filters | replace(" ","_") | lower

So like this:

- alias: Living Room Scenes
  trigger:
    platform: state
    entity_id: input_select.living_room_scenes
  action:
    - service: scene.turn_on
      data_template:
        entity_id: scene.{{trigger.to_state.state | replace(" ","_") | lower}}
3 Likes

I would love to use this solution for cycling through scenes (and playlist-entries) within Node-Red. Has anyone tried this perhaps? Will be thankful for any hints.

I’m using this:

in configuration.yaml

input_select:
   huiskamer_scenes:
     name: Huiskamer Scenes
     options:
       - uit (huiskamer)
       - soft achter (huiskamer)
       - soft voor en achter (huiskamer)
       - soft voor (huiskamer)
       - fel (huiskamer)
     initial: uit (huiskamer)
     icon: mdi:lightbulb-on-outline

and in automations.yaml

- id: '1583839323446'
  alias: zb switch A 2 huiskamer
  initial_state: 'on'
  trigger:
    platform: event
    event_type: deconz_event
    event_data:
      id:  zb_switch_a
  action:
  - service: input_select.select_option
    entity_id: input_select.huiskamer_scenes
    data_template:
      option: >
        {% set options = state_attr('input_select.huiskamer_scenes','options') -%}
        {% set selection = options.index(states('input_select.huiskamer_scenes')) -%}
        {% if trigger.event.data.event == 1002 -%}
          {% if (selection + 1) >= options | length -%}
            {{ options[1] }}
          {% else -%}
            {{ options[selection + 1] }}
          {% endif %}
        {% else %}
          {% if trigger.event.data.event == 2002 -%}
            {{ options[0] }}
          {% endif -%}
        {% endif -%}
  - service: scene.turn_on
    data_template:
      transition: 1
      entity_id: scene.{{states('input_select.huiskamer_scenes') | replace(" ","_") | replace("(","") | replace(")","") | lower}}

The options: script cycles through all options pressing the on (I) button, except for option 0 (off), which is only selected when the off (o) zigbee button is pressed.

I’m using the IKEA tradfri with deconz-II


https://phoscon.de/en/conbee2
3 Likes

To teach myself the new scripting features in 0.113, I modified your automation to use the new choose feature. It is useful when the action must choose between different services and especially when the services have different options. Although it can be done entirely with templates, the result is a bit messy; the choose feature makes it neater.

Here’s how it works:

  • If the event is 1002, it calls select_next.
  • If the event is 2002, it sets the input_select to its first option.
  • Finally, the action calls scene.turn_on and computes the scene’s name. I shortened the template slightly by using regex_replace to remove ( and ) characters.
- id: '1583839323446'
  alias: zb switch A 2 huiskamer
  initial_state: 'on'
  trigger:
    platform: event
    event_type: deconz_event
    event_data:
      id:  zb_switch_a
  action:
    - choose:
        - conditions:
            - condition: template
              value_template: "{{trigger.event.data.event == 1002}}"
          sequence:
            service: input_select.select_next
            entity_id: input_select.huiskamer_scenes
        - conditions:
            - condition: template
              value_template: "{{trigger.event.data.event == 2002}}"
          sequence:
            service: input_select.select_option
            data_template:
              entity_id: input_select.huiskamer_scenes
              option: "{{state_attr('input_select.huiskamer_scenes','options')[0]}}"
    - service: scene.turn_on
      data_template:
        transition: 1
        entity_id: >
          scene.{{states("input_select.huiskamer_scenes").replace(" ","_") | regex_replace(find="[\(\)]", replace="") | lower }}
4 Likes

Wow that looks lots better :grinning:
Only question I have is, in my earlier script it skipped option 0 as this is the Off option, which I do not want to cycle through.
How does your script prevent that ?