Pushbuttons in node-red with websockets



  • I have the issue that on a short press the websocket doesn't send a value of 1 , it only sends a 0 when the button is released. Most of the time it works as evok normally only sends the changed input, so I act on that message no matter what the value is. However, sometimes I get the entire group through the websocket, so all lights in that group get toggled sometimes.

    Can I change the polling frequency so I could also receive the 1 or should I use the counter value instead? Any other suggestions?

    btw, I'm using a Neuron M203

    [{"id":"77893f7c.39406","type":"websocket in","z":"b3408b47.04fd88","name":"","server":"","client":"6ecbf0ef.69ace","x":360,"y":460,"wires":[["e1ca81e3.be73a"]]},{"id":"7687cc40.122e14","type":"http request","z":"b3408b47.04fd88","name":"RO2.13 - zolder verlichting","method":"POST","ret":"txt","url":"http://127.0.0.1:8088/rest/relay/2_13","tls":"","x":1572.2500228881836,"y":723.5000114440918,"wires":[[]]},{"id":"6121d93.ed7ef28","type":"http request","z":"b3408b47.04fd88","name":"RO2.14 - gang +2 verlichting","method":"POST","ret":"txt","url":"http://127.0.0.1:8088/rest/relay/2_14","tls":"","x":1572.2500228881836,"y":759.5000114440918,"wires":[[]]},{"id":"7ed56638.d57d48","type":"http request","z":"b3408b47.04fd88","name":"RO2.1 - vrijgave ventilatie","method":"POST","ret":"txt","url":"http://127.0.0.1:8088/rest/relay/2_01","tls":"","x":1558.5000038146973,"y":211.24999856948853,"wires":[[]]},{"id":"3880c81a.369078","type":"http request","z":"b3408b47.04fd88","name":"RO2.2 - badkamer meubel","method":"POST","ret":"txt","url":"http://127.0.0.1:8088/rest/relay/2_02","tls":"","x":1567.500015258789,"y":359.99999809265137,"wires":[[]]},{"id":"79e5c145.10c08","type":"http request","z":"b3408b47.04fd88","name":"RO2.3 - badkamer verlichting","method":"POST","ret":"txt","url":"http://127.0.0.1:8088/rest/relay/2_03","tls":"","x":1577.0000076293945,"y":439.00000286102295,"wires":[[]]},{"id":"3e168b0b.4d20a4","type":"http request","z":"b3408b47.04fd88","name":"RO2.4 - gang +1 verlichting","method":"POST","ret":"txt","url":"http://127.0.0.1:8088/rest/relay/2_04","tls":"","x":1571.0000076293945,"y":556.500002861023,"wires":[[]]},{"id":"a51a7971.5c6568","type":"http request","z":"b3408b47.04fd88","name":"RO2.5 - slaapkamer verlichting","method":"POST","ret":"txt","url":"http://127.0.0.1:8088/rest/relay/2_05","tls":"","x":1581.2500076293945,"y":591.2500038146973,"wires":[[]]},{"id":"ceb982af.ad478","type":"http request","z":"b3408b47.04fd88","name":"RO2.6 - kamer Henri verlichting","method":"POST","ret":"txt","url":"http://127.0.0.1:8088/rest/relay/2_06","tls":"","x":1583.2500076293945,"y":630.2500038146973,"wires":[[]]},{"id":"ed36ffcc.95df3","type":"http request","z":"b3408b47.04fd88","name":"RO2.7 - kamer Renée verlichting","method":"POST","ret":"txt","url":"http://127.0.0.1:8088/rest/relay/2_07","tls":"","x":1592.2500076293945,"y":670.2500038146973,"wires":[[]]},{"id":"a01ffa8d.65cfb8","type":"http request","z":"b3408b47.04fd88","name":"DO1.2 - drukknop badkamer B","method":"POST","ret":"txt","url":"http://127.0.0.1:8088/rest/relay/1_02","tls":"","x":1578.7500038146973,"y":246.74999713897705,"wires":[[]]},{"id":"e1ca81e3.be73a","type":"json","z":"b3408b47.04fd88","name":"","x":290,"y":520,"wires":[["8f91b2ac.a648e","43ada45b.3a96ac"]]},{"id":"2d89aca8.a11194","type":"http request","z":"b3408b47.04fd88","name":"DO1.3 - drukknop badkamer C","method":"POST","ret":"txt","url":"http://127.0.0.1:8088/rest/relay/1_03","tls":"","x":1576.750015258789,"y":395.99999713897705,"wires":[[]]},{"id":"6c3523d4.37d1ac","type":"http request","z":"b3408b47.04fd88","name":"DO1.4 - drukknop badkamer D","method":"POST","ret":"txt","url":"http://127.0.0.1:8088/rest/relay/1_04","tls":"","x":1575.750015258789,"y":477.5000009536743,"wires":[[]]},{"id":"8f91b2ac.a648e","type":"split","z":"b3408b47.04fd88","name":"","splt":"\\n","x":290,"y":580,"wires":[["e35819d5.2c2068"]]},{"id":"d3f64828.421488","type":"switch","z":"b3408b47.04fd88","name":"Inputs","property":"payload.circuit","propertyType":"msg","rules":[{"t":"eq","v":"1_01","vt":"str"},{"t":"eq","v":"1_02","vt":"str"},{"t":"eq","v":"1_03","vt":"str"},{"t":"eq","v":"1_04","vt":"str"},{"t":"eq","v":"2_01","vt":"str"},{"t":"eq","v":"2_02","vt":"str"},{"t":"eq","v":"2_03","vt":"str"},{"t":"eq","v":"2_04","vt":"str"},{"t":"eq","v":"2_05","vt":"str"},{"t":"eq","v":"2_06","vt":"str"},{"t":"eq","v":"2_07","vt":"str"},{"t":"eq","v":"2_08","vt":"str"},{"t":"eq","v":"2_09","vt":"str"},{"t":"eq","v":"2_10","vt":"str"},{"t":"eq","v":"2_11","vt":"str"},{"t":"eq","v":"2_12","vt":"str"},{"t":"eq","v":"2_13","vt":"str"},{"t":"eq","v":"2_14","vt":"str"},{"t":"eq","v":"2_15","vt":"str"},{"t":"eq","v":"2_16","vt":"str"}],"checkall":"true","outputs":20,"x":676.0000114440918,"y":448.25,"wires":[["f39b5a6f.109a38"],["e04ee2cc.e9e2e"],["553cb5a7.86ba8c"],[],[],["54a13c4e.2f3a94"],["2d90df98.1a5f9"],["829faa84.dde3f8"],["8e24e6b.e608218"],["2df5b139.6a88fe"],["704c5245.41382c"],[],[],[],[],[],["86eeee7a.b2071"],["37e8e489.8d238c"],[],[]]},{"id":"54a13c4e.2f3a94","type":"function","z":"b3408b47.04fd88","name":"pushbutton","func":"newMsg = {};\nprevValue = context.get('value')||0;\n\nif (msg.payload.dev == \"input\") {\n    if (prevValue === 0) {\n        newValue = 1;\n        newMsg.payload = \"value=1\";\n    } else {\n        newValue = 0;\n        newMsg.payload = \"value=0\";\n    }\n    newMsg.headers = { \"Content-type\" : \"application/x-www-form-urlencoded\" };\n    context.set('value', newValue);\n    return newMsg;\n}\nif (msg.payload.dev == \"relay\") {\n    context.set('value', msg.payload.value);\n}\n\n\n","outputs":1,"noerr":0,"x":1125.0000190734863,"y":366.2500057220459,"wires":[["3880c81a.369078","2d89aca8.a11194"]]},{"id":"e35819d5.2c2068","type":"switch","z":"b3408b47.04fd88","name":"","property":"payload.dev","propertyType":"msg","rules":[{"t":"eq","v":"input","vt":"str"},{"t":"eq","v":"relay","vt":"str"},{"t":"neq","v":"ai","vt":"str"}],"checkall":"true","outputs":3,"x":290,"y":640,"wires":[["d3f64828.421488"],["ef8bd356.5bc43"],[]]},{"id":"ef8bd356.5bc43","type":"switch","z":"b3408b47.04fd88","name":"Outputs","property":"payload.circuit","propertyType":"msg","rules":[{"t":"eq","v":"1_01","vt":"str"},{"t":"eq","v":"1_02","vt":"str"},{"t":"eq","v":"1_03","vt":"str"},{"t":"eq","v":"1_04","vt":"str"},{"t":"eq","v":"2_01","vt":"str"},{"t":"eq","v":"2_02","vt":"str"},{"t":"eq","v":"2_03","vt":"str"},{"t":"eq","v":"2_04","vt":"str"},{"t":"eq","v":"2_05","vt":"str"},{"t":"eq","v":"2_06","vt":"str"},{"t":"eq","v":"2_07","vt":"str"},{"t":"eq","v":"2_08","vt":"str"},{"t":"eq","v":"2_09","vt":"str"},{"t":"eq","v":"2_10","vt":"str"},{"t":"eq","v":"2_11","vt":"str"},{"t":"eq","v":"2_12","vt":"str"},{"t":"eq","v":"2_13","vt":"str"},{"t":"eq","v":"2_14","vt":"str"}],"checkall":"true","outputs":18,"x":685,"y":775,"wires":[["553cb5a7.86ba8c"],[],[],[],["553cb5a7.86ba8c"],["54a13c4e.2f3a94"],["2d90df98.1a5f9"],["829faa84.dde3f8"],[],[],[],[],[],[],[],[],["86eeee7a.b2071"],["37e8e489.8d238c"]]},{"id":"2d90df98.1a5f9","type":"function","z":"b3408b47.04fd88","name":"pushbutton","func":"newMsg = {};\nprevValue = context.get('value')||0;\n\nif (msg.payload.dev == \"input\") {\n    if (prevValue === 0) {\n        newValue = 1;\n        newMsg.payload = \"value=1\";\n    } else {\n        newValue = 0;\n        newMsg.payload = \"value=0\";\n    }\n    newMsg.headers = { \"Content-type\" : \"application/x-www-form-urlencoded\" };\n    context.set('value', newValue);\n    return newMsg;\n}\nif (msg.payload.dev == \"relay\") {\n    context.set('value', msg.payload.value);\n}\n\n\n","outputs":1,"noerr":0,"x":1126.2500190734863,"y":458.75000762939453,"wires":[["6c3523d4.37d1ac","79e5c145.10c08"]]},{"id":"f39b5a6f.109a38","type":"function","z":"b3408b47.04fd88","name":"motionVentilation","func":"relayMsg = {};\naoMsg = {};\nfbMsg = {};\nfbMsg.payload.dev = \"relay\";\nfbMsg.payload.circuit = \"2_01\";\n\nvar hour = new Date().getHours();\n//node.warn(hour);\n\nif (hour >= 7 && hour <= 23) {\n    if (msg.payload.value === 1) {\n        relayMsg.payload = \"value=1\";\n        aoMsg.payload = \"value=2\";\n        fbMsg.payload.value = 1;\n    } else {\n        relayMsg.payload = \"value=0\";\n        aoMsg.payload = \"value=0\";\n        fbMsg.payload.value = 0;\n    } \n    relayMsg.headers = { \"Content-type\" : \"application/x-www-form-urlencoded\" };\n    aoMsg.headers = { \"Content-type\" : \"application/x-www-form-urlencoded\" };\n    return [relayMsg, aoMsg, fbMsg];\n}","outputs":"3","noerr":0,"x":1067.500015258789,"y":168.75000286102295,"wires":[["7ed56638.d57d48","a01ffa8d.65cfb8"],["2a5a451c.fc08ea"],["553cb5a7.86ba8c"]]},{"id":"2a5a451c.fc08ea","type":"http request","z":"b3408b47.04fd88","name":"AO - sturing ventilatie","method":"POST","ret":"txt","url":"http://127.0.0.1:8088/rest/ao/1_01","tls":"","x":1547.5000038146973,"y":285.00001430511475,"wires":[[]]},{"id":"553cb5a7.86ba8c","type":"function","z":"b3408b47.04fd88","name":"manualVentilation","func":"relayMsg = {};\naoMsg = {};\ntriggerMsg = {};\n\nprevValue = context.get('value')||0;\n\n\nif (msg.payload.dev == \"input\") {\n    if (prevValue === 0) {\n        newValue = 1;\n        relayMsg.payload = \"value=1\";\n        aoMsg.payload = \"value=3\";\n        triggerMsg = 1;\n    } else {\n        newValue = 0;\n        relayMsg.payload = \"value=0\";\n        aoMsg.payload = \"value=0\";\n        triggerMssg = 0;\n    }\n    relayMsg.headers = { \"Content-type\" : \"application/x-www-form-urlencoded\" };\n    aoMsg.headers = { \"Content-type\" : \"application/x-www-form-urlencoded\" };\n    context.set('value', newValue);\n    return [relayMsg, aoMsg, triggerMsg];\n}\nif (msg.payload.dev == \"relay\") {\n    context.set('value', msg.payload.value);\n}\n\n\n","outputs":"3","noerr":0,"x":1066.250015258789,"y":245.00000381469727,"wires":[["7ed56638.d57d48","a01ffa8d.65cfb8"],["2a5a451c.fc08ea"],[]]},{"id":"829faa84.dde3f8","type":"function","z":"b3408b47.04fd88","name":"pushbutton","func":"newMsg = {};\nprevValue = context.get('value')||0;\n\nif (msg.payload.dev == \"input\") {\n    if (prevValue === 0) {\n        newValue = 1;\n        newMsg.payload = \"value=1\";\n    } else {\n        newValue = 0;\n        newMsg.payload = \"value=0\";\n    }\n    newMsg.headers = { \"Content-type\" : \"application/x-www-form-urlencoded\" };\n    context.set('value', newValue);\n    return newMsg;\n}\nif (msg.payload.dev == \"relay\") {\n    context.set('value', msg.payload.value);\n}\n\n\n","outputs":1,"noerr":0,"x":1132.5,"y":555,"wires":[["3e168b0b.4d20a4"]]},{"id":"86eeee7a.b2071","type":"function","z":"b3408b47.04fd88","name":"pushbutton","func":"newMsg = {};\nprevValue = context.get('value')||0;\n\nif (msg.payload.dev == \"input\") {\n    if (prevValue === 0) {\n        newValue = 1;\n        newMsg.payload = \"value=1\";\n    } else {\n        newValue = 0;\n        newMsg.payload = \"value=0\";\n    }\n    newMsg.headers = { \"Content-type\" : \"application/x-www-form-urlencoded\" };\n    context.set('value', newValue);\n    return newMsg;\n}\nif (msg.payload.dev == \"relay\") {\n    context.set('value', msg.payload.value);\n}\n\n\n","outputs":1,"noerr":0,"x":1133.75,"y":721.25,"wires":[["7687cc40.122e14"]]},{"id":"37e8e489.8d238c","type":"function","z":"b3408b47.04fd88","name":"pushbutton","func":"newMsg = {};\nprevValue = context.get('value')||0;\n\nif (msg.payload.dev == \"input\") {\n    if (prevValue === 0) {\n        newValue = 1;\n        newMsg.payload = \"value=1\";\n    } else {\n        newValue = 0;\n        newMsg.payload = \"value=0\";\n    }\n    newMsg.headers = { \"Content-type\" : \"application/x-www-form-urlencoded\" };\n    context.set('value', newValue);\n    return newMsg;\n}\nif (msg.payload.dev == \"relay\") {\n    context.set('value', msg.payload.value);\n}\n\n\n","outputs":1,"noerr":0,"x":1135,"y":761.25,"wires":[["6121d93.ed7ef28"]]},{"id":"8e24e6b.e608218","type":"function","z":"b3408b47.04fd88","name":"switch","func":"newMsg = {};\n\nif (msg.payload.value === 1) {\n    newMsg.payload = \"value=1\";\n} else {\n    newMsg.payload = \"value=0\";\n} \nnewMsg.headers = { \"Content-type\" : \"application/x-www-form-urlencoded\" };\nreturn newMsg;","outputs":1,"noerr":0,"x":1128.750015258789,"y":592.5000133514404,"wires":[["a51a7971.5c6568"]]},{"id":"2df5b139.6a88fe","type":"function","z":"b3408b47.04fd88","name":"switch","func":"newMsg = {};\n\nif (msg.payload.value === 1) {\n    newMsg.payload = \"value=1\";\n} else {\n    newMsg.payload = \"value=0\";\n} \nnewMsg.headers = { \"Content-type\" : \"application/x-www-form-urlencoded\" };\nreturn newMsg;","outputs":1,"noerr":0,"x":1128.75,"y":630,"wires":[["ceb982af.ad478"]]},{"id":"704c5245.41382c","type":"function","z":"b3408b47.04fd88","name":"switch","func":"newMsg = {};\n\nif (msg.payload.value === 1) {\n    newMsg.payload = \"value=1\";\n} else {\n    newMsg.payload = \"value=0\";\n} \nnewMsg.headers = { \"Content-type\" : \"application/x-www-form-urlencoded\" };\nreturn newMsg;","outputs":1,"noerr":0,"x":1128.75,"y":667.5,"wires":[["ed36ffcc.95df3"]]},{"id":"43ada45b.3a96ac","type":"debug","z":"b3408b47.04fd88","name":"","active":false,"console":"false","complete":"false","x":375.71428571428567,"y":834.2857142857142,"wires":[]},{"id":"6ecbf0ef.69ace","type":"websocket-client","z":"","path":"ws://127.0.0.1:8088/ws","wholemsg":"false"}]```

  • administrators

    @Niko-Raes Please try to set the scan_frequency to higher (eg. 5) value in /etc/evok.conf



  • @tomas_hora Thank you, this is indeed better. What does this number mean? Polls per second? What's the maximum?


  • administrators

    @Niko-Raes Exactly, its polls per second. Honestly, I have not tried the maximum because it depends on the exact model - with more IOs there are more values to be read which results in smaller possible polling rate.