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

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.