Shelly relays how to handle update period in node red

Hi first post. I chose a dead mosquito cause I’m struggling with MQTT in Node-RED.

I’ve got a Shelly 1 that I’m using as an “input” only in detached mode to control a separate light. I’ve got MQTT enabled and unicast to HA on the Shelly 1 WebGUI.

My flow works, but I’ve got an issue where the Shelly 1 keeps sending a new MQTT In every 30 seconds. Is there a way to only have it send MQTT messages when the switch is flipped? I tried to turn off the keep alive 30s on the WebGUI of the Shelly but it says it can’t do 0sec (firmware 2021/07)

How do I manage this? I basically want the equivalent of a state change node from the HA palette but MQTT keeps blasting the state. The reason for me wanting to use MQTT directly in Node-RED as opposed to using the HA integration is response time. MQTT response time is super fast. Using a state change from the HA palette to drive the light from a service call is somewhat delayed but not bad.

This is my solution. Works but I feel like I’m missing something basic. Open to ideas.

it’s not keep alive. It’s mqtt_update_period feature which definitively can be set to zero. but it can be done using http api only

In addition I would verify your current approach, or mqtt topic you are reading with NR. Physical state of input is reported by 0 and 1 values. So to intercept pressing the button it’s enough to check current state against previous state.

BTW there is great NR node Button Events. it’s not in default installation but available to be added to palette. It allows to recognize single and multiple clicks, button holds etc from series of impulses

1 Like

Use an rbe node after the mqtt node. Rbe only lets the message pass when it changes. So it will send 0/1 once and won’t send again unless the value changes.

[{"id":"49b14779.7a9e58","type":"rbe","z":"7d105d71.cc18e4","name":"","func":"rbe","gap":"","start":"","inout":"out","septopics":true,"property":"payload","x":1800,"y":1300,"wires":[[]]}]
1 Like

Right on. That makes a lot more sense considering the keep alive is at 60sec. I was able to set it using “http:///settings?mqtt_update_period=0”. Are there any disadvantages to setting this to 0?

Agreed. It’s probably a good strategy to be able to handle repeat messages without triggering an event either way.

Thanks this works great. I did have to make a startup shellies/command update to feed the rbe the initial state to cover the first 30sec of startup.

Thanks for all the help guys. Love this forum already.

Would you be able to share this flow so I can try it out please? I dont quite have the knowledge to set this up yet.