Light control, need help with long button press

i need help to realize a long press function for the following flow
For now, a key press switches the relais on or off and defines a flow var for timeout (automatic off)

Next step is to add an additional "on" time to the relais (in flipflop relais node the timeout is defined)
how i can realize that here?

relevant flow part:

[{"id":"655d24bd.d0a164","type":"subflow","name":"FlipFlop Relais","info":"","category":"","in":[{"x":50,"y":30,"wires":[{"id":"a1072dd0.068098"}]}],"out":[{"x":340,"y":40,"wires":[{"id":"a1072dd0.068098","port":0}]},{"x":300,"y":140,"wires":[{"id":"a1072dd0.068098","port":1}]}],"env":[],"color":"#DDAA99"},{"id":"a1072dd0.068098","type":"function","z":"655d24bd.d0a164","name":"","func":"var last_state = flow.get('$parent.RO_' + msg.relais + '_last')||0;\nvar xor_relais = Number(1^last_state);\n\nif ( (xor_relais == 1) )\n{\n    trigger = flow.get('$parent.' + msg.timer)||false;\n\n    var date;\n    date = new Date().getTime();\n    if(trigger)\n        date = date + ( msg.timer_active * 60 * 1000 ) ;\n    else\n        date = date + ( msg.timer_inactive * 60 * 1000 ) ;\n    flow.set('$parent.RO_' + msg.relais + '_timer', date);\n\n    return [ {payload: true}, {payload: date} ];\n}\nelse \n{\n    return [ {payload: false}, {payload: 0 } ];\n}\n","outputs":2,"noerr":0,"x":190,"y":120,"wires":[[],[]]},{"id":"b6bc19b6.c6d128","type":"comment","z":"31da2beb.cfd3fc","name":"Bad","info":"","x":370,"y":720,"wires":[]},{"id":"cd948130.657508","type":"switch","z":"31da2beb.cfd3fc","name":"press/release","property":"payload.value","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"0","vt":"str"}],"checkall":"false","repair":false,"outputs":2,"x":620,"y":760,"wires":[["cfcc223d.2b4e7"],[]],"outputLabels":["press","release"]},{"id":"e7db16e4.9cc6b","type":"comment","z":"31da2beb.cfd3fc","name":"Bad Deckenlampe","info":"","x":1490,"y":740,"wires":[]},{"id":"cfcc223d.2b4e7","type":"function","z":"31da2beb.cfd3fc","name":"Press Checker","func":"var input = msg.payload.circuit; // Digitaler Eingang aus msg Objekt\nvar last_counter = flow.get('DI_' + input + '_counter')||0;\n\nif ( (last_counter != msg.payload.counter) )\n{\n    flow.set('DI_' + input + '_counter', msg.payload.counter);\n\n    msg = {payload: true};\n    return msg;\n}","outputs":1,"noerr":0,"x":820,"y":760,"wires":[["1c0af307.cdcb5d"]]},{"id":"3492be48.db80ea","type":"mqtt in","z":"31da2beb.cfd3fc","name":"","topic":"Mitte/ChangeRelais/3_03","qos":"2","datatype":"json","broker":"8be602c8.90492","x":790,"y":720,"wires":[["1c0af307.cdcb5d"]]},{"id":"91336d3d.037268","type":"mqtt out","z":"31da2beb.cfd3fc","name":"","topic":"Mitte/Licht/3_03","qos":"2","retain":"false","broker":"8be602c8.90492","x":1380,"y":780,"wires":[]},{"id":"1c0af307.cdcb5d","type":"change","z":"31da2beb.cfd3fc","name":"3_03","rules":[{"t":"set","p":"relais","pt":"msg","to":"3_03","tot":"str"},{"t":"set","p":"timer","pt":"msg","to":"timer2","tot":"str"},{"t":"set","p":"timer_active","pt":"msg","to":"10","tot":"num"},{"t":"set","p":"timer_inactive","pt":"msg","to":"40","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1030,"y":760,"wires":[["d7ad132a.9d0f4"]]},{"id":"d7ad132a.9d0f4","type":"subflow:655d24bd.d0a164","z":"31da2beb.cfd3fc","name":"","env":[],"x":1180,"y":760,"wires":[["23aa3b56.abffa4"],["91336d3d.037268"]]},{"id":"30462b11.f34684","type":"unipi-input","z":"31da2beb.cfd3fc","name":"DI3_13","alias":"","devices":"input","circuits":"3.13","property":"","seedev":"0","seecirc":"0","seeorig":"0","x":380,"y":760,"wires":[["cd948130.657508"]]},{"id":"23aa3b56.abffa4","type":"unipi-output","z":"31da2beb.cfd3fc","name":"R3.03","cmd":"set","alias":"","devices":"relay","circuits":"3.03","enableFil":"1","inputFil":"","relayFil":"","digoutFil":"","analoutFil":"","analinFil":"","ledFil":"","x":1630,"y":760,"wires":[["28cc4c48.56a7b4"]]},{"id":"8be602c8.90492","type":"mqtt-broker","name":"UV Keller","broker":"uv-kg","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

first input to switch node: (key press)

{"payload":{"counter_modes":["Enabled","Disabled"],"glob_dev_id":1,"modes":["Simple","DirectSwitch"],"value":1,"circuit":"3_15","debounce":50,"counter":131,"counter_mode":"Enabled","dev":"input","mode":"Simple"},"_session":{"type":"websocket","id":"8d5f9f03.3ccea"},"_msgid":"a1b05c03.a4278","_event":"node:4e0b472d.4289e"}

output from flipflop relais node: (change relais state)

{"payload":true,"_msgid":"a1b05c03.a4278"}

input to switch node (key release)

{"payload":{"counter_modes":["Enabled","Disabled"],"glob_dev_id":1,"modes":["Simple","DirectSwitch"],"value":0,"circuit":"3_15","debounce":50,"counter":131,"counter_mode":"Enabled","dev":"input","mode":"Simple"},"_session":{"type":"websocket","id":"8d5f9f03.3ccea"},"_msgid":"34295feb.73a4c","_event":"node:4e0b472d.4289e"}

new press and release changes the relais state (on/off)

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.