Debug Function Node

Hi all, I made a function for bathroom ventilation to compare humidity measurements and output a boolean depending on the results. I’m attempting to add 5% on the sensor.home_humidity value to give a little wiggle room for the vent fan activation. However, it’s always sending “true” in debug. What did I miss?

if ("sensor.lumi_lumi_weather_336f0807_humdity" > (5 + "sensor.home_humidity")) {msg.payload = true; }else{ msg.payload=false; } return msg;

Thanks!

Are you sure you want " around the sensor values?

No quotes gives me this error:
ReferenceError: sensor is not defined (line 1, col 1)

well, you did not post the entire flow, so its hard to know if you somehow gathered the sensor values.
Personally I would use a current state node on each sensor and save that in a msg.something values.

Good point. I was only have issues with the function node. Here’s the whole flow:

[{"id":"adf9dab36c06d7fb","type":"tab","label":"Master Bath Vent Fan - V2","disabled":false,"info":"","env":[]},{"id":"32c50907.2cde1e","type":"stoptimer","z":"adf9dab36c06d7fb","duration":"5","units":"Minute","payloadtype":"num","payloadval":"0","name":"Wait 5 Minutes","x":1340,"y":220,"wires":[["cdfbf50a.3eecc8"],[]]},{"id":"cdfbf50a.3eecc8","type":"api-current-state","z":"adf9dab36c06d7fb","name":"High Humidity?","server":"1952aa83.c9e0e5","version":2,"outputs":2,"halt_if":"sensor.home_humidity","halt_if_type":"entity","halt_if_compare":"gt","entity_id":"sensor.lumi_lumi_weather_336f0807_humidity","state_type":"num","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"true","valueType":"bool"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"x":1000,"y":340,"wires":[["7e082343.a7f13c"],["c5c47556.bb3f8"]]},{"id":"c5c47556.bb3f8","type":"api-call-service","z":"adf9dab36c06d7fb","name":"Turn off fan","server":"1952aa83.c9e0e5","version":3,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.main_vent_fan_9cf395fe_on_off","data":"","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1330,"y":340,"wires":[[]]},{"id":"7e082343.a7f13c","type":"stoptimer","z":"adf9dab36c06d7fb","duration":"1","units":"Minute","payloadtype":"num","payloadval":"0","name":"Wait 1 min","x":1330,"y":280,"wires":[["cdfbf50a.3eecc8"],[]]},{"id":"595cf5bf.3e5e34","type":"api-call-service","z":"adf9dab36c06d7fb","name":"Turn on fan","server":"1952aa83.c9e0e5","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.bathroom_vent_fan_on_off","data":"","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1030,"y":220,"wires":[["32c50907.2cde1e"]]},{"id":"29de0b58a85d3aa0","type":"inject","z":"adf9dab36c06d7fb","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"44","payloadType":"num","x":760,"y":120,"wires":[["595cf5bf.3e5e34"]]},{"id":"e71797bfe2050169","type":"function","z":"adf9dab36c06d7fb","name":"","func":"if (\"sensor.lumi_lumi_weather_336f0807_humdity\" > (5 + \"sensor.home_humidity\"))\n {msg.payload = true;\n}else{\n msg.payload=false;\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":640,"y":260,"wires":[["eb51ee5cd5fa77ad","595cf5bf.3e5e34"]]},{"id":"28f50d4e5d6daeb7","type":"poll-state","z":"adf9dab36c06d7fb","name":"","server":"1952aa83.c9e0e5","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"updateinterval":"60","updateIntervalUnits":"seconds","outputinitially":true,"outputonchanged":true,"entity_id":"sensor.lumi_lumi_weather_336f0807_humidity","state_type":"num","halt_if":"0","halt_if_type":"num","halt_if_compare":"gte","outputs":2,"x":210,"y":180,"wires":[["e71797bfe2050169"],[]]},{"id":"82340667d3e18d56","type":"poll-state","z":"adf9dab36c06d7fb","name":"","server":"1952aa83.c9e0e5","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"updateinterval":"60","updateIntervalUnits":"seconds","outputinitially":true,"outputonchanged":true,"entity_id":"sensor.home_humidity","state_type":"num","halt_if":"0","halt_if_type":"num","halt_if_compare":"gte","outputs":2,"x":190,"y":240,"wires":[["e71797bfe2050169"],[]]},{"id":"eb51ee5cd5fa77ad","type":"debug","z":"adf9dab36c06d7fb","name":"vent function output","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":1000,"y":480,"wires":[]},{"id":"1952aa83.c9e0e5","type":"server","name":"Home Assistant","version":1,"legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open|1","connectionDelay":true,"cacheJson":true}]

Ok, you have a bit wrong concept of how a flow works.
If you have two or more connections OUT of a node, then nodes connected to these will get data from the node at the same time, but two or more connections IN to a node will not arrive at the same time. It will be multiple different versions of the flow.

In your example here you will have a flow for when sensor.home_humidity is updated and another for sensor.lumi_lumi_weather_336f0807_humidity. Whenever one sensor is starting a flow the other sensor will be missing and you poll state node will send the sensor state in a msg. variable in the flow, not store it in a sensor. variable.

Try this instead and see what the output is to get the values you need.
[{"id":"e0ed17fb2db8f989","type":"inject","z":"adf9dab36c06d7fb","name":"Trigger each 60 seconds (5 seconds after startup. Might adjust to make sure the sensors are ready)","props":[{"p":"payload"}],"repeat":"60","crontab":"","once":true,"onceDelay":"5","topic":"","payload":"","payloadType":"date","x":395,"y":600,"wires":[["7a4f8151beee1ad9"]]},{"id":"7a4f8151beee1ad9","type":"api-current-state","z":"adf9dab36c06d7fb","name":"","server":"541ade28.b4a62","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.lumi_lumi_weather_336f0807_humidity","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"weather_state","propertyType":"msg","value":"","valueType":"entityState"},{"property":"weather_data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":995,"y":600,"wires":[["bb5d61d61f25d61c"]]},{"id":"bb5d61d61f25d61c","type":"api-current-state","z":"adf9dab36c06d7fb","name":"","server":"541ade28.b4a62","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.home_humidity","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"home_humidity_state","propertyType":"msg","value":"","valueType":"entityState"},{"property":"home_humidity_data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1395,"y":600,"wires":[["333e0d0967827b2c"]]},{"id":"333e0d0967827b2c","type":"debug","z":"adf9dab36c06d7fb","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1625,"y":600,"wires":[]},{"id":"541ade28.b4a62","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"","connectionDelay":false,"cacheJson":false,"heartbeat":false,"heartbeatInterval":""}]