Dim lights when button is pressed

I got a zdB5100 Matrix Switch. When a button is pushed and held I can catch the following in debug. When released the scene data value changes to 7740.

object
  event_type: "zwave.scene_activated"
  entity_id: "zwave.logic_soft_unknown_type_0003_id_0121"
event: object
  entity_id: "zwave.logic_soft_unknown_type_0003_id_0121"
  node_id: 7
  scene_id: 2
  scene_data: 7800

I want to build a dimmer that takes the current brightness value of a light in HA and increases the brigtness value untill the button is released. Likewise I want the opposite to decrease brightness when another scene_id (button) is pressed.

I’d probably give the traffic node a try. Simply listen for the scene data and if it changes to 7800 turn the traffic node to “allow” and then make a loop increasing the brightness. When you release the switch, the scene_data changes to 7740 and that in turn needs to turn the traffice node to “disallow” or “stop”.

Im using something similar with the Ikea Tradfri remote:

[
    {
        "id": "2db5a6a5.ddffda",
        "type": "switch",
        "z": "d4113bbe.91f4a8",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "brightness_up_hold",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "brightness_up_release",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 330,
        "y": 1000,
        "wires": [
            [
                "235ac263.baf1de",
                "79a7a052.73"
            ],
            [
                "79a7a052.73"
            ]
        ]
    },
    {
        "id": "235ac263.baf1de",
        "type": "api-current-state",
        "z": "d4113bbe.91f4a8",
        "name": "",
        "server": "2fba4297.e4145e",
        "version": 1,
        "outputs": 2,
        "halt_if": "off",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "override_topic": false,
        "entity_id": "light.wohnzimmer",
        "state_type": "str",
        "state_location": "payload",
        "override_payload": "msg",
        "entity_location": "data",
        "override_data": "msg",
        "blockInputOverrides": false,
        "x": 870,
        "y": 1000,
        "wires": [
            [],
            [
                "3d5903d0.c8a5cc"
            ]
        ]
    },
    {
        "id": "3d5903d0.c8a5cc",
        "type": "function",
        "z": "d4113bbe.91f4a8",
        "name": "Lower or Higher",
        "func": "newmsg = {}\n\nvar currentbrightness = msg.data.attributes.brightness\nvar up = currentbrightness + 45\n\nnewmsg.payload = { data: { \"brightness\":(up)},\"transition\":\"1\" };\n\n\n\nreturn newmsg;",
        "outputs": 1,
        "noerr": 0,
        "x": 1100,
        "y": 1000,
        "wires": [
            [
                "6c08d8e4.aa23d8"
            ]
        ]
    },
    {
        "id": "6c08d8e4.aa23d8",
        "type": "api-call-service",
        "z": "d4113bbe.91f4a8",
        "name": "Wohnzimmer 100%",
        "server": "2fba4297.e4145e",
        "version": "1",
        "service_domain": "light",
        "service": "turn_on",
        "entityId": "light.wohnzimmer",
        "data": "",
        "dataType": "json",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 1290,
        "y": 1000,
        "wires": [
            [
                "6cd31cf3.8c09f4"
            ]
        ]
    },
    {
        "id": "79a7a052.73",
        "type": "traffic",
        "z": "d4113bbe.91f4a8",
        "name": "",
        "property_allow": "payload",
        "filter_allow": "brightness_up_hold",
        "ignore_case_allow": false,
        "negate_allow": false,
        "send_allow": false,
        "property_stop": "payload",
        "filter_stop": "brightness_up_release",
        "ignore_case_stop": false,
        "negate_stop": false,
        "send_stop": false,
        "default_start": false,
        "differ": false,
        "x": 650,
        "y": 1000,
        "wires": [
            [
                "235ac263.baf1de"
            ]
        ]
    },
    {
        "id": "6cd31cf3.8c09f4",
        "type": "delay",
        "z": "d4113bbe.91f4a8",
        "name": "",
        "pauseType": "delay",
        "timeout": "1",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "x": 480,
        "y": 1000,
        "wires": [
            [
                "79a7a052.73"
            ]
        ]
    },
    {
        "id": "89e8dfba.f919b",
        "type": "server-state-changed",
        "z": "d4113bbe.91f4a8",
        "name": "Button?",
        "server": "2fba4297.e4145e",
        "version": 1,
        "entityidfilter": "sensor.ikea_remote_action",
        "entityidfiltertype": "exact",
        "outputinitially": false,
        "state_type": "str",
        "haltifstate": "",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "outputs": 1,
        "output_only_on_state_change": true,
        "x": 70,
        "y": 1000,
        "wires": [
            [
                "513118c2.ffcf08",
                "387a685a.e54248",
                "2db5a6a5.ddffda",
                "9001417d.475cf",
                "f79774f7.10fe88"
            ]
        ]
    },
    {
        "id": "9bd2c2f0.f1535",
        "type": "comment",
        "z": "d4113bbe.91f4a8",
        "name": "Up",
        "info": "",
        "x": 330,
        "y": 960,
        "wires": []
    },
    {
        "id": "2fba4297.e4145e",
        "type": "server",
        "z": "",
        "name": "Home Assistant",
        "legacy": false,
        "hassio": true,
        "rejectUnauthorizedCerts": true,
        "ha_boolean": "y|yes|true|on|home|open",
        "connectionDelay": true
    }
]

1 Like

This might help with making a loop to increase or decrease the lights

https://notenoughtech.com/home-automation/nodered-home-automation/xiaomi-aqara-switch-in-nodered/

Thank you very much for the input. I got the traffic light working by using your flow and altering. However, I get a brightness NaN in the debug node at the last step. Not sure why the variable is not working.
50

Is the light on when you get the NaN? What kind of light is it?
What does it normally report?

Yes it is on. It’s two hue lights in a group, which comes up as one entity from HA. If I place an inject node before the current state then the debug after the function outputs a value for brightness as expected.

Here is the traffic node, which appears to work as intended.

You could try to set the override topic setting in the current_state: light.dinning_table node.

Thanks. The “block input overrides” did the trick. Now I just need to figure out how to make it smooth dimming instead of jumpy increments.

Don’t forget to pasta a nice finished copy of the code !
:grinning:

Woud you post the code of what you have so far?