Home Assistant Node-RED documentation

My full code as a backup and some useful reminders that are difficult to find online.

In order not to spam z-wave communication. Only send a command when the value has changed > 4 (0-255). A join block before this combines the current (msg.payload.huidig) and setpoint (msg.payload.aansturing). Here we send the first node output only when the difference between set and current is > 4.

[{"id":"efc424fe7efcc58f","type":"function","z":"c2ef1cc98daf2c98","name":"aansturen als target!=huidig","func":"msg.payload.aansturing = Number(msg.payload.aansturing);\nmsg.payload.huidig = Number(msg.payload.huidig);\n//return msg;\nif (Math.abs(msg.payload.aansturing - msg.payload.huidig) > 4) {\n    if (msg.payload.aansturing === 0) {\n        return [ null, msg ];\n    }\n    else{\n    return [ msg, null ];\n}};","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1060,"y":40,"wires":[["cb81cd2824a77fd4"],["69eecb2112758531","c1b6aace4d6466e8"]]}]

Full code below, this gets messy

[{"id":"c2ef1cc98daf2c98","type":"tab","label":"Ventilatie aansturing","disabled":false,"info":"","env":[]},{"id":"2710882f6d85a630","type":"poll-state","z":"c2ef1cc98daf2c98","name":"","server":"c82c6ec0.d70ce","version":2,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"updateinterval":"60","updateIntervalType":"num","updateIntervalUnits":"seconds","outputinitially":true,"outputonchanged":false,"entity_id":"sensor.mh_z19_co2_value","state_type":"num","halt_if":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"x":200,"y":140,"wires":[["392cc7b2f4d00904"]]},{"id":"390bde87783eda88","type":"api-call-service","z":"c2ef1cc98daf2c98","name":"setMV","server":"c82c6ec0.d70ce","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":["29706e0991142b57719d53f2917226a1"],"entityId":[],"data":"{\"brightness\":{{payload}}}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1450,"y":20,"wires":[[]]},{"id":"9b80fac1.4d62e8","type":"join","z":"c2ef1cc98daf2c98","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":590,"y":140,"wires":[["9d32943.7172068"]]},{"id":"9d32943.7172068","type":"change","z":"c2ef1cc98daf2c98","name":"change","rules":[{"t":"set","p":"payload","pt":"msg","to":"$max(payload)","tot":"jsonata"},{"t":"set","p":"topic","pt":"msg","to":"aansturing","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":730,"y":140,"wires":[["8f8806f9d93207ee"]]},{"id":"c2d9cbe7.35c678","type":"debug","z":"c2ef1cc98daf2c98","name":"CO2 aansturing","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":460,"y":100,"wires":[]},{"id":"392cc7b2f4d00904","type":"function","z":"c2ef1cc98daf2c98","name":"function 1","func":"msg.payload=(msg.payload-950)/1.56\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":440,"y":140,"wires":[["9b80fac1.4d62e8","c2d9cbe7.35c678"]]},{"id":"8f8806f9d93207ee","type":"range","z":"c2ef1cc98daf2c98","minin":"0","maxin":"255","minout":"0","maxout":"255","action":"clamp","round":true,"property":"payload","name":"aansturing","x":890,"y":140,"wires":[["55d193ef29fdd294","1db1535a7fbc18d2"]]},{"id":"20f316fb96e5abe3","type":"poll-state","z":"c2ef1cc98daf2c98","name":"","server":"c82c6ec0.d70ce","version":2,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"updateinterval":"60","updateIntervalType":"num","updateIntervalUnits":"seconds","outputinitially":true,"outputonchanged":false,"entity_id":"sensor.solar","state_type":"num","halt_if":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"x":220,"y":220,"wires":[["6d298738b4713257"]]},{"id":"6d298738b4713257","type":"function","z":"c2ef1cc98daf2c98","name":"function 2","func":"msg.payload=(msg.payload/100*2.56)\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":440,"y":220,"wires":[["9b80fac1.4d62e8","5d60c2fdd637f4a0"]]},{"id":"5d60c2fdd637f4a0","type":"debug","z":"c2ef1cc98daf2c98","name":"Solar aansturing","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":440,"y":180,"wires":[]},{"id":"7b83e97ddacaec0e","type":"poll-state","z":"c2ef1cc98daf2c98","name":"badkamer RV","server":"c82c6ec0.d70ce","version":2,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"updateinterval":"60","updateIntervalType":"num","updateIntervalUnits":"seconds","outputinitially":true,"outputonchanged":false,"entity_id":"sensor.humidity_158d00019cadcb","state_type":"num","halt_if":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"x":250,"y":280,"wires":[["9ad2e333ecc7671b"]]},{"id":"d8b2f1b8d527d296","type":"poll-state","z":"c2ef1cc98daf2c98","name":"Badkamer AV","server":"c82c6ec0.d70ce","version":2,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"updateinterval":"60","updateIntervalType":"num","updateIntervalUnits":"seconds","outputinitially":true,"outputonchanged":false,"entity_id":"sensor.thermal_badkamer_absolutehumidity","state_type":"num","halt_if":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"x":250,"y":340,"wires":[["9ad2e333ecc7671b"]]},{"id":"4d18a86726ec3f2c","type":"poll-state","z":"c2ef1cc98daf2c98","name":"Buiten AV","server":"c82c6ec0.d70ce","version":2,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"updateinterval":"60","updateIntervalType":"num","updateIntervalUnits":"seconds","outputinitially":true,"outputonchanged":false,"entity_id":"sensor.thermal_buiten_absolutehumidity","state_type":"num","halt_if":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"x":240,"y":400,"wires":[["9ad2e333ecc7671b"]]},{"id":"2927ad3defe07c77","type":"debug","z":"c2ef1cc98daf2c98","name":"mv aansturing","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1480,"y":60,"wires":[]},{"id":"efc424fe7efcc58f","type":"function","z":"c2ef1cc98daf2c98","name":"aansturen als target!=huidig","func":"msg.payload.aansturing = Number(msg.payload.aansturing);\nmsg.payload.huidig = Number(msg.payload.huidig);\n//return msg;\nif (Math.abs(msg.payload.aansturing - msg.payload.huidig) > 5) {\n    if (msg.payload.aansturing === 0) {\n        return [ null, msg ];\n    }\n    else{\n    return [ msg, null ];\n}};","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1060,"y":40,"wires":[["cb81cd2824a77fd4"],["69eecb2112758531","c1b6aace4d6466e8"]]},{"id":"55d193ef29fdd294","type":"join","z":"c2ef1cc98daf2c98","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":850,"y":40,"wires":[["efc424fe7efcc58f","5578c9f78be4a103"]]},{"id":"5578c9f78be4a103","type":"debug","z":"c2ef1cc98daf2c98","name":"join","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":990,"y":80,"wires":[]},{"id":"b691db32a61fa003","type":"poll-state","z":"c2ef1cc98daf2c98","name":"","server":"c82c6ec0.d70ce","version":2,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"updateinterval":"60","updateIntervalType":"num","updateIntervalUnits":"seconds","outputinitially":true,"outputonchanged":false,"entity_id":"light.mechanische_ventilatie","state_type":"num","halt_if":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"x":190,"y":40,"wires":[["943308481e53b3c3","9b2eb3b5721e7a90"]]},{"id":"69eecb2112758531","type":"debug","z":"c2ef1cc98daf2c98","name":"mv uitsturing","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1210,"y":140,"wires":[]},{"id":"c1b6aace4d6466e8","type":"api-call-service","z":"c2ef1cc98daf2c98","name":"setMV","server":"c82c6ec0.d70ce","version":5,"debugenabled":false,"domain":"light","service":"turn_off","areaId":[],"deviceId":["29706e0991142b57719d53f2917226a1"],"entityId":[],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1190,"y":100,"wires":[[]]},{"id":"bc656e3233c080b6","type":"change","z":"c2ef1cc98daf2c98","name":"mv staat uit","rules":[{"t":"set","p":"topic","pt":"msg","to":"huidig","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":690,"y":40,"wires":[["55d193ef29fdd294"]]},{"id":"cb81cd2824a77fd4","type":"change","z":"c2ef1cc98daf2c98","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.aansturing","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1280,"y":20,"wires":[["390bde87783eda88","2927ad3defe07c77"]]},{"id":"1db1535a7fbc18d2","type":"debug","z":"c2ef1cc98daf2c98","name":"aansturing","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1030,"y":180,"wires":[]},{"id":"943308481e53b3c3","type":"debug","z":"c2ef1cc98daf2c98","name":"huidig","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":410,"y":60,"wires":[]},{"id":"3309f603760f9269","type":"change","z":"c2ef1cc98daf2c98","name":"mv staat aan","rules":[{"t":"set","p":"topic","pt":"msg","to":"huidig","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"data.attributes.brightness","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":690,"y":80,"wires":[["55d193ef29fdd294"]]},{"id":"9ad2e333ecc7671b","type":"join","z":"c2ef1cc98daf2c98","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":410,"y":340,"wires":[["1d33518d9aa72fc6","f48ec69c62b898cd"]]},{"id":"1d33518d9aa72fc6","type":"debug","z":"c2ef1cc98daf2c98","name":"debug 1","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":540,"y":380,"wires":[]},{"id":"f48ec69c62b898cd","type":"function","z":"c2ef1cc98daf2c98","name":"badkamer berekening","func":"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":580,"y":340,"wires":[[]]},{"id":"9b2eb3b5721e7a90","type":"function","z":"c2ef1cc98daf2c98","name":"mv staat aan of uit","func":"//msg.payload = msg.data.attributes.brightness\n//var huidig = msg.data.attributes.brightness; \n//if (msg.data.attributes.brightness = \"Null\") {\nif (typeof msg.data.attributes.brightness != 'undefined' && msg.data.attributes.brightness !== null) {\n    return [null, msg];\n}\nelse\nreturn [msg, null];","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":510,"y":40,"wires":[["bc656e3233c080b6"],["3309f603760f9269"]]},{"id":"c82c6ec0.d70ce","type":"server","name":"Home Assistant","addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"","connectionDelay":false,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"","statusSeparator":"","enableGlobalContextStore":false}]

Leave a Reply

Your email address will not be published. Required fields are marked *