How do I tell a flow to ignore the next msg.payload received after msg.payload=unavailable?

So basically what I have is a Shelly Dimmer 2 relay set up in detached mode controlling 3 zigbee lights. At night my son uses one of those lights as a night light however the Shelly will sometimes go "unavailable" for a split second and then resend the the state of the the light switch it's wired to. So at night the light switch is in the 'OFF' position but one of the zigbee lights is on, the Shelly would go unavailable and would send a msg.payload = unavailable, at this point nothing has happened to the light yet, immediately after the Shelly goes unavailable it comes back and sends an 'OFF' command since that is the position of the switch and turns the nightlight off. The end result is a panicked toddler calling out in the middle of the night when he notices his light is off.

What I'm looking for is a way to ignore the next msg.payload if a mag.payload=unavailable is received but haven't been able to figure it out. Is there a node that could perform this for me?

Welcome to the forum @SpaceCadetRick

I can't think of an easy way to do that using basic nodes. I would probably do it using a function node which remembers the previous value and ignores the next one when appropriate.

In my opinion you can always implement a flow - instead of using function nodes. For sure I can implement complete flows in a function node - but then the advantage to use node red as graphical programming tool will be obsolete.

So in this case - always a context is needed to remember the last value. So I can use a flow variable in the flow context as well as a node context in a function node.

If I would implement this as a flow - it would look like this:

[{"id":"da54c086cebdd0ef","type":"switch","z":"4fd2253740654c8a","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"unavailable","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":630,"y":260,"wires":[["0fefc1c4f30d5ff7"],["0153ab52ee7f2f03"]]},{"id":"1d90f0ab2374ed50","type":"inject","z":"4fd2253740654c8a","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"unavailable","payloadType":"str","x":450,"y":200,"wires":[["da54c086cebdd0ef"]]},{"id":"0fefc1c4f30d5ff7","type":"change","z":"4fd2253740654c8a","name":"","rules":[{"t":"set","p":"block","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":810,"y":220,"wires":[[]]},{"id":"0153ab52ee7f2f03","type":"switch","z":"4fd2253740654c8a","name":"","property":"block","propertyType":"flow","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":780,"y":300,"wires":[["75bfeae5d3125472"],["e23818ec8b7b8903"]]},{"id":"e23818ec8b7b8903","type":"debug","z":"4fd2253740654c8a","name":"continue","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":950,"y":340,"wires":[]},{"id":"b3f291f324da2da1","type":"inject","z":"4fd2253740654c8a","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"dosomething","payloadType":"str","x":450,"y":260,"wires":[["da54c086cebdd0ef"]]},{"id":"75bfeae5d3125472","type":"change","z":"4fd2253740654c8a","name":"","rules":[{"t":"set","p":"block","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":960,"y":280,"wires":[[]]},{"id":"63b99699a18e4708","type":"inject","z":"4fd2253740654c8a","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":450,"y":120,"wires":[["343bca61ec66ec2d"]]},{"id":"343bca61ec66ec2d","type":"change","z":"4fd2253740654c8a","name":"","rules":[{"t":"set","p":"block","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":120,"wires":[[]]}]

And if you like, then pack this flow in a subflow - so it can be used with one node for your different shellies

A simple store of incoming messages in a flow variable and a switch node should work to stop the following message after an unavailable payload.

[{"id":"53fc6dc.ec49f14","type":"inject","z":"c791cbc0.84f648","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"smoe other value","payloadType":"str","x":170,"y":1940,"wires":[["c3c368a4.9c7f78"]]},{"id":"a0958109.bf19d","type":"inject","z":"c791cbc0.84f648","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"unavailable","payloadType":"str","x":150,"y":1900,"wires":[["c3c368a4.9c7f78"]]},{"id":"c3c368a4.9c7f78","type":"change","z":"c791cbc0.84f648","name":"","rules":[{"t":"set","p":"check","pt":"flow","to":"[$flowContext(\"check\")[1],$$.payload]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":1900,"wires":[["9cb92086.8f489"]]},{"id":"9cb92086.8f489","type":"switch","z":"c791cbc0.84f648","name":"","property":"check[0]","propertyType":"flow","rules":[{"t":"neq","v":"unavailable","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":600,"y":1900,"wires":[["da13de5e.8621a"]]},{"id":"da13de5e.8621a","type":"debug","z":"c791cbc0.84f648","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":630,"y":2160,"wires":[]}]

Or same thing with out any JSONata expression

[{"id":"53fc6dc.ec49f14","type":"inject","z":"c791cbc0.84f648","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"smoe other value","payloadType":"str","x":170,"y":1940,"wires":[["c3c368a4.9c7f78"]]},{"id":"a0958109.bf19d","type":"inject","z":"c791cbc0.84f648","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"unavailable","payloadType":"str","x":150,"y":1900,"wires":[["c3c368a4.9c7f78"]]},{"id":"c3c368a4.9c7f78","type":"change","z":"c791cbc0.84f648","name":"","rules":[{"t":"set","p":"check[0]","pt":"flow","to":"check[1]","tot":"flow"},{"t":"set","p":"check[1]","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":1900,"wires":[["9cb92086.8f489"]]},{"id":"9cb92086.8f489","type":"switch","z":"c791cbc0.84f648","name":"","property":"check[0]","propertyType":"flow","rules":[{"t":"neq","v":"unavailable","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":600,"y":1900,"wires":[["da13de5e.8621a"]]},{"id":"da13de5e.8621a","type":"debug","z":"c791cbc0.84f648","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":630,"y":2160,"wires":[]}]

I like that (the second one). I hadn't thought of using a rolling buffer in a Change node. I will have to remember that design pattern. Good stuff.

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