# Multiple inputs with external conditions from Home-Assistant

**URL:** <https://discourse.nodered.org/t/multiple-inputs-with-external-conditions-from-home-assistant/35312>\
**Category:** Developing Nodes\
**Created:** [4 November 2020 08:42 UTC](https://discourse.nodered.org/t/multiple-inputs-with-external-conditions-from-home-assistant/35312 "2020-11-04T08:42:30Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![noobred](https://avatars.discourse-cdn.com/v4/letter/n/aeb1de/32.png) [@noobred](https://discourse.nodered.org/u/noobred)\
**Post date:** [4 November 2020 08:42 UTC](https://discourse.nodered.org/t/multiple-inputs-with-external-conditions-from-home-assistant/35312/1 "2020-11-04T08:42:31Z")

</div>

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:

```auto
[{"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.

 ![Bildschirmfoto 2020-11-04 um 09.42.49](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/2/623fe17f10f054a3c76887a7d3f41d6616e82632.png)

Edit2: Here is the function:

```auto
if (msg.payload1 === "true" && msg.payload2 == "true") {
    msg.payload = true;
}

else {
    msg.payload = false;
}

return msg;

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [4 November 2020 08:56 UTC](https://discourse.nodered.org/t/multiple-inputs-with-external-conditions-from-home-assistant/35312/2 "2020-11-04T08:56:51Z")

</div>

Hi, @noobred, welcome to the fourm.

The first concept you need to understand in node-red (or any computer language) is that messages do NOT arrive at the same time.

See [this article in the cookbook](https://cookbook.nodered.org/basic/join-streams) for an example of how to join messages into one object.

---

<div class="post-metadata">

**Author:** ![noobred](https://avatars.discourse-cdn.com/v4/letter/n/aeb1de/32.png) [@noobred](https://discourse.nodered.org/u/noobred)\
**Post date:** [4 November 2020 09:18 UTC](https://discourse.nodered.org/t/multiple-inputs-with-external-conditions-from-home-assistant/35312/3 "2020-11-04T09:18:30Z")

</div>

thank you very much ! Sorry that I forgot to mention that I had this considered yesterday. I went through the cookbook but eventually failed. Added this pattern now with the following code:

- set per node a custom message.topic
- join them together into one key/value object
- using the function to apply IF/ELSE logic

Am i doing it right?

 ![Bildschirmfoto 2020-11-04 um 10.14.58](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/8/38e78c75b9716f232a83e9e2c9ac1a25e81efe0e.png)

```auto
[{"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":110,"y":640,"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":650,"y":540,"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":930,"y":540,"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":1190,"y":800,"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":290,"y":640,"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":1170,"y":540,"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":"minutes","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":240,"y":740,"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":940,"y":660,"wires":[["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"},{"t":"set","p":"topic","pt":"msg","to":"shroom_humidity","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":700,"wires":[["799c678c.1257a8","4aee80b.97c9f8"]]},{"id":"8be66078.37f18","type":"change","z":"e3e1d3c0.6b18","name":"","rules":[{"t":"set","p":"payload1","pt":"msg","to":"true","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"interval","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":640,"wires":[["91d0e013.26e44","4aee80b.97c9f8"]]},{"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":600,"y":600,"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":600,"y":740,"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":970,"y":760,"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":310,"y":960,"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":"4aee80b.97c9f8","type":"join","z":"e3e1d3c0.6b18","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":"","reduceFixup":"","x":750,"y":660,"wires":[["5d701db5.14fd14","9497e70e.e5d758"]]},{"id":"9497e70e.e5d758","type":"debug","z":"e3e1d3c0.6b18","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":850,"y":600,"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}]

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [4 November 2020 09:29 UTC](https://discourse.nodered.org/t/multiple-inputs-with-external-conditions-from-home-assistant/35312/4 "2020-11-04T09:29:08Z")

</div>

> [@noobred](#):
>
> Am i doing it right?

I dont think so.

In your function you try to access `msg.payload1` and `msg.payload2` but I that is not what will be coming out of the `join` node.

Have a look at the debug message coming out of the `join` node.

Then read this page in the docs that will explain how to use the debug panel to find the right path to any data item.

[https://nodered.org/docs/user-guide/messages](https://nodered.org/docs/user-guide/messages)

---

<div class="post-metadata">

**Author:** ![noobred](https://avatars.discourse-cdn.com/v4/letter/n/aeb1de/32.png) [@noobred](https://discourse.nodered.org/u/noobred)\
**Post date:** [4 November 2020 10:02 UTC](https://discourse.nodered.org/t/multiple-inputs-with-external-conditions-from-home-assistant/35312/5 "2020-11-04T10:02:40Z")

</div>

> [@Steve-Mcl](#):
>
> Then read this page in the docs that will explain how to use the debug panel to find the right path to any data item.

Thanks Steve! That helped very much. Now I can address specific elements in a payload. That is really cool. I think it works now technically. However the switch turns on regardless of my injection node interval (1hour). In example I set the update interval of the humidity to 2seconds but the interval should fire only once an hour. The switch should not be turned ON. How can I solve this problem?

Thank you very much !

 ![Bildschirmfoto 2020-11-04 um 10.59.40](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/5/05077386d8c5f2a4d3e27b27d7d7fc1411368f25.png)

```auto
[{"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":110,"y":534,"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":650,"y":434,"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":930,"y":434,"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":1290,"y":540,"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":290,"y":534,"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":1170,"y":434,"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":"2","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":240,"y":634,"wires":[["e6b66866.3640b8"],[]]},{"id":"5d701db5.14fd14","type":"function","z":"e3e1d3c0.6b18","name":"","func":"if (msg.payload.interval === \"true\" && msg.payload.shroom_humidity == \"true\") {\n msg.payload = true;\n}\n\nelse {\n msg.payload = false;\n}\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":940,"y":540,"wires":[["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":474,"wires":[]},{"id":"e6b66866.3640b8","type":"change","z":"e3e1d3c0.6b18","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"shroom_humidity","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":620,"wires":[["4aee80b.97c9f8"]]},{"id":"8be66078.37f18","type":"change","z":"e3e1d3c0.6b18","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"interval","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":520,"wires":[["4aee80b.97c9f8"]]},{"id":"64541d80.bccbe4","type":"switch","z":"e3e1d3c0.6b18","name":"","property":"payload","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":1090,"y":540,"wires":[["e0e6509a.a4a18","909abdf6.78efa"],[]]},{"id":"4aee80b.97c9f8","type":"join","z":"e3e1d3c0.6b18","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":"","reduceFixup":"","x":750,"y":554,"wires":[["9497e70e.e5d758","5d701db5.14fd14"]]},{"id":"9497e70e.e5d758","type":"debug","z":"e3e1d3c0.6b18","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":850,"y":494,"wires":[]},{"id":"909abdf6.78efa","type":"debug","z":"e3e1d3c0.6b18","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1270,"y":494,"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}]

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [4 November 2020 10:15 UTC](https://discourse.nodered.org/t/multiple-inputs-with-external-conditions-from-home-assistant/35312/6 "2020-11-04T10:15:31Z")

</div>

Sorry, I dont know HA

however, in your function code, you test for payload to be both == "true" **and** === "true" (i.e. would fail on a boolean true as `true !== "true"`)

I would probably do ...

```auto
var i = msg.payload.interval == true || msg.payload.interval == "true";
var h = msg.payload.shroom_humidity == true || msg.payload.shroom_humidity == "true";
msg.payload = (i && h);
return msg;

```

also, the switch node - the 2nd condition should really be "otherwise" (as a catch all)

But the answer to why - you will need to inspect the values in the debug coming out of the join node to figure out the reason.

---

<div class="post-metadata">

**Author:** ![noobred](https://avatars.discourse-cdn.com/v4/letter/n/aeb1de/32.png) [@noobred](https://discourse.nodered.org/u/noobred)\
**Post date:** [4 November 2020 10:23 UTC](https://discourse.nodered.org/t/multiple-inputs-with-external-conditions-from-home-assistant/35312/7 "2020-11-04T10:23:44Z")

</div>

thank you very much Steve! I will try it out and come back to document the solution here - at least to challenge it ;9

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [4 November 2020 10:26 UTC](https://discourse.nodered.org/t/multiple-inputs-with-external-conditions-from-home-assistant/35312/8 "2020-11-04T10:26:09Z")

</div>

I updated the function code (I misunderstood) your intent - i think its right now...

> [@Steve-Mcl](#):
>
> ```auto
> var i = msg.payload.interval == true || msg.payload.interval == "true";
> var h = msg.payload.shroom_humidity == true || msg.payload.shroom_humidity == "true";
> msg.payload = (i && h);
> return msg;
> 
> ```

---

<div class="post-metadata">

**Author:** ![noobred](https://avatars.discourse-cdn.com/v4/letter/n/aeb1de/32.png) [@noobred](https://discourse.nodered.org/u/noobred)\
**Post date:** [4 November 2020 14:05 UTC](https://discourse.nodered.org/t/multiple-inputs-with-external-conditions-from-home-assistant/35312/9 "2020-11-04T14:05:43Z")

</div>

> [@Steve-Mcl](#):
>
> ```auto
> var i = msg.payload.interval == true || msg.payload.interval == "true";
> var h = msg.payload.shroom_humidity == true || msg.payload.shroom_humidity == "true";
> msg.payload = (i && h);
> return msg;
> 
> ```

yeah!i think it is working now. with your code it looks professionally coded and copes also with my inability declaring boolean vs. string "true" - thanks for that. To help others I paste the code here:

```auto
[{"id":"aec813ed.ae5","type":"inject","z":"e3e1d3c0.6b18","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"7200","crontab":"","once":true,"onceDelay":"","topic":"","payload":"","payloadType":"date","x":110,"y":534,"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":650,"y":434,"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":930,"y":434,"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":1290,"y":540,"wires":[["fdb5db07.7c6488"]]},{"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":290,"y":534,"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":1170,"y":434,"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":"15","updateIntervalUnits":"minutes","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":240,"y":634,"wires":[["e6b66866.3640b8"],[]]},{"id":"5d701db5.14fd14","type":"function","z":"e3e1d3c0.6b18","name":"","func":"var i = msg.payload.interval == true || msg.payload.interval == \"true\";\nvar h = msg.payload.shroom_humidity == true || msg.payload.shroom_humidity == \"true\";\nmsg.payload = (i && h);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":920,"y":540,"wires":[["64541d80.bccbe4","be16c70.f61f938"]]},{"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":474,"wires":[]},{"id":"e6b66866.3640b8","type":"change","z":"e3e1d3c0.6b18","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"shroom_humidity","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":620,"wires":[["4aee80b.97c9f8"]]},{"id":"8be66078.37f18","type":"change","z":"e3e1d3c0.6b18","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"interval","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":520,"wires":[["4aee80b.97c9f8"]]},{"id":"64541d80.bccbe4","type":"switch","z":"e3e1d3c0.6b18","name":"","property":"payload","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":1090,"y":540,"wires":[["e0e6509a.a4a18","909abdf6.78efa"],[]]},{"id":"4aee80b.97c9f8","type":"join","z":"e3e1d3c0.6b18","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":"","reduceFixup":"","x":750,"y":554,"wires":[["9497e70e.e5d758","5d701db5.14fd14"]]},{"id":"9497e70e.e5d758","type":"debug","z":"e3e1d3c0.6b18","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":850,"y":494,"wires":[]},{"id":"909abdf6.78efa","type":"debug","z":"e3e1d3c0.6b18","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1270,"y":494,"wires":[]},{"id":"fdb5db07.7c6488","type":"change","z":"e3e1d3c0.6b18","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"false","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"interval","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1480,"y":540,"wires":[[]]},{"id":"be16c70.f61f938","type":"debug","z":"e3e1d3c0.6b18","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1110,"y":600,"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}]

```

thanks again !

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [3 January 2021 14:05 UTC](https://discourse.nodered.org/t/multiple-inputs-with-external-conditions-from-home-assistant/35312/10 "2021-01-03T14:05:46Z")

</div>

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