[Help ] openhab 2 / node-red rule with multiple inputs

Hello,

I’m trying to create a rule with openhab and node red to archive the following:
I would like to mesaure the humidity and create an visible alarm with a flashlight, when motion is detected in the room.

For that I used 1 Cyrus 4 in 1 sensor for motion and humidity detection and a virtual switch to enable the rule.

Below is the code from node-red, does someone has an idea what is going wrong or how to solve or better create the rule ?

[{"id":"51946f4d.7eaf3","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"28b33a69.122b66","type":"openhab2-in","z":"51946f4d.7eaf3","name":"SenMotion_CyrusBad","controller":"f1872b12.bfd088","itemname":"SenMotion_CyrusBad","x":153.1667938232422,"y":83.000075340271,"wires":[["a65b3386.1fb0c"],[]]},{"id":"149ad426.1ee92c","type":"openhab2-in","z":"51946f4d.7eaf3","name":"SenHumidityItem_CyrusBad","controller":"f1872b12.bfd088","itemname":"SenHumidityItem_CyrusBad","x":165.16669464111328,"y":317.00014877319336,"wires":[[],["93938a89.3f5968"]]},{"id":"a65b3386.1fb0c","type":"function","z":"51946f4d.7eaf3","name":"Storing the Data var motion","func":"\nif (msg.payload == \"ON\")\n{\n    global.set(\"motion\",\"ON\");\n  \n}\nelse if (msg.payload == \"OFF\")\n{\n    global.set(\"motion\",\"OFF\");\n}","outputs":1,"noerr":0,"x":515.1667175292969,"y":81.00006198883057,"wires":[[]]},{"id":"c55b67ff.8148a8","type":"openhab2-in","z":"51946f4d.7eaf3","name":"RuleSwitch On/OFF","controller":"f1872b12.bfd088","itemname":"RuleItem_SwitchBad","x":143.00003814697266,"y":201.00007915496826,"wires":[["578f1936.6c9c48","fc3a0557.f5a068"],[]]},{"id":"578f1936.6c9c48","type":"function","z":"51946f4d.7eaf3","name":"Storing the Data var RULE","func":"\n\nif (msg.payload==\"ON\")\n{\n    global.set(\"rule\",\"ON\");\n}\nelse if (msg.payload==\"OFF\")\n{\n    global.set(\"rule\",\"OFF\");\n}","outputs":1,"noerr":0,"x":621.000114440918,"y":190.00005340576172,"wires":[[]]},{"id":"be4c42f6.fb3d5","type":"function","z":"51946f4d.7eaf3","name":"humidhigh","func":"var motionstatus=global.get(\"motion\");\nvar rulestatus=global.get(\"rule\");\nvar humidity=global.get(hum1)\n\n\nif((motionstatus==\"ON\") && (rulestatus==\"ON\") && (humidity>65))\n{\n    global.set(\"humidhigh\",ON);\n    }\nelse\n{\n    global.set(\"hmidhigh\",OFF);\n}\n","outputs":1,"noerr":0,"x":276.1670608520508,"y":475.00015449523926,"wires":[[]]},{"id":"1823f006.148fe","type":"function","z":"51946f4d.7eaf3","name":"Storing the Data var humitidy","func":"global.set(\"hum1\",msg.payload);","outputs":1,"noerr":0,"x":1041.000228881836,"y":333.0002250671387,"wires":[[]]},{"id":"1ca5c355.2f076d","type":"debug","z":"51946f4d.7eaf3","name":"humid value","active":true,"console":"true","complete":"true","x":1003.000129699707,"y":288.0001392364502,"wires":[]},{"id":"6c60595c.021af8","type":"function","z":"51946f4d.7eaf3","name":"humidhigh check","func":"var humiditystatus=global.get(\"humidhigh\")\n\nif(humiditystatus==\"ON\")\n{\n    msg.payload=\"sendCommand(LSELECT)\";\n    }\n    else if (humiditystatus==\"OFF\")\n    {\n        msg.payload=\"sendCommand(NONE)\";\n    }\nreturn msg;","outputs":1,"noerr":0,"x":342.16674041748047,"y":696.0001630783081,"wires":[["4b07fe20.535d6","1170915e.7a730f"]]},{"id":"4b07fe20.535d6","type":"openhab2-out","z":"51946f4d.7eaf3","name":"FlurDG_Alert","controller":"f1872b12.bfd088","itemname":"item_FlurDG_Alert","topic":"","payload":"","x":693.1667404174805,"y":695.0001611709595,"wires":[]},{"id":"1170915e.7a730f","type":"debug","z":"51946f4d.7eaf3","name":"humiditystatus value","active":true,"console":"true","complete":"payload","x":603.0000648498535,"y":619.0001583099365,"wires":[]},{"id":"fc3a0557.f5a068","type":"debug","z":"51946f4d.7eaf3","name":"SW Status","active":true,"console":"true","complete":"true","x":567.0000686645508,"y":148.00003910064697,"wires":[]},{"id":"93938a89.3f5968","type":"switch","z":"51946f4d.7eaf3","name":"ItemStateEvent","property":"payload.type","propertyType":"msg","rules":[{"t":"eq","v":"ItemStateEvent","vt":"str"}],"checkall":"true","outputs":1,"x":399.0000762939453,"y":320.0001049041748,"wires":[["62d713ef.5cf54c"]]},{"id":"62d713ef.5cf54c","type":"switch","z":"51946f4d.7eaf3","name":"Changed >65","property":"payload.payload.value","propertyType":"msg","rules":[{"t":"gt","v":"65","vt":"str"}],"checkall":"true","outputs":1,"x":600.0001678466797,"y":320.00018310546875,"wires":[["1ca5c355.2f076d","1823f006.148fe"]]},{"id":"c04b8434.d595e8","type":"comment","z":"51946f4d.7eaf3","name":"flow motion detection will bestored in a variable","info":"","x":231.16667938232422,"y":28.333337783813477,"wires":[]},{"id":"34886c97.9a2904","type":"comment","z":"51946f4d.7eaf3","name":"flow Rule on/off will bestored in a variable","info":"","x":209,"y":156,"wires":[]},{"id":"1a25e104.043dcf","type":"comment","z":"51946f4d.7eaf3","name":"flow humidity check over 65% will be stored in a variable","info":"","x":254.00000762939453,"y":275.0000162124634,"wires":[]},{"id":"eda80746.7ed1d8","type":"comment","z":"51946f4d.7eaf3","name":"AND function to compine the inputs into one output","info":"","x":234.00000762939453,"y":417.0000247955322,"wires":[]},{"id":"56fc1bb8.984d14","type":"comment","z":"51946f4d.7eaf3","name":"reading the status of all 3 conditions to switch on an alert","info":"","x":258.0000305175781,"y":599.0000371932983,"wires":[]},{"id":"f1872b12.bfd088","type":"openhab2-controller","z":"","name":"openhabian","protocol":"http","host":"192.168.99.101","port":"8080","path":"","username":"","password":""}]

Best regards
Maik

You are likely to have better luck posting to a Node-Red forum. While there are a few users of Node-Red on this forum, you will reach a far larger audience.

Sorry, I don’t use the oh nodes anymore so can’t load up your flow. But based on what you described there are a couple of options I would suggest:

  • Simplest is to store the state variables (I’m guessing you are doing that ni your functions but you can also do that using a change node to set a flow or global variable). And then run multiple switche nodes in serial for each state after your initial high humidity trigger.
  • Instead of multiple switch nodes there is a contributed match node that lets you check all at once - https://www.npmjs.com/package/node-red-contrib-match
  • Third option would be to use the oh get nodes with each combined with the appropriate switch check in serial after the initial high humidity trigger vs storing the variables.

I hope these suggestions make sense and help.

1 Like