Newbie Question - Storing entity value for comparison

Hi Everyone!,

Literally migrated my setup to Home Assistant and Node-Red this afternoon and trying to replicate an extractor fan setup I had with Smartthings and Webcore.

Basically, when the bathroom light turns on I would like to store the bathroom humidity level in a variable and turn the extractor on. When the humidity drops back to within 5% of the original humidity level I would like to leave the extractor running for 5 more mins before turning off.

I have taught myself the basics of flows this afternoon, but am struggling to work out how to capture and store the initial humidity level in a Flow of Global variable. I assume I would also need an if statement in a function block to compare the current humidity against the initial humidity?

Some pointers here would be much appreciated. I am only just starting my Home Assistant journey but already it kicks ars3 out of Smartthings!!

Many thanks!

https://nodered.org/docs/user-guide/context

See how this works for you

[{"id":"076712da66f4087e","type":"server-state-changed","z":"f80b6c338afd5483","name":"set bathroom light to entity, set humidity sensor in output","server":"","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"light.light","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"hum_var","propertyType":"flow","value":"$number($entities(\"sensor.humidity\").state) * 1.05","valueType":"jsonata"}],"x":340,"y":1380,"wires":[["5702673323f5376a"],[]]},{"id":"5702673323f5376a","type":"api-call-service","z":"f80b6c338afd5483","name":"turn on fan","server":"","version":3,"debugenabled":false,"service_domain":"","service":"","entityId":"","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":670,"y":1380,"wires":[["09a3c001e642889b"]]},{"id":"9d8737c6c9fcdfd6","type":"delay","z":"f80b6c338afd5483","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":920,"y":1300,"wires":[["09a3c001e642889b"]]},{"id":"09a3c001e642889b","type":"api-current-state","z":"f80b6c338afd5483","name":"","server":"","version":3,"outputs":2,"halt_if":"$number($entity()) < flow.hum_var","halt_if_type":"jsonata","halt_if_compare":"is","entity_id":"sensor.humidity","state_type":"num","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"5","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":930,"y":1380,"wires":[["f9c4d631c13fc7f6"],["9d8737c6c9fcdfd6"]]},{"id":"f9c4d631c13fc7f6","type":"api-call-service","z":"f80b6c338afd5483","name":"turn off fan","server":"","version":3,"debugenabled":false,"service_domain":"","service":"","entityId":"","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1210,"y":1380,"wires":[[]]}]

Great, thanks for this. Starting to make sense!

I have modified this to suit my devices but I am getting an error with the current state vs previous state check.

“Error: JSONata Error: Argument 1 of function “number” does not match function signature”

This is the function:
‘$number($entity()) < flow.hum_var’

Any ideas please?