Ikea TRÅDFRI shortcut button: counting clicks and presses!

This is a example flow with a subflow - it collect's the clicks (short holding the button) or the presses (longer holding the button).

The input comes from a Zigbee-device - mine is the Sonoff-gateway flashed with Tasmota.

When click, then the variable: msg.payload.ZbReceived.Ikea_Event_Button_1.Power contains 1. When you press it (click an hold the button for about 1sec) the variable: msg.payload.ZbReceived.DimmerStop.Power contains TRUE.

Ikea_Event_Button_1 is a friendly name by myself for the Zigbee-button, so it may vary in your own setting.

For clicks a delay time of 800 (msec) is good, for presses try 1600 as shown in the flow.

What does the subflow do? It's counting the clicks! And how it is doing that?

The click is starting a timer - if you press the button again before the 800 msec are over, it's resetting the timer and count the clicks - and so on!

The result is the count of the clicks in the end is in msg.payload.

Because the time between click - hold - and release of the "presses" need a longer time, the subflow with its timer has to "watch" the input for the next press for a longer time - so the time of 1600 msec is a good value.

The programming of the subflow seems to be a little "quick and dirty" but it has a reason: I didn't want to use other nodes (besides Zigbee-handling) than the the basic nodes - so I had to program the timing loop with the possibility to reset it by myself.

Used hardware: Sonoff Zigbee gateway flashed with Tasmota, Raspberry 3 with mosquitto and Nodered.

[{"id":"37ff5f86.e3fd8","type":"subflow","name":"ClickCounter","info":"","category":"","in":[{"x":40,"y":160,"wires":[{"id":"cd57b76.f03b448"}]}],"out":[{"x":1220,"y":740,"wires":[{"id":"99b7358e.7b4908","port":0}]}],"env":[{"name":"ClickName","type":"str","value":"Click","ui":{"icon":"font-awesome/fa-circle"}},{"name":"DelayTimer","type":"num","value":"1000","ui":{"icon":"font-awesome/fa-clock-o","label":{"en-US":"DelayTimer"},"type":"input","opts":{"types":["num"]}}}],"color":"#DDAA99"},{"id":"cd57b76.f03b448","type":"switch","z":"37ff5f86.e3fd8","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"ClickName","vt":"env"}],"checkall":"true","repair":false,"outputs":1,"x":130,"y":160,"wires":[["e51b52f1.cac86"]]},{"id":"e51b52f1.cac86","type":"change","z":"37ff5f86.e3fd8","name":"set flow.click true","rules":[{"t":"set","p":"click","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":310,"y":160,"wires":[["fd81b0c.edfa55"]]},{"id":"fd81b0c.edfa55","type":"change","z":"37ff5f86.e3fd8","name":"set flow.counter","rules":[{"t":"set","p":"counter","pt":"msg","to":"counter","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":160,"wires":[["cb2ec38e.c7af"]]},{"id":"1939d949.13464f","type":"change","z":"37ff5f86.e3fd8","name":"set flow.click false when click has been counted","rules":[{"t":"set","p":"click","pt":"flow","to":"false","tot":"bool"},{"t":"set","p":"counter","pt":"flow","to":"counter","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":280,"wires":[["417cf67d.3d2068"]]},{"id":"7558801f.6482e","type":"switch","z":"37ff5f86.e3fd8","name":"if new click: new loop","property":"click","propertyType":"flow","rules":[{"t":"true"},{"t":"false"}],"checkall":"false","repair":false,"outputs":2,"x":580,"y":560,"wires":[["fd81b0c.edfa55"],["2940fbdd.220f3c"]]},{"id":"2940fbdd.220f3c","type":"change","z":"37ff5f86.e3fd8","name":"set counter into payload","rules":[{"t":"set","p":"payload","pt":"msg","to":"counter","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":270,"y":740,"wires":[["a0e4d6c3.f90728"]]},{"id":"a0e4d6c3.f90728","type":"change","z":"37ff5f86.e3fd8","name":"reset click & counter, delete not needed msgs","rules":[{"t":"set","p":"click","pt":"flow","to":"false","tot":"bool"},{"t":"set","p":"counter","pt":"flow","to":"0","tot":"num"},{"t":"delete","p":"counter","pt":"msg"},{"t":"delete","p":"timercounter","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":660,"y":740,"wires":[["99b7358e.7b4908"]]},{"id":"cb2ec38e.c7af","type":"function","z":"37ff5f86.e3fd8","name":"+ 1 to msg.counter","func":"var counter = parseInt(msg.counter,10) + 1;\nmsg.counter = counter;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":610,"y":220,"wires":[["1939d949.13464f"]]},{"id":"b0f90759.141fb","type":"switch","z":"37ff5f86.e3fd8","name":"Timer looping!","property":"timercounter","propertyType":"msg","rules":[{"t":"lt","v":"DelayTimer","vt":"env"},{"t":"gte","v":"DelayTimer","vt":"env"}],"checkall":"true","repair":false,"outputs":2,"x":980,"y":460,"wires":[["75f260a5.e8fd5"],["7558801f.6482e"]]},{"id":"75f260a5.e8fd5","type":"function","z":"37ff5f86.e3fd8","name":"msg.timercounter + 1","func":"var timercounter = parseInt(msg.timercounter,10) + 1;\nmsg.timercounter = timercounter;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":960,"y":340,"wires":[["dc78ed82.c47008"]]},{"id":"dc78ed82.c47008","type":"delay","z":"37ff5f86.e3fd8","name":"delay 1msec","pauseType":"delay","timeout":"1","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":970,"y":400,"wires":[["b0f90759.141fb"]]},{"id":"417cf67d.3d2068","type":"change","z":"37ff5f86.e3fd8","name":"msg.timercounter=0 when nem Click arrives","rules":[{"t":"set","p":"timercounter","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1010,"y":280,"wires":[["75f260a5.e8fd5"]]},{"id":"99b7358e.7b4908","type":"switch","z":"37ff5f86.e3fd8","name":"only counted cklicks","property":"payload","propertyType":"msg","rules":[{"t":"gt","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":1000,"y":740,"wires":[[]]},{"id":"f0ba9a73.429ac","type":"comment","z":"37ff5f86.e3fd8","name":"Delay Loop","info":"","x":910,"y":40,"wires":[]},{"id":"e6675dd7.fd28e","type":"comment","z":"37ff5f86.e3fd8","name":"Click counter","info":"","x":550,"y":40,"wires":[]},{"id":"96b43e2c.688838","type":"tab","label":"Ikea TRÅDFRI Shortcut Butto","disabled":false,"info":""},{"id":"51ad3fd6.86cde8","type":"debug","z":"96b43e2c.688838","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":650,"y":180,"wires":[]},{"id":"7e9c144d.b87f14","type":"subflow:37ff5f86.e3fd8","z":"96b43e2c.688838","name":"","env":[{"name":"ClickName","value":"1","type":"str"},{"name":"DelayTimer","value":"800","type":"num"}],"x":430,"y":160,"wires":[["51ad3fd6.86cde8"]]},{"id":"f79a6141.24d98","type":"inject","z":"96b43e2c.688838","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"str","x":170,"y":120,"wires":[["7e9c144d.b87f14"]]},{"id":"98e4e99a.68d7e","type":"link in","z":"96b43e2c.688838","name":"ZigbeeIn","links":["3151325c.ba2b76"],"x":75,"y":200,"wires":[["93082e45.0b3178","befdefac.3325c8"]]},{"id":"93082e45.0b3178","type":"change","z":"96b43e2c.688838","name":"Short Click","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.Power","tot":"msg"},{"t":"set","p":"clicklenght","pt":"msg","to":"short","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":190,"y":180,"wires":[["7e9c144d.b87f14"]]},{"id":"befdefac.3325c8","type":"change","z":"96b43e2c.688838","name":"Long Click","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.DimmerStop","tot":"msg"},{"t":"set","p":"clicklength","pt":"msg","to":"long","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":190,"y":220,"wires":[["65924a0.a51c238"]]},{"id":"65924a0.a51c238","type":"subflow:37ff5f86.e3fd8","z":"96b43e2c.688838","name":"","env":[{"name":"ClickName","value":"true","type":"bool"},{"name":"DelayTimer","value":"1600","type":"num"}],"x":430,"y":240,"wires":[["51ad3fd6.86cde8"]]}]

Flow Info

Created 3 years, 11 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • change (x8)
  • comment (x2)
  • debug (x1)
  • delay (x1)
  • function (x2)
  • inject (x1)
  • link in (x1)
  • switch (x4)
Other
  • subflow (x1)
  • subflow:37ff5f86.e3fd8 (x2)
  • tab (x1)

Tags

  • Ikea
  • TRÅDFRI
  • shortcut
  • button
  • clicks
  • press
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option