Setting a variable to a string?

So I have a flow where I want to notify the Mrs and I if a temperature sensor goes outside of its range.

That part is working great, but what I’d like to do is set a variable when the initial notification goes out to say a 1, then once we’re back in range I’ll reset the variable to 0. Problem is right now I’m below the range on the sensor and everytime the sensor checks in I get another notification and I don’t want this to get to the point of the boy who cried wolf

So I’m new to java script and I’m trying to pick this up but I’m just not sure I’m doing it right.

So I want for too cold to be called coldnotification then I’ll do up another one after I get this working for hot

if (coldnotification === 1 ){
    exit;
} else {
    return [ coldnotication, null];
}

I figured if it returns null that it’ll just keep pushing on through the flow and then get to the set bit

var coldnotification = 1
return coldnotification;

Should I declare the var in the first part and then just refer to it in the 2nd?

I’ve written a good bit of my automations in appdaemon and I love appdaemon but I tend to like using NR for things that are simpler and won’t look super complex in a flow chart.

If I understood you correctly these are some examples that should help you. The third example uses node-red-contrib-throttle. Also returning null in a function node stops the flows.

[{"id":"bebcf877.bbab18","type":"server-state-changed","z":"5eb3594f.d294b8","name":"Sensor","server":"ef067c6f.620e6","entityidfilter":"sensor.sensor","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"x":114,"y":1936,"wires":[["27fa6116.c414de"]]},{"id":"1d94a1e8.c558de","type":"debug","z":"5eb3594f.d294b8","name":"Notify People","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":742,"y":1968,"wires":[]},{"id":"27fa6116.c414de","type":"switch","z":"5eb3594f.d294b8","name":"In Range?","property":"payload","propertyType":"msg","rules":[{"t":"btwn","v":"50","vt":"num","v2":"75","v2t":"num"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":262,"y":1936,"wires":[["458ca65f.ce00d8"],["378c1d7b.991e32"]]},{"id":"458ca65f.ce00d8","type":"change","z":"5eb3594f.d294b8","name":"Reset Throttle","rules":[{"t":"set","p":"notifyThrottled","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":448,"y":1920,"wires":[[]]},{"id":"378c1d7b.991e32","type":"switch","z":"5eb3594f.d294b8","name":"Throttled?","property":"notifyThrottled","propertyType":"flow","rules":[{"t":"false"}],"checkall":"true","repair":false,"outputs":1,"x":428,"y":1968,"wires":[["2c5e930c.69cfac"]]},{"id":"2c5e930c.69cfac","type":"change","z":"5eb3594f.d294b8","name":"Set Throttled","rules":[{"t":"set","p":"notifyThrottled","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":582,"y":1968,"wires":[["1d94a1e8.c558de"]]}]

[{"id":"e40b0977.a4a4e8","type":"server-state-changed","z":"5eb3594f.d294b8","name":"Sensor","server":"ef067c6f.620e6","entityidfilter":"sensor.sensor","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"x":130,"y":2048,"wires":[["bd29dc40.0a9de"]]},{"id":"b12cf332.1ec1b","type":"debug","z":"5eb3594f.d294b8","name":"Notify People","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":406,"y":2048,"wires":[]},{"id":"bd29dc40.0a9de","type":"function","z":"5eb3594f.d294b8","name":"logic","func":"const throttled = context.get('throttled') || false;\nif (msg.payload > 50 && msg.payload < 75) {\n    context.set('allow', false);\n    return null;\n}\n\nif (throttled) return null;\n\ncontext.set('throttled', true);\n\nreturn msg;","outputs":1,"noerr":0,"x":258,"y":2048,"wires":[["b12cf332.1ec1b"]]}]

[{"id":"a32dcae7.adb568","type":"server-state-changed","z":"5eb3594f.d294b8","name":"Sensor","server":"ef067c6f.620e6","entityidfilter":"sensor.sensor","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"x":114,"y":2160,"wires":[["cd1189e4.a85718"]]},{"id":"dcaba920.bf92d8","type":"debug","z":"5eb3594f.d294b8","name":"Notify People","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":710,"y":2160,"wires":[]},{"id":"e3808b38.2a2d88","type":"throttle","z":"5eb3594f.d294b8","name":"","throttleType":"reset","timeLimit":0,"timeLimitType":"seconds","countLimit":0,"blockSize":0,"locked":true,"x":562,"y":2160,"wires":[["dcaba920.bf92d8"]]},{"id":"cd1189e4.a85718","type":"switch","z":"5eb3594f.d294b8","name":"In Range?","property":"payload","propertyType":"msg","rules":[{"t":"btwn","v":"50","vt":"num","v2":"75","v2t":"num"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":262,"y":2160,"wires":[["a78ed7db.0697e8"],["e3808b38.2a2d88"]]},{"id":"a78ed7db.0697e8","type":"change","z":"5eb3594f.d294b8","name":"reset","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":418,"y":2112,"wires":[["e3808b38.2a2d88"]]}]

Kermit you are awesome. Thank you so much. I’m going to take a look at these flows greatly appreciated.