Increase or decrease the value of a device

Hello!

I recently wondered while installing a button (Zigbee2MQTT),
How it was possible to increment a value such as brightness in my case.

Indeed, my button allows me to perform several actions, 4 of which interest me:

  • arrow_left_hold,
  • arrow_right_hold,
  • arrow_left_release,
  • arrow_right_release

But on the gladys side, I cannot do a « while »

So I would like to be able to increment or decrement the brightness while I press a button and when I release it, the action stops.

Perhaps you can do this from a scene using pauses.

The trigger will be your click.
You pause for 1 second.
You retrieve the button state
Continue only if the button is still on hold
Increase brightness
Pause for 1 second again
Etc…

Indeed, it’s a solution but cumbersome :smiley:
The value of the brightness on some lamps is 255, I can’t see myself creating 255 blocks to say brightness++ :grinning_face:

After that, we can maybe have a block that repeats actions x and y times until the sensor is not in a certain state :slight_smile:

Hello @spenceur!
Isn’t it possible to configure your device so that it sends 1 every 500ms (or even every 50ms)? In this case, you only need to configure the scene once without checking the box « Run only […] ». It will repeat the « +1 » scene as long as you hold down the button. If it’s 500ms, you will need to hold down for 127 seconds to cover the entire range.
Ambient devices are usually configured with a step or frequency every x seconds to avoid having to hold down for so long. With a virtual device, you could even do it yourself.

Oh but indeed I didn’t think of that but it should work normally :thinking:
I’ll test it as soon as possible!

@Terdious @pierre-gilles, any idea how to retrieve the last value and add +1 to it?

This is not possible as is, we don’t have math functions in the scenes :slight_smile:

It is possible by going through Node-RED, however

Yeah, that’s what I’m currently using. I wonder if it shouldn’t be part of the core.

Clearly :slight_smile: There is a feature request that is close to this: Somme, moyenne, calculs dans les scènes

After this request goes off in all directions, it’s not very concrete, so I would create concrete feature requests.

Concretely for your request, two things are missing:

  • Being able to perform a mathematical operation on a « scene variable »: addition, subtraction, multiplication, division
  • Being able to inject a variable into an action « control a device ».

I’ll try that on my side to see what I can (or can’t) do!

Sorry, I may not have been clear, but I wouldn’t create the feature requests myself. It’s up to you to create them if you ever want to see them in Gladys :slight_smile:

Personally, I was going through Node-RED, but the button doesn’t go through Gladys (I would pass my flow).

@pierre-gilles Yes, I understood, but I’m at work, so I haven’t had time to do it yet.

Here’s what I did in the meantime:

In short, via a Z2M node, I retrieve the click action, then via a big switch, I send the info to the desired lamp, still via other Z2M nodes

[
    {
        "id": "04fe395c3e704b2a",
        "type": "switch",
        "z": "7ae9230582bf5831",
        "name": "",
        "property": "payload.action",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "on",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "off",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "brightness_move_up",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "brightness_move_down",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "brightness_stop",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "arrow_left_click",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "arrow_right_click",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "arrow_left_hold",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "arrow_right_hold",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "arrow_left_release",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "arrow_right_release",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 11,
        "x": 330,
        "y": 220,
        "wires": [
            [
                "2df8d7b2f5291fb7"
            ],
            [
                "1c3acbbddd183827"
            ],
            [],
            [],
            [],
            [
                "93fd7fdfe19f9209"
            ],
            [
                "a5f5aad809a82a17"
            ],
            [
                "e666d44b7b131d3e"
            ],
            [
                "43d6067a8e026fec"
            ],
            [
                "69f3c1ddc48ca93c"
            ],
            [
                "69f3c1ddc48ca93c"
            ]
        ]
    },
    {
        "id": "072c37a2c2c16bd9",
        "type": "debug",
        "z": "7ae9230582bf5831",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 340,
        "y": 80,
        "wires": []
    },
    {
        "id": "b2b7835c2619dfff",
        "type": "zigbee2mqtt-in",
        "z": "7ae9230582bf5831",
        "name": "Styrbar",
        "server": "d51526c1d3f21365",
        "friendly_name": "0x842e14fffe462c2a",
        "device_id": "0x842e14fffe462c2a",
        "state": "0",
        "outputAtStartup": true,
        "x": 50,
        "y": 120,
        "wires": [
            [
                "072c37a2c2c16bd9",
                "04fe395c3e704b2a"
            ]
        ]
    },
    {
        "id": "28ff1c7daf962686",
        "type": "zigbee2mqtt-out",
        "z": "7ae9230582bf5831",
        "name": "",
        "server": "d51526c1d3f21365",
        "friendly_name": "0x000b57fffe4960e8",
        "device_id": "0x000b57fffe4960e8",
        "command": "state",
        "commandType": "z2m_cmd",
        "payload": "payload",
        "payloadType": "msg",
        "transition": 0,
        "x": 700,
        "y": 120,
        "wires": []
    },
    {
        "id": "2df8d7b2f5291fb7",
        "type": "function",
        "z": "7ae9230582bf5831",
        "name": "",
        "func": "msg.payload = \"on\";\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 520,
        "y": 100,
        "wires": [
            [
                "28ff1c7daf962686"
            ]
        ]
    },
    {
        "id": "1c3acbbddd183827",
        "type": "function",
        "z": "7ae9230582bf5831",
        "name": "",
        "func": "msg.payload = \"off\";\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 520,
        "y": 140,
        "wires": [
            [
                "28ff1c7daf962686"
            ]
        ]
    },
    {
        "id": "7f4dd9cc9aed52fb",
        "type": "zigbee2mqtt-out",
        "z": "7ae9230582bf5831",
        "name": "",
        "server": "d51526c1d3f21365",
        "friendly_name": "0x000b57fffe4960e8",
        "device_id": "0x000b57fffe4960e8",
        "command": "brightness",
        "commandType": "z2m_cmd",
        "payload": "payload",
        "payloadType": "msg",
        "transition": 0,
        "x": 920,
        "y": 240,
        "wires": []
    },
    {
        "id": "a5f5aad809a82a17",
        "type": "zigbee2mqtt-get",
        "z": "7ae9230582bf5831",
        "name": "",
        "server": "d51526c1d3f21365",
        "friendly_name": "0x000b57fffe4960e8",
        "device_id": "0x000b57fffe4960e8",
        "state": "0",
        "x": 560,
        "y": 240,
        "wires": [
            [
                "bc87b3c6c082b665"
            ]
        ]
    },
    {
        "id": "bc87b3c6c082b665",
        "type": "function",
        "z": "7ae9230582bf5831",
        "name": "",
        "func": "msg.payload = msg.payload.brightness+50;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 740,
        "y": 240,
        "wires": [
            [
                "7f4dd9cc9aed52fb"
            ]
        ]
    },
    {
        "id": "dfc4380a19b4d4cc",
        "type": "zigbee2mqtt-out",
        "z": "7ae9230582bf5831",
        "name": "",
        "server": "d51526c1d3f21365",
        "friendly_name": "0x000b57fffe4960e8",
        "device_id": "0x000b57fffe4960e8",
        "command": "brightness",
        "commandType": "z2m_cmd",
        "payload": "payload",
        "payloadType": "msg",
        "transition": 0,
        "x": 920,
        "y": 200,
        "wires": []
    },
    {
        "id": "93fd7fdfe19f9209",
        "type": "zigbee2mqtt-get",
        "z": "7ae9230582bf5831",
        "name": "",
        "server": "d51526c1d3f21365",
        "friendly_name": "0x000b57fffe4960e8",
        "device_id": "0x000b57fffe4960e8",
        "state": "0",
        "x": 560,
        "y": 200,
        "wires": [
            [
                "077a9abae383f024"
            ]
        ]
    },
    {
        "id": "077a9abae383f024",
        "type": "function",
        "z": "7ae9230582bf5831",
        "name": "",
        "func": "msg.payload = msg.payload.brightness-50;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 740,
        "y": 200,
        "wires": [
            [
                "dfc4380a19b4d4cc"
            ]
        ]
    },
    {
        "id": "43d6067a8e026fec",
        "type": "function",
        "z": "7ae9230582bf5831",
        "name": "",
        "func": "msg.payload = \"+50\";\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 560,
        "y": 320,
        "wires": [
            [
                "fba10e4b7c87bb54"
            ]
        ]
    },
    {
        "id": "e666d44b7b131d3e",
        "type": "function",
        "z": "7ae9230582bf5831",
        "name": "",
        "func": "msg.payload = \"-50\";\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 560,
        "y": 280,
        "wires": [
            [
                "fba10e4b7c87bb54"
            ]
        ]
    },
    {
        "id": "fba10e4b7c87bb54"```json
        "type": "zigbee2mqtt-out",
        "z": "7ae9230582bf5831",
        "name": "",
        "server": "d51526c1d3f21365",
        "friendly_name": "0x000b57fffe4960e8",
        "device_id": "0x000b57fffe4960e8",
        "command": "brightness_move",
        "commandType": "z2m_cmd",
        "payload": "payload",
        "payloadType": "msg",
        "transition": 0,
        "x": 820,
        "y": 340,
        "wires": []
    },
    {
        "id": "69f3c1ddc48ca93c",
        "type": "function",
        "z": "7ae9230582bf5831",
        "name": "",
        "func": "msg.payload = \"stop\";\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 560,
        "y": 360,
        "wires": [
            [
                "fba10e4b7c87bb54"
            ]
        ]
    },
    {
        "id": "d51526c1d3f21365",
        "type": "zigbee2mqtt-server",
        "name": "",
        "host": "192.168.1.59",
        "mqtt_port": "1884",
        "mqtt_username": "z2m",
        "mqtt_password": "BdoseXmoNi5OpOJsYEdY",
        "tls": "",
        "usetls": false,
        "base_topic": "zigbee2mqtt"
    }
]

done

I didn’t overthink it, I admit :slight_smile:

Thanks @spenceur! Let the vote happen now :slight_smile: