Node-Red value change from low value to high(er) value

What is the best way to only trigger when a value is rising from a lower number to a higher number. Without risking “flapping” between single digits.

I have a sensor outputting between 0-100 and I want to trigger when above 95. But sometimes the sensor slowly flaps between 95/96 and that could cause false triggers.

I want to prevent that and only trigger once when value was coming from a value lower than 93 and going over 95.

But I do not get/know how to get than in my trigger state node. This does not work:

Am I using the correct node/approach?

EDIT: state type string or number no difference.

See if this will work for you.

[{"id":"b82809670d4c9cb4","type":"trigger-state","z":"0a325c35fc29f44e","name":">95","server":"","version":4,"inputs":1,"outputs":2,"exposeAsEntityConfig":"","entityIdType":"exact","debugEnabled":false,"constraints":[{"targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":""}],"customOutputs":[],"outputInitially":false,"stateType":"str","enableInput":true,"x":870,"y":7720,"wires":[["314ef966f6cf717c","a5fe6c47e256ab2b"],[]]},{"id":"314ef966f6cf717c","type":"change","z":"0a325c35fc29f44e","name":"disable","rules":[{"t":"set","p":"payload","pt":"msg","to":"disable","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1060,"y":7620,"wires":[["b82809670d4c9cb4"]]},{"id":"4490b835a73831ce","type":"server-state-changed","z":"0a325c35fc29f44e","name":">93 enable trigger","server":"","version":5,"outputs":2,"exposeAsEntityConfig":"","entityIdType":"exact","outputInitially":false,"stateType":"str","ifState":"93","ifStateType":"num","ifStateOperator":"gt","outputOnlyOnStateChange":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"enable","valueType":"str"}],"x":610,"y":7720,"wires":[["b82809670d4c9cb4"],[]]},{"id":"a5fe6c47e256ab2b","type":"debug","z":"0a325c35fc29f44e","name":"do @ >95","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1060,"y":7720,"wires":[]}]

Thank for replying. Your trigger node is empty… intentionally?

It was not intentional. Set the entity and the condition > 95

Seems to work, although it feels unnatural…

Thanks!

On second thought I don’t think this will not work with a number state. You can create a boolean that you would turn on above 95. Then shuts off only when below 93. Use that boolean in an event state for the trigger to the automation.

[{"id":"4490b835a73831ce","type":"server-state-changed","z":"0a325c35fc29f44e","name":"< 93 ","server":"6b1110b5.183a4","version":5,"outputs":2,"exposeAsEntityConfig":"","entityIdType":"exact","outputInitially":false,"stateType":"str","ifState":"93","ifStateType":"num","ifStateOperator":"gt","outputOnlyOnStateChange":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"off","valueType":"str"}],"x":590,"y":7700,"wires":[["74c21714f193be5b"],[]]},{"id":"cd4e4df13825192e","type":"server-state-changed","z":"0a325c35fc29f44e","name":"> 95 ","server":"6b1110b5.183a4","version":5,"outputs":2,"exposeAsEntityConfig":"","entityIdType":"exact","outputInitially":false,"stateType":"str","ifState":"95","ifStateType":"num","ifStateOperator":"gt","outputOnlyOnStateChange":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"on","valueType":"str"}],"x":590,"y":7640,"wires":[["74c21714f193be5b"],[]]},{"id":"74c21714f193be5b","type":"api-call-service","z":"0a325c35fc29f44e","name":"","server":"6b1110b5.183a4","version":5,"debugenabled":false,"domain":"input_boolean","service":"turn_{{payload}}","areaId":[],"deviceId":[],"entityId":["input_boolean.my_test_toggle"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":910,"y":7660,"wires":[[]]},{"id":"a92213decb61a810","type":"server-state-changed","z":"0a325c35fc29f44e","name":"","server":"6b1110b5.183a4","version":5,"outputs":1,"exposeAsEntityConfig":"","entityId":"input_boolean.my_test_toggle","entityIdType":"exact","outputInitially":false,"stateType":"str","ifState":"","ifStateType":"str","ifStateOperator":"is","outputOnlyOnStateChange":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":720,"y":7760,"wires":[["f8f483efbd186141"]]},{"id":"f8f483efbd186141","type":"debug","z":"0a325c35fc29f44e","name":"do something","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1120,"y":7760,"wires":[]},{"id":"6b1110b5.183a4","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"id","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

The previous works. Thats fine for now. If i habe time i’ll dig in deeper.

1 Like