I have recently migrated from Philips Hue to Home assistant. I am quite a noob in HA automations but it seems that it has quite a freedom to do what I want.
There is one feature I really liked in Philips Hue with a Hue Smart Button. With this button I was able to turn the lights on/off (when pressing it), switch scenes (when pressing it with short delay between button presses) and dim up/down (long press of the button). I kind of see how could I achieve the on/off and dimming behavior but do not know how to arrange switching between scenes. Could you please help me with the ideas on how to do that?
I’d create an input_select with the names of the different scenes, then on each button press select the next element in the input_select and execute the corresponsing scene.
If you want to setup toggling for scenes, you will need to create an input_select first and then the rest can be done with a ControllerX config.
The first thing we would need to do is get the mapping for the Hue Smart Button. Which integration are you currently using? And could you provide the events that the controller fire when pressing, double pressing (if any), hold, release.
Thanks for your reply. I implemented the scene switching with input_select and I was already looking at ControllerX documentation to see how could I achieve the behavior I am looking for.
I am currently using deconz for switch but could also change to Hue integration if it will be needed. I am quite a noob in the home assistant automation and do not know how could I check for events. I would be happy to help you if needed. Currently in HA, I have these triggers available:
Thank you for your reply. Since ControllerX does not yet support this controller, we need to define the full mapping for each controller config. Imagine you have the following input_select:
Then, you will need the following ControllerX config in the apps.yaml:
# Generic config to change option of the input_select when double clicking the button
example_app:
module: controllerx
class: LightController
controller: <controller name in deCONZ>
integration: deCONZ
light: light.my_light
mapping:
1002: toggle
1002$2:
service: input_select.select_next
data:
entity_id: input_select.light_state
1001: hold_brightness_toggle
1003: release
# Config for scene1
example_app_scene_1:
module: controllerx
class: Controller
controller: <controller name in deCONZ>
integration: deCONZ
mapping:
1002$2:
scene: scene.scene1
constrain_input_select: input_select.scenes,scene1
# Config for scene2
example_app_scene_2:
module: controllerx
class: Controller
controller: <controller name in deCONZ>
integration: deCONZ
mapping:
1002$2:
scene: scene.scene2
constrain_input_select: input_select.scenes,scene2
# Config for scene3
example_app_scene_3:
module: controllerx
class: Controller
controller: <controller name in deCONZ>
integration: deCONZ
mapping:
1002$2:
scene: scene.scene3
constrain_input_select: input_select.scenes,scene3
This assumes that you use the same light when changing scenes. Once I add support for this controller, you will be able to reduce a bit this config, but you will still need one config for each scene.
Took me a bit too long to start up app daemon addon. I have tried your config but there is something wrong in the behavior of the button. Also I changed ‘deCONZ’ to ‘deconz’ as appdaemon was not able to load it otherwise. I am able to toggle it on/off and dim but scene switching did not work. input_selector value changed but not the scene. I will try to fix it myself but not sure if I will manage.
I also checked how the button behaves when I pressed it:
one press: 1000 and 1002 event
two/three short presses with short interval(which I would like to use for scene switching) : 2/3x 1000 and 1002 events
long press: 1000 at start, couple of 1001 events which appear with constant interval when the button is pressed and 1003 at finish
For a Hue Dimmer switch (Philips) I couldn’t get the double_click action config to work either in order to cycle through a list of scenes.
For a while tried to read out current state of “input_select.scene_selector” to get the target value for next action “scene:” but failed.
Eventually managed the intended scene cycling to work upon <single click ‘I’> events.
Now the effective action on single <Click ‘I’> event (1002) is dependent on the state of the ‘my_light’ by adding another input_boolean.my_light helper plus a corresponding example_app_<on|off> yaml block.
Config below preserves all predefined ControllerX.action mappings.
The required repetition of code for each scenery-action-yaml smells DRY though. Not sure if its feasible for more than a dozen scenes for round robin.
Nevertheless, does work to go through my half a dozen scenes.
Thanks @xaviml for making ControllerX and for the use case config here.
# Generic config to change option of the input_select when double clicking the button
#
# current light.my_light.state == off
example_app_off:
module: controllerx
class: LightController
controller: <controller name in deCONZ>
integration: deconz
light: light.my_light
mapping:
1002:
- action: 'on'
# - scene: scene.scene1 # optional: set a fixed scene at 'on'
- service: input_boolean.turn_on
data:
entity_id: input_boolean.my_light
constrain_input_boolean: input_boolean.light_my_light,off
# current light.my_light.state == on
example_app_on:
module: controllerx
class: LightController
controller: <controller name in deCONZ>
integration: deconz
light: light.my_light
mapping:
1002:
- service: input_select.select_next
data:
entity_id: input_select.scene_selector
4002: # Hue Dimmer switch (Philips)
- action: 'off'
- service: input_boolean.turn_off
data:
entity_id: input_boolean.my_light
1001: hold_brightness_toggle
1003: release
# depending on the controller add all states relevant for state context 'on' here
constrain_input_boolean: input_boolean.light_my_light,on
# Config for scene1
example_app_scene_1:
module: controllerx
class: Controller
controller: <controller name in deCONZ>
integration: deconz
mapping:
1002:
scene: scene.scene1
constrain_input_select: input_select.scenes,scene1
# Config for scene2
example_app_scene_2:
module: controllerx
class: Controller
controller: <controller name in deCONZ>
integration: deconz
mapping:
1002:
scene: scene.scene2
constrain_input_select: input_select.scenes,scene2
# Config for scene3
example_app_scene_3:
module: controllerx
class: Controller
controller: <controller name in deCONZ>
integration: deconz
mapping:
1002:
scene: scene.scene3
constrain_input_select: input_select.scenes,scene3
There is definitely something wrong in how I configure apps.yaml. The switching of scenes does not work. It only switches the input_select but not scenes. Here is my apps.yaml:
example_app_off:
module: controllerx
class: LightController
controller: bedroom_hue_switch
integration: deconz
light: light.bedroom
mapping:
1002:
action: 'on'
# - scene: scene.scene1 # optional: set a fixed scene at 'on'
service: input_boolean.turn_on
data:
entity_id: input_boolean.bedroom
constrain_input_boolean: input_boolean.bedroom, off
# current light.bedroom.state == on
example_app_on:
module: controllerx
class: LightController
controller: bedroom_hue_switch
integration: deconz
light: light.bedroom
mapping:
1002:
service: input_select.select_next
data:
entity_id: input_select.bedroom_scenes
4002: # Hue Dimmer switch (Philips)
action: 'off'
service: input_boolean.turn_off
data:
entity_id: input_boolean.bedroom
1001: hold_brightness_toggle
1003: release
# depending on the controller add all states relevant for state context 'on' here
constrain_input_boolean: input_boolean.bedroom,on
# Config for scene1
app_bedroom_scene_max:
module: controllerx
class: Controller
controller: bedroom_hue_switch
integration: deconz
mapping:
1002$2:
scene: scene.bedroom_max
constrain_input_select: input_select.bedroom_scenes, bedroom_max
# Config for scene2
app_bedroom_scene_dimmed:
module: controllerx
class: Controller
controller: bedroom_hue_switch
integration: deconz
mapping:
1002$2:
scene: scene.bedroom_dimmed
constrain_input_select: input_select.bedroom_scenes, bedroom_dimmed
# Config for scene3
app_bedroom_scene_off:
module: controllerx
class: Controller
controller: bedroom_hue_switch
integration: deconz
mapping:
1002$2:
scene: scene.bedroom_off
constrain_input_select: input_select.bedroom_scenes, bedroom_off
I also noticed that I could only adjust the light brightness by a little if I press the button continuously.
If I am not mistaken the syntax for constrain_xxx does not allow any whitespace after the comma, i.e. remove the whitespace
i.e. correct syntax:
possibly not working because of the whitespace after comma
This could be the reason why the input_select is rolling but the scenes don’t
and this won’t work either
1002$2:
just plain “1002:”
basically if constrain_xxx matches, e.g. the current state of input_select.bedroom_scenes == 'bedroom_dimmed' the app code block ‘scene2’ will be executed
I am failing to achieve getting a scene called by double-clicking the on-button.
With the following mapping, the scene gets activated with a single click, so its not a general problem.
1000:
scene: scene.schlafzimmer_lesemodus
What you are saying is, that there is no “easy” way to get double-click to work on Hue DImmer Switch?
As it is with the Hue Smart Button (pls s post #9@silkoo) Hue dimmer switch RWL21 sends for ea click on Button <I> a sequence of two deconz events: <1000><1002>, i.e. not a single <1002> only, i.e. makes single indistinguishable from a double click.
For a work around my config uses single click only. After the first click on <I>, i.e. PowerOn, any subsequent single click on <\I> will activate the next scene in round robin.
Hi toixdm, Thanks for noticing the errors. Unfortunately the config still does not work:
When I switch on the light the boolean value does not change from on to off. So I could not switch the lights off (only if I change the boolean switch to ‘on’ manually it works fine)
The scene switching still does not work
Here is my config:
module: controllerx
class: LightController
controller: bedroom_hue_switch
integration: deconz
light: light.bedroom
mapping:
1002:
scene: scene.bedroom_max # optional: set a fixed scene at 'on'
service: input_boolean.turn_on
data:
entity_id: input_boolean.bedroom
constrain_input_boolean: input_boolean.bedroom,off
# current light.bedroom.state == on
example_app_on:
module: controllerx
class: LightController
controller: bedroom_hue_switch
integration: deconz
light: light.bedroom
mapping:
1002:
service: input_select.select_next
data:
entity_id: input_select.bedroom_scenes
1002$2: # Hue Dimmer switch (Philips)
action: 'off'
service: input_boolean.turn_off
data:
entity_id: input_boolean.bedroom
1001: hold_brightness_toggle
1003: release
# depending on the controller add all states relevant for state context 'on' here
constrain_input_boolean: input_boolean.bedroom,on
# Config for scene1
app_bedroom_scene_max:
module: controllerx
class: Controller
controller: bedroom_hue_switch
integration: deconz
mapping:
1002:
scene: scene.bedroom_max
constrain_input_select: input_select.bedroom_scenes,bedroom_max
# Config for scene2
app_bedroom_scene_dimmed:
module: controllerx
class: Controller
controller: bedroom_hue_switch
integration: deconz
mapping:
1002:
scene: scene.bedroom_dimmed
constrain_input_select: input_select.bedroom_scenes,bedroom_dimmed
# Config for scene3
app_bedroom_scene_off:
module: controllerx
class: Controller
controller: bedroom_hue_switch
integration: deconz
mapping:
1002:
scene: scene.bedroom_off
constrain_input_select: input_select.bedroom_scenes,bedroom_off
Don’t know what code your Hue device sends for action ‘off’ but doubt 1002$2 is the one. Something like 1004 perhaps? And a trailing “$2” won’t work anyway. My config example works for ‘single’ clicks only. $2 means count.
I see. According to the event sequences in your post#9 above and what the ControllerX Hue Smart Button shows my config example may not be feasible for this particular device since Hue Smart Button lacks a distinguishable “off” event code. Unless the “double click counter” recipe would work somehow, i.e. <1000$2>, right now I wouldn’t see how to adapt my config example to work for a Hue Smart Button (and similar). You are right, given the limited number of events for it after the initial ‘on’ any subsequent “single short press” <1002> can either be an ‘off’ (default with XController) or with the extra ‘input_boolean’ configured to trigger another action, e.g. ‘switch to next scene’ action. But not both.
You are not using a list to separate actions, so when you do:
mapping:
1002:
scene: scene.bedroom_max # optional: set a fixed scene at 'on'
service: input_boolean.turn_on
data:
entity_id: input_boolean.bedroom
You should be doing:
mapping:
1002:
- scene: scene.bedroom_max # optional: set a fixed scene at 'on'
- service: input_boolean.turn_on
data:
entity_id: input_boolean.bedroom
What this last config does is to activate the scene first and then call an HA service call to turn on an input_boolean.