There are projects that allow cycling through scenes with a button press on a Hue dimmer, such as this community post or this scene toggle blueprint. There are also HACS integrations for dynamic scenes, similar to the Hue app. However, I hadn’t seen a solution that combines both features.
This script lets you cycle through dynamic scenes in multiple areas using a single configuration. It supports multiple devices, each with unique area mappings, and cycles through scene presets on each button press.
Instructions
- Create a helper with type Number and name it
current_preset_index
. - Add the following automation to your configuration.
alias: Toggle over scenes when clicking on hue remote
description: >-
Cycle through scene presets on each button press, dynamically based on
triggering device
Supports multiple devices
Note it uses same counter for all rooms
triggers:
- device_id: 0d4455fe62a4f93668f4c5b52ed319f7
domain: zha
type: remote_button_short_press
subtype: turn_off
trigger: device
- device_id: 183d97576b582212c0e74c9565ab8010
domain: zha
type: remote_button_short_press
subtype: turn_off
trigger: device
actions:
- data:
preset_id: "{{ presets[current_index] }}"
targets:
area_id: "{{ areas }}"
transition: 45
interval: 60
action: scene_presets.start_dynamic_scene
- data:
entity_id: input_number.current_preset_index
value: "{{ (current_index + 1) % presets | length }}"
action: input_number.set_value
variables:
presets:
- 84ebc26c-9d61-4d25-830c-41ea66f1c325
- 7c6e81e7-d89a-4759-ae9e-b7c41e3fc0cb
- d8436b74-84b3-4750-83ba-fead7d94144f
- 5768805d-27c1-442e-b069-d20443485201
device_areas:
0d4455fe62a4f93668f4c5b52ed319f7:
- shower
- closet
183d97576b582212c0e74c9565ab8010:
- bathroom
current_index: "{{ states('input_number.current_preset_index') | int(default=0) }}"
areas: "{{ device_areas[trigger.event.data.device_id]}}"
mode: single