Toggle scenes / light scenarios

Can you help me create a script for a single button press to toggle between multiple light scenes/scenarios? I believe it should include a state so the script know what scene comes next.

I still haven’t decided if I should toggle between hue.scenes or light config in yaml, as I haven’t selected my path on lights yet (IKEA or HUE).

Example on what needs to be toggled if we go with the script (activates a Hue Scene):
group_name: Sofa
scene_name: Bright
scene_name: Relax
scene_name: Party

Just added the yaml code here.

  • id: ‘1583061829815’
    alias: Ny automatisering toggle test
    description: ‘’
    trigger:
    • device_id: 80188063433d445986cdc3bfa1f7fd89
      domain: deconz
      platform: device
      subtype: turn_off
      type: remote_button_short_press
      condition: []
      action:
    • data:
      group_name: Sofa
      scene_name: Bright
      service: hue.hue_activate_scene
    • data:
      group_name: Sofa
      scene_name: Relax
      service: hue.hue_activate_scene
    • data:
      group_name: Sofa
      scene_name: Party
      service: hue.hue_activate_scene

Thanks

You could create an input select that your automation would select next as the action. Then another automation that would select scene based on the input select.

input_select:
  scene_select:
    options:
      - Bright
      - Relax
      - Party

automation:
  - alias: 'Ny automatisering toggle test'
    trigger:
      - platform: device
        domain: deconz
        device_id: 80188063433d445986cdc3bfa1f7fd89
        subtype: turn_off
        type: remote_button_short_press
    action:
      service: input_select.select_next
      entity_id: input_select.scene_select

  - alias: 'Send scene'
    trigger:
      - platform: state
        entity_id: input_select.scene_select
    condition:
      - condition: template
        value_template: "{{ trigger.to_state != trigger.from_state }}"
    action:
      service: hue.hue_activate_scene
      group_name: Sofa
      data_template: 
        scene_name: "{{ states('input_select.scene_select') }}"
2 Likes

Hi walrus

Thanks for your input. I need to ask for more clarification as I need to understand this better.

I understand the first automation is both the trigger and action for the scene select, but in the second automation I dont understand how this knows what scene it comes from and should go to next - i guess this is in the to.state and from state, but as there is not selection of scenes, how does it know which to selected from?

Hope this could be clarified :slight_smile:

Thanks

From your explanation, you would like the scenes to cycle when you press a button. This can be done easily through an input select.

Since an initial option is not set on the input select, it will retain the last selected option through HA restarting. The entity would have “Bright” as its state on first boot. If you want a particular scene to be the first every time, you can set an initial option.

The second automation triggers when the input select entity changes. Since the input select options match the scenes you are sending to Hue, we can send the input select option in a data template. However, the condition might not be needed. It is only passing the action if the states are different (“to state” is “not equal” to “from state”).

Yes, I would like the button to cycle between (3) Hue Scenes which is defined in the Hue iOS app which can be called through a service call. Alternative is to cycle between 3 HA scripts that activates the different Hue Scenes.

I unfortunately still don’t see the code functioning, but to give you the overview this is how far I have gotten:

  • id: ‘1578179040304’
    alias: Ny automatisering toggle Hovedregel
    description: test
    trigger:

    • device_id: 80188063433d445986cdc3bfa1f7fd89
      domain: deconz
      platform: device
      subtype: turn_off
      type: remote_button_short_press
      condition: []
      action:
    • entity_id: input_select.scene_select
      service: input_select.select_next
  • id: ‘1583139096365’
    alias: ‘Ny automatisering toggle #1
    description: Første flow
    trigger:

    • entity_id: input_select.scene_select
      platform: state
      condition:
    • condition: template
      value_template: ‘"{{ trigger.to_state != trigger.from_state }}"’
      action:
    • data:
      group_name: Anemone
      data_template:
      scene_name: ‘{{ states(’’’‘input_select.scene_select’’’’) }}’
      service: hue.hue_activate_scene

Personally i dont think the service call gets to Philips Hue with scene.select. I think this stays in HA. Whats you call on that?

When you are pasting yaml code, place ``` before and after so that the formatting is maintained.

value_template: ‘"{{ trigger.to_state != trigger.from_state }}"’ #where did the single fancy quotes come from? They are not valid in yaml.

scene_name: ‘{{ states(’’’‘input_select.scene_select’’’’) }}’ #make sure single or doubles quotes are outside, the other inside shown in my example above.

Something is happening when you are copying and pasting the code. Make sure they are not “fancy” quotes as they are not valid in yaml.

The statement might be right, but as hue.scene is not an HA scene input_select.scene_select does not go to Hue. I think thats the problem.

I could create the scenes to fire a call service to Hue for each scene, as a “middle-man”… that would solve it I think. I will test.

Yes, it is probably not being sent because the quotes around the template are not valid.

The input_select is the middle man.

Looking at the example in the docs, the group name should be moved into the data_template section with quotes around it.

script:
  porch_on:
    sequence:
      - service: hue.hue_activate_scene
        data:
          group_name: "Porch"
          scene_name: "Porch Orange"
  - alias: 'Send scene'
    trigger:
      - platform: state
        entity_id: input_select.scene_select
    condition:
      - condition: template
        value_template: "{{ trigger.to_state != trigger.from_state }}"
    action:
      service: hue.hue_activate_scene
      data_template: 
        group_name: 'Anemone'
        scene_name: "{{ states('input_select.scene_select') }}"

Thank for your help on this, I’m doing the same thing, I’m wondering where Bright, Relax and Party are defined, for example if I create a custom scene called Dimmed50 at all light 50%, where exactly is it defined as “Dimmed50”. The rest all makes sense.

I’m probably over complicating it, is it as simple as it just uses “name: Dimmed50” as below.

In configuration.yaml

input_select:
  lr_brightness:
    options:
      - Dimmed50
      - Dimmed99
      - Bright

In the automation.yaml

automation:
  - alias: LR Dim Rotation
    trigger:
      platform: event
      event_type: "smartthings.button"
      event_data:
        component_id: "button4"
        name: "LR Aeotec Remote"
        value: "pushed"
    action:
      service: input_select.select_next
      entity_id: input_select.lr_brightness

In scenes.yaml

- id: '1592734165530'
  name: Dimmed50
  entities:
    light.hue_filament_bulb_1:
      brightness: 126
      friendly_name: Hue filament bulb 1
      state: 'on'
      supported_features: 41

- id: '1592734165531'
  name: Bright
  entities:
    light.hue_filament_bulb_1:
      brightness: 255
      friendly_name: Hue filament bulb 1
      state: 'on'
      supported_features: 41

It appears when I create scenes using the scene creator tool, they don’t actually appear in scenes, nor entities. I think this could be a key component of why it’s not working.

FIXED: When I try to call the scene, using the id since the name isn’t in the list, I simply get this:

Could it be the existence of this piece of code in the Configuration.yaml which is causing it to skip other scenes I’m creating in the scenes.yaml?

scene:
  platform: hunterdouglas_powerview
  address: 192.168.0.13

EDIT FIX: I moved the above from configuration.yaml in to the scenes.yaml, now all of my scenes are loading correctly as entities.

Still not getting them to fire off through input select though.

SOLVED (for me): This will enable one physical button to cycle through scenes using the Smartthings Hub using the event_type: “smartthings.button”

Create your Scenes in scene creator (Configuration -> Scenes).

The scene creator will save the current state of your devices at the time you save them, for example 3 different dim levels are 3 different scenes, set the dim level (I did it on my hue phone app), save the scene.

Once created, the name you have chosen for your scene is simply the friendly name you use in the Menu under the options. You can find them all in File Editor -> Open -> Scenes.yaml

Here’s the scene entity example:

- id: '1592734165530'
  name: Dimmed50
  entities:
    light.hue_filament_bulb_1:
      brightness: 126
      friendly_name: Hue filament bulb 1
      state: 'on'
      supported_features: 41
- id: '1592735231307'
  name: LR Bright
  entities:
    light.hue_filament_bulb_1:
      brightness: 255
      friendly_name: Hue filament bulb 1
      state: 'on'
      supported_features: 41
- id: '1592735550593'
  name: LR Max Dim
  entities:
    light.hue_filament_bulb_1:
      brightness: 1
      friendly_name: Hue filament bulb 1
      state: 'on'
      supported_features: 41

Create your Input Select in the Configuration.yaml
This is your “menu”, so pop those names you created earlier in to the menu like so:

#Create Menu
input_select:
  lr_brightness: #Custom Variable
    options:
      - Dimmed50
      - LR Max Dim
      - LR Bright
    initial: LR Bright

In automations.yaml create your trigger for the button then create actual scene selections
Configuring “Actions”:
You want to use the preexisting service: input_select.select_next
This will cycle through the input_select “menu” defined in your Entity ID below

Your Entity_id must link to the custom variable (your chosen name, lr_brightness in my case) as seen above:

input_select.lr_brightness

#Automate Scene Rotation on Button2 Held      
  - alias: LR Dim Rotation
    trigger:
      platform: event
      event_type: "smartthings.button"
      event_data:
        component_id: "button2"
        name: "LR Aeotec Remote"
        value: "held"
    action:
      service: input_select.select_next
      entity_id: input_select.lr_brightness

Next the Actual Scene selections
Configure trigger -> “to:” with your Menu option name
Configure action -> “entity_id:” to the scene entity.

To confirm the scene entity go to Developer Tools -> Services and confirm the name of your entity:
image

Also in Automations.yaml

#Create Scene Selection 
  - alias: Full Brightness selected
    trigger:
      platform: state
      entity_id: input_select.lr_brightness
      to: "LR Bright"
    action:
      service: scene.turn_on
      entity_id: scene.lr_bright

  - alias: 50% Brightness
    trigger:
      platform: state
      entity_id: input_select.lr_brightness
      to: "Dimmed50"
    action:
      service: scene.turn_on
      entity_id: scene.dimmed50

  - alias: Dimmed
    trigger:
      platform: state
      entity_id: input_select.lr_brightness
      to: "LR Max Dim"
    action:
      service: scene.turn_on
      entity_id: scene.lr_max_dim

Done

4 Likes

does somebody have a blueprint for this ? thx

3 Likes

Hey Chrisxsxs,

This is an awesome workflow and I think I’ve almost got it figured out for my own setup but I’m a little lost as to what you mean in the section where you refer to the “Actual Scene Selections”

Next the Actual Scene selections
Configure trigger → “to:” with your Menu option name
Configure action → “entity_id:” to the scene entity.

Could I possibly beg you to expand on what needs to be done here, please? Sorry I’m new to HA and really want to get this working.

Someone made a blueprint to do just that: