Hi all,
I read nearly every article and the Node-Red Primer (here) to figure out how to accomplish my node setup. Following requirements:
- interval every 2hours turn on this switch - with a delay of 30min turn it off (working)
- skip the switch turn on action if humidity is below 80%
- thus those two inputs to be joined and contents compared with a function
here is my current not working code with kind request for your help:
[{"id":"aec813ed.ae5","type":"inject","z":"e3e1d3c0.6b18","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"3600","crontab":"","once":true,"onceDelay":"","topic":"","payload":"","payloadType":"date","x":170,"y":660,"wires":[["ab666945.3b5c68"]]},{"id":"4457999e.bcd758","type":"delay","z":"e3e1d3c0.6b18","name":"","pauseType":"delay","timeout":"15","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":710,"y":560,"wires":[["e9f35c06.ef52f"]]},{"id":"e9f35c06.ef52f","type":"api-call-service","z":"e3e1d3c0.6b18","name":"","server":"2c3f285.7dce7d8","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_off","entityId":"switch.luftung_bad","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":990,"y":560,"wires":[["133b3eb2.6309c1"]]},{"id":"e0e6509a.a4a18","type":"api-call-service","z":"e3e1d3c0.6b18","name":"","server":"2c3f285.7dce7d8","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.luftung_bad","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1170,"y":740,"wires":[[]]},{"id":"ab666945.3b5c68","type":"time-range-switch","z":"e3e1d3c0.6b18","name":"","lat":"50.93333","lon":"6.95","startTime":"sunriseEnd","endTime":"00:00","startOffset":0,"endOffset":0,"x":350,"y":660,"wires":[["4457999e.bcd758","8be66078.37f18"],[]]},{"id":"133b3eb2.6309c1","type":"debug","z":"e3e1d3c0.6b18","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1230,"y":560,"wires":[]},{"id":"e85a6f2.8c2919","type":"poll-state","z":"e3e1d3c0.6b18","name":"","server":"2c3f285.7dce7d8","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"updateinterval":"60","updateIntervalUnits":"seconds","outputinitially":false,"outputonchanged":false,"entity_id":"sensor.lywsd03mmc_humidity_kleines_bad","state_type":"str","halt_if":"80","halt_if_type":"num","halt_if_compare":"gt","outputs":2,"x":300,"y":760,"wires":[["3bda4ff1.27158","e6b66866.3640b8"],[]]},{"id":"5d701db5.14fd14","type":"function","z":"e3e1d3c0.6b18","name":"","func":"if (msg.payload1 === \"true\" && msg.payload2 == \"true\") {\n msg.payload = true;\n}\n\nelse {\n msg.payload = false;\n}\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":800,"y":700,"wires":[["16eb6d5b.5513e3","64541d80.bccbe4"]]},{"id":"dc66e6f5.42a418","type":"comment","z":"e3e1d3c0.6b18","name":"Multiple Inputs / Conditions","info":"You can have multiple inputs into a function node BUT each one will run separately. If you need data fron the other one, you will need to join them together before sending to the function node.","x":320,"y":580,"wires":[]},{"id":"e6b66866.3640b8","type":"change","z":"e3e1d3c0.6b18","name":"","rules":[{"t":"set","p":"payload2","pt":"msg","to":"true","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":720,"wires":[["5d701db5.14fd14","799c678c.1257a8"]]},{"id":"8be66078.37f18","type":"change","z":"e3e1d3c0.6b18","name":"","rules":[{"t":"set","p":"payload1","pt":"msg","to":"true","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":660,"wires":[["5d701db5.14fd14","91d0e013.26e44"]]},{"id":"16eb6d5b.5513e3","type":"debug","z":"e3e1d3c0.6b18","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":850,"y":640,"wires":[]},{"id":"91d0e013.26e44","type":"debug","z":"e3e1d3c0.6b18","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload1","targetType":"msg","statusVal":"","statusType":"auto","x":660,"y":620,"wires":[]},{"id":"799c678c.1257a8","type":"debug","z":"e3e1d3c0.6b18","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload2","targetType":"msg","statusVal":"","statusType":"auto","x":660,"y":760,"wires":[]},{"id":"64541d80.bccbe4","type":"switch","z":"e3e1d3c0.6b18","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"true","vt":"str"},{"t":"eq","v":"false","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":960,"y":720,"wires":[["e0e6509a.a4a18"],[]]},{"id":"2c532f67.0330e","type":"trigger","z":"e3e1d3c0.6b18","name":"","op1":"reset","op2":"true","op1type":"str","op2type":"bool","duration":"2","extend":true,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":500,"y":860,"wires":[["e4e42b96.97a338"]]},{"id":"e4e42b96.97a338","type":"trigger","z":"e3e1d3c0.6b18","name":"","op1":"0","op2":"0","op1type":"str","op2type":"str","duration":"-2","extend":false,"overrideDelay":false,"units":"s","reset":"reset","bytopic":"all","topic":"topic","outputs":1,"x":660,"y":860,"wires":[["83e47b7.c234188"]]},{"id":"3bda4ff1.27158","type":"debug","z":"e3e1d3c0.6b18","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":370,"y":980,"wires":[]},{"id":"83e47b7.c234188","type":"debug","z":"e3e1d3c0.6b18","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":890,"y":860,"wires":[]},{"id":"2c3f285.7dce7d8","type":"server","name":"Home-Assistant","legacy":false,"addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]
Edit: Picture attached that not everyone needs to import the code.
Edit2: Here is the function:
if (msg.payload1 === "true" && msg.payload2 == "true") {
msg.payload = true;
}
else {
msg.payload = false;
}
return msg;