Scene switching + tuning on/off + dimming with one button

Hi @xaviml,

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:

  • “Turn on” button pressed
  • “Turn on” button released
  • “Turn on” button continuously pressed
  • “Turn on” button released after long press

I have also found this discussion about the Hue Smart Button deCONZ integration (https://github.com/dresden-elektronik/deconz-rest-plugin/issues/2077). These events are outlined there:

"events": [
	{
		"buttonevent": 1000,
		"eventtype": "initial_press"
	},
	{
		"buttonevent": 1001,
		"eventtype": "repeat"
	},
	{
		"buttonevent": 1002,
		"eventtype": "short_release"
	},
	{
		"buttonevent": 1003,
		"eventtype": "long_release"
	}
]

Not sure if it will help. Please let me know if I could help you somehow with defining events.

Hi @silkoo,

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:

input_select:
  scenes:
    options:
      - scene1
      - scene2
      - scene3

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.

Regards,
Xavi M.

Hi Xavi,

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

Regards,
silkoo

Hi @silkoo,

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
2 Likes

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 not sure if i understand correctly what you found out with double-clicking the Philips Hue Dimmer Switch.
What I want to achieve:

  • Single click at on-button: Light turns on (this is working)
  • Double click at on-button: activates scene (this is not working)

I have following configuration in ControllerX:

bedroom_controllerx:
    module: controllerx
    class: HueDimmerController
    controller: hue_schlafzimmer_dimmschalter
    integration: deconz
    light: light.schlafzimmer
    multiple_click_delay: 500
    actions:
        - 1000
        - 1001
        - 4000
        - 4001
    mapping: 
        1000: "on"
        1001: hold_brightness_up
        4000: "off"
        4001: hold_brightness_down

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.

1 Like

Perfect, thanks! Working now with the input.boolean!

Hi toixdm, Thanks for noticing the errors. Unfortunately the config still does not work:

  1. 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)
  2. 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.

There is no off button on hue button switch. It is only a one button device

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.

Hi @silkoo,

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.

The same happens to the 1002$2 action.

Regards,
Xavi M.

Cool, now it works. Thank you. In order to make it work how I like I would need to use the timers. Does ControllerX allow starting timers and checking their statuses?

I finally constructed the solution with node-red. I find it very nice because it gives a lot of controls for a one button device: you could toggle the light, switch between scenes and dim the lights.
You will need to configure get_device_id node, event_type node and several helpers in home assistant:

  • timer (2s) for switching between light toggle and scene selection
  • dim switch boolean to switch dimming up/down
  • input select to select scenes

Here is the flow:

[
    {
        "id": "4cb2d8d4.f1ff18",
        "type": "tab",
        "label": "living_room",
        "disabled": false,
        "info": ""
    },
    {
        "id": "cfeb8db3.53c14",
        "type": "server-events",
        "z": "4cb2d8d4.f1ff18",
        "name": "event",
        "server": "10991ca8.1f1c03",
        "event_type": "deconz_event",
        "exposeToHomeAssistant": false,
        "haConfig": [
            {
                "property": "name",
                "value": ""
            },
            {
                "property": "icon",
                "value": ""
            }
        ],
        "waitForRunning": true,
        "x": 90,
        "y": 160,
        "wires": [
            [
                "425b6f10.008f3"
            ]
        ]
    },
    {
        "id": "425b6f10.008f3",
        "type": "switch",
        "z": "4cb2d8d4.f1ff18",
        "name": "get_device_id",
        "property": "payload.event.unique_id",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "00:17:88:01:06:05:c1:f2",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 260,
        "y": 160,
        "wires": [
            [
                "2b31e17a.901bfe"
            ]
        ]
    },
    {
        "id": "2b31e17a.901bfe",
        "type": "switch",
        "z": "4cb2d8d4.f1ff18",
        "name": "event_type",
        "property": "payload.event.event",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "1001",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "1002",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "1003",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "1004",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 4,
        "x": 450,
        "y": 160,
        "wires": [
            [
                "fd750856.f7f64"
            ],
            [
                "c9b4bd65.7776e8"
            ],
            [
                "5434c17c.c69228"
            ],
            []
        ]
    },
    {
        "id": "c9b4bd65.7776e8",
        "type": "api-current-state",
        "z": "4cb2d8d4.f1ff18",
        "name": "check_timer",
        "server": "10991ca8.1f1c03",
        "version": 1,
        "outputs": 2,
        "halt_if": "active",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "override_topic": false,
        "entity_id": "timer.living_room_switch_timer",
        "state_type": "str",
        "state_location": "payload",
        "override_payload": "msg",
        "entity_location": "data",
        "override_data": "msg",
        "blockInputOverrides": false,
        "x": 650,
        "y": 120,
        "wires": [
            [
                "4617b194.abe3a8",
                "7f57714e.ee038"
            ],
            [
                "e8b86bd4.b806a",
                "7f57714e.ee038"
            ]
        ]
    },
    {
        "id": "e8b86bd4.b806a",
        "type": "api-call-service",
        "z": "4cb2d8d4.f1ff18",
        "name": "toggle_lights",
        "server": "10991ca8.1f1c03",
        "version": 1,
        "debugenabled": true,
        "service_domain": "light",
        "service": "toggle",
        "entityId": "light.living_room",
        "data": "",
        "dataType": "json",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 930,
        "y": 180,
        "wires": [
            [
                "f43007b7.d74288"
            ]
        ]
    },
    {
        "id": "7f57714e.ee038",
        "type": "api-call-service",
        "z": "4cb2d8d4.f1ff18",
        "name": "restart_timer",
        "server": "10991ca8.1f1c03",
        "version": 1,
        "debugenabled": false,
        "service_domain": "timer",
        "service": "start",
        "entityId": "timer.living_room_switch_timer",
        "data": "",
        "dataType": "jsonata",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 930,
        "y": 120,
        "wires": [
            []
        ]
    },
    {
        "id": "51e9c79c.e1fb4",
        "type": "link in",
        "z": "4cb2d8d4.f1ff18",
        "name": "toggle_scenes",
        "links": [
            "4617b194.abe3a8"
        ],
        "x": 55,
        "y": 340,
        "wires": [
            [
                "f511d989.bb014"
            ]
        ]
    },
    {
        "id": "4617b194.abe3a8",
        "type": "link out",
        "z": "4cb2d8d4.f1ff18",
        "name": "toggle_scenes",
        "links": [
            "51e9c79c.e1fb4"
        ],
        "x": 875,
        "y": 80,
        "wires": []
    },
    {
        "id": "d494dea5.d271d8",
        "type": "api-call-service",
        "z": "4cb2d8d4.f1ff18",
        "name": "max",
        "server": "10991ca8.1f1c03",
        "version": 1,
        "debugenabled": false,
        "service_domain": "scene",
        "service": "turn_on",
        "entityId": "scene.living_room_all_max",
        "data": "",
        "dataType": "jsonata",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 550,
        "y": 280,
        "wires": [
            [
                "b15c5603.4c50a"
            ]
        ]
    },
    {
        "id": "98b4635f.5ecf7",
        "type": "api-call-service",
        "z": "4cb2d8d4.f1ff18",
        "name": "dimmed",
        "server": "10991ca8.1f1c03",
        "version": 1,
        "debugenabled": false,
        "service_domain": "scene",
        "service": "turn_on",
        "entityId": "scene.living_room_all_dimmed",
        "data": "",
        "dataType": "jsonata",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 560,
        "y": 340,
        "wires": [
            [
                "b15c5603.4c50a"
            ]
        ]
    },
    {
        "id": "f511d989.bb014",
        "type": "api-current-state",
        "z": "4cb2d8d4.f1ff18",
        "name": "scene_selected",
        "server": "10991ca8.1f1c03",
        "version": 1,
        "outputs": 1,
        "halt_if": "",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "override_topic": false,
        "entity_id": "input_select.living_room_scenes",
        "state_type": "str",
        "state_location": "payload",
        "override_payload": "msg",
        "entity_location": "data",
        "override_data": "msg",
        "blockInputOverrides": false,
        "x": 180,
        "y": 340,
        "wires": [
            [
                "887e2a2a.721e88"
            ]
        ]
    },
    {
        "id": "887e2a2a.721e88",
        "type": "switch",
        "z": "4cb2d8d4.f1ff18",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "max",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "dimmed",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "stand_lamp_only",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 3,
        "x": 350,
        "y": 340,
        "wires": [
            [
                "d494dea5.d271d8"
            ],
            [
                "98b4635f.5ecf7"
            ],
            [
                "27063e72.6abbfa"
            ]
        ]
    },
    {
        "id": "27063e72.6abbfa",
        "type": "api-call-service",
        "z": "4cb2d8d4.f1ff18",
        "name": "table_lamp_only",
        "server": "10991ca8.1f1c03",
        "version": 1,
        "debugenabled": false,
        "service_domain": "scene",
        "service": "turn_on",
        "entityId": "scene.living_room_table_lamp_only",
        "data": "",
        "dataType": "jsonata",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 580,
        "y": 400,
        "wires": [
            [
                "b15c5603.4c50a"
            ]
        ]
    },
    {
        "id": "b15c5603.4c50a",
        "type": "api-call-service",
        "z": "4cb2d8d4.f1ff18",
        "name": "input_select_next",
        "server": "10991ca8.1f1c03",
        "version": 1,
        "debugenabled": false,
        "service_domain": "input_select",
        "service": "select_next",
        "entityId": "input_select.living_room_scenes",
        "data": "",
        "dataType": "jsonata",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 830,
        "y": 340,
        "wires": [
            []
        ]
    },
    {
        "id": "56232653.5918d",
        "type": "function",
        "z": "4cb2d8d4.f1ff18",
        "name": "brightness_up",
        "func": "'var bright_pct = flow.get(\"bright_pct\");'\nvar new_msg = {};\nvar bright_pct = msg.data.attributes.brightness;\n\nif(bright_pct > 254){\n    bright_pct = 255\n}\nelse{\n    bright_pct =  bright_pct + 30;\n}\n\n\n\n\nflow.set('bright_pct', bright_pct);\nnew_msg = {\"payload\": {\"data\" : {\"brightness\" : Number(bright_pct)}}};\nreturn new_msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 760,
        "y": 520,
        "wires": [
            [
                "ec1b742e.48b47"
            ]
        ]
    },
    {
        "id": "3a35850e.2009b2",
        "type": "link in",
        "z": "4cb2d8d4.f1ff18",
        "name": "dim",
        "links": [
            "fd750856.f7f64"
        ],
        "x": 55,
        "y": 560,
        "wires": [
            [
                "b04e95a8.04cd78"
            ]
        ]
    },
    {
        "id": "fd750856.f7f64",
        "type": "link out",
        "z": "4cb2d8d4.f1ff18",
        "name": "dim",
        "links": [
            "3a35850e.2009b2"
        ],
        "x": 595,
        "y": 80,
        "wires": []
    },
    {
        "id": "ec1b742e.48b47",
        "type": "api-call-service",
        "z": "4cb2d8d4.f1ff18",
        "name": "",
        "server": "10991ca8.1f1c03",
        "version": 1,
        "debugenabled": false,
        "service_domain": "light",
        "service": "turn_on",
        "entityId": "light.living_room",
        "data": "",
        "dataType": "json",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 990,
        "y": 560,
        "wires": [
            []
        ]
    },
    {
        "id": "763f78ed.ace38",
        "type": "function",
        "z": "4cb2d8d4.f1ff18",
        "name": "brightness_down",
        "func": "'var bright_pct = flow.get(\"bright_pct\");'\nvar new_msg = {};\nvar bright_pct = msg.data.attributes.brightness;\n\nif (bright_pct > 0){\n    bright_pct =  bright_pct - 30;\n}\nelse {\n    bright_pct = 0\n}\n\n\nflow.set('bright_pct', bright_pct);\nnew_msg = {\"payload\": {\"data\" : {\"brightness\" : Number(bright_pct)}}};\nreturn new_msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 770,
        "y": 600,
        "wires": [
            [
                "ec1b742e.48b47"
            ]
        ]
    },
    {
        "id": "b04e95a8.04cd78",
        "type": "api-current-state",
        "z": "4cb2d8d4.f1ff18",
        "name": "check_dim_switch",
        "server": "10991ca8.1f1c03",
        "version": 1,
        "outputs": 1,
        "halt_if": "",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "override_topic": false,
        "entity_id": "input_boolean.living_room_dimming_up",
        "state_type": "habool",
        "state_location": "payload",
        "override_payload": "msg",
        "entity_location": "data",
        "override_data": "msg",
        "blockInputOverrides": false,
        "x": 190,
        "y": 560,
        "wires": [
            [
                "e885e47b.c75148"
            ]
        ]
    },
    {
        "id": "5434c17c.c69228",
        "type": "api-call-service",
        "z": "4cb2d8d4.f1ff18",
        "name": "toggle_dimming",
        "server": "10991ca8.1f1c03",
        "version": 1,
        "debugenabled": false,
        "service_domain": "input_boolean",
        "service": "toggle",
        "entityId": "input_boolean.living_room_dimming_up",
        "data": "",
        "dataType": "jsonata",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 660,
        "y": 200,
        "wires": [
            []
        ]
    },
    {
        "id": "f43007b7.d74288",
        "type": "api-call-service",
        "z": "4cb2d8d4.f1ff18",
        "name": "input_select_reset",
        "server": "10991ca8.1f1c03",
        "version": 1,
        "debugenabled": true,
        "service_domain": "input_select",
        "service": "select_first",
        "entityId": "input_select.living_room_scenes",
        "data": "",
        "dataType": "json",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 1150,
        "y": 180,
        "wires": [
            []
        ]
    },
    {
        "id": "e885e47b.c75148",
        "type": "switch",
        "z": "4cb2d8d4.f1ff18",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "true"
            },
            {
                "t": "false"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 370,
        "y": 560,
        "wires": [
            [
                "d6551564.9d24"
            ],
            [
                "b05509cc.bd6b08"
            ]
        ]
    },
    {
        "id": "d6551564.9d24",
        "type": "api-current-state",
        "z": "4cb2d8d4.f1ff18",
        "name": "living_room",
        "server": "10991ca8.1f1c03",
        "version": 1,
        "outputs": 1,
        "halt_if": "",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "override_topic": false,
        "entity_id": "light.living_room",
        "state_type": "str",
        "state_location": "payload",
        "override_payload": "msg",
        "entity_location": "data",
        "override_data": "msg",
        "blockInputOverrides": false,
        "x": 570,
        "y": 520,
        "wires": [
            [
                "56232653.5918d"
            ]
        ]
    },
    {
        "id": "b05509cc.bd6b08",
        "type": "api-current-state",
        "z": "4cb2d8d4.f1ff18",
        "name": "living_room",
        "server": "10991ca8.1f1c03",
        "version": 1,
        "outputs": 1,
        "halt_if": "",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "override_topic": false,
        "entity_id": "light.living_room",
        "state_type": "str",
        "state_location": "payload",
        "override_payload": "msg",
        "entity_location": "data",
        "override_data": "msg",
        "blockInputOverrides": false,
        "x": 570,
        "y": 600,
        "wires": [
            [
                "763f78ed.ace38"
            ]
        ]
    },
    {
        "id": "dc875720.1f3b08",
        "type": "comment",
        "z": "4cb2d8d4.f1ff18",
        "name": "Set timer",
        "info": "Use ",
        "x": 680,
        "y": 80,
        "wires": []
    },
    {
        "id": "8dfc18f5.b50c4",
        "type": "comment",
        "z": "4cb2d8d4.f1ff18",
        "name": "Set scene input select",
        "info": "Use ",
        "x": 180,
        "y": 300,
        "wires": []
    },
    {
        "id": "b3182803.8135f8",
        "type": "comment",
        "z": "4cb2d8d4.f1ff18",
        "name": "Set dim boolean switch",
        "info": "Use ",
        "x": 180,
        "y": 520,
        "wires": []
    },
    {
        "id": "1186c478.5e5914",
        "type": "comment",
        "z": "4cb2d8d4.f1ff18",
        "name": "Edit scenes here",
        "info": "Use ",
        "x": 420,
        "y": 260,
        "wires": []
    },
    {
        "id": "10991ca8.1f1c03",
        "type": "server",
        "name": "Home Assistant",
        "addon": true
    }
]
2 Likes

Hi, thanks for this flow
Got me looking into helper which is really useful
May I ask how exactly does the timer work when you’re pressing the button?

The timer works this way: you could activate it and then check its status. It will give you different output depending on its status. When you reset it timer starts again.

The way I use it in the flow is I activate the timer helper every time I press the button, if the timer is active (timer is still counting down) the flow will perform the scene switching. If the timer is inactive it will turn the light on/off.

1 Like
* one press: 1000 and 1002 event - for toggling lights
* 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 dimming up and down

The way i understand is that you’re using timer because your hue button doesn’t have specific payload for 2x, 3x, 4x presses yes? So you’d need to add this timer with 2 second duration for example

# Example configuration.yaml entry
timer:
  light_livingroom:
    duration: "00:00:02"

Also, as for dimming with long press, when exactly does dim up or down occur? Is it based on the current light brightness?

yes, right. My button does not have a specific payload for multiple presses.

Dim/up or down occurs as soon as you press, there 1001 events firing up at that moment. The change in light brightness does not depend on current light. This is actually something I want to change as it also affects the lights which are powered off. You could change this behavior in brightness_up/brightness_down functions.