Single/long press

This subflow handles single and long press for simpler switches/inputs that only send a pressed and released event.

The single press is handled instantly after releasing the switch/input. The long press is handled after 0.75s, but you can edit the subflow and change this value by editing the trigger.

[{"id":"0cade48b6615ae2c","type":"subflow","name":"Single/long press","info":"","category":"","in":[{"x":40,"y":120,"wires":[{"id":"d9648d6265316da7"}]}],"out":[{"x":940,"y":140,"wires":[{"id":"ba0dc4d0a3e1e436","port":0}]},{"x":940,"y":180,"wires":[{"id":"f3d857b4b7366fd1","port":0}]}],"env":[{"name":"ButtonPressed","type":"str","value":"press"},{"name":"ButtonReleased","type":"str","value":"release"},{"name":"OutputSingle","type":"str","value":"single"},{"name":"OutputLong","type":"str","value":"long"}],"meta":{},"color":"#DDAA99"},{"id":"94715ffd7ebcbe6e","type":"trigger","z":"0cade48b6615ae2c","name":"send long press after 0.75s","op1":"","op2":"long","op1type":"nul","op2type":"str","duration":"0.75","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":460,"y":120,"wires":[["b4e451b4d33a14ff","ba9d2f5d092958d9"]]},{"id":"d9648d6265316da7","type":"switch","z":"0cade48b6615ae2c","name":"press/release?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"ButtonPressed","vt":"env"},{"t":"eq","v":"ButtonReleased","vt":"env"}],"checkall":"true","repair":false,"outputs":2,"x":180,"y":120,"wires":[["94715ffd7ebcbe6e","8749fa54c44ca0fd"],["738fb6b865c6a754","6a19e221af4c5a8a"]]},{"id":"b4e451b4d33a14ff","type":"switch","z":"0cade48b6615ae2c","name":"single/long?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"single","vt":"str"},{"t":"eq","v":"long","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":670,"y":160,"wires":[["ba0dc4d0a3e1e436"],["f3d857b4b7366fd1"]]},{"id":"738fb6b865c6a754","type":"change","z":"0cade48b6615ae2c","name":"Reset trigger","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":160,"wires":[["94715ffd7ebcbe6e"]]},{"id":"6a19e221af4c5a8a","type":"change","z":"0cade48b6615ae2c","name":"send single press","rules":[{"t":"set","p":"payload","pt":"msg","to":"single","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":200,"wires":[["d07ffbaf1baaad6a"]]},{"id":"ba9d2f5d092958d9","type":"change","z":"0cade48b6615ae2c","name":"Handled","rules":[{"t":"set","p":"handled","pt":"flow","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":660,"y":120,"wires":[[]]},{"id":"8749fa54c44ca0fd","type":"change","z":"0cade48b6615ae2c","name":"Unhandled","rules":[{"t":"set","p":"handled","pt":"flow","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":80,"wires":[[]]},{"id":"d07ffbaf1baaad6a","type":"switch","z":"0cade48b6615ae2c","name":"Not handled yet","property":"handled","propertyType":"flow","rules":[{"t":"eq","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":600,"y":200,"wires":[["b4e451b4d33a14ff"]]},{"id":"ba0dc4d0a3e1e436","type":"change","z":"0cade48b6615ae2c","name":"Single press","rules":[{"t":"set","p":"payload","pt":"msg","to":"OutputSingle","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":830,"y":140,"wires":[[]]},{"id":"f3d857b4b7366fd1","type":"change","z":"0cade48b6615ae2c","name":"Long press","rules":[{"t":"set","p":"payload","pt":"msg","to":"OutputLong","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":830,"y":180,"wires":[[]]}]

Flow Info

Created 3 years ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • change (x6)
  • switch (x3)
  • trigger (x1)
Other
  • subflow (x1)

Tags

  • single
  • long
  • press
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option