Hey everyone, I just wanted to share my recent experience setting up an automation for my Sonoff SNZB-01 switch using Node-RED. I’m still pretty new to this, so I thought I’d walk through my process and hopefully help others who might be facing similar challenges.
First off, I wanted to control a lamp using the Sonoff SNZB-01 button, which is connected via a Sonoff ZBBridge flashed with Tasmota firmware. The button can produce three states based on how it’s pressed: single, double, or long press. My goal was to have each press type trigger a different action for the lamp.
Initially, I tried connecting directly to the MQTT broker using the MQTT in node. The data from the button was coming through fine, but I struggled with parsing the Power value from the JSON payload. I attempted using the Switch node with a JSONata filter and even the Template node, but neither worked as expected. It was a bit frustrating, but I knew I just needed to keep trying different approaches.
After some research and testing, I realized that using the JSON node to parse the payload was the key. Once I had the Power value extracted, I could use a Switch node to route the different press types to their respective actions. For example, a single press could turn the lamp on, a double press could toggle the brightness, and a long press could turn it off.
One thing I noticed was that the state of the lamp wasn’t resetting properly after each press. This meant that subsequent presses weren’t triggering the correct actions. To fix this, I added a Delay node to ensure the state was reset before the next action. It worked like a charm!
I also wanted to make sure the automation was user-friendly, so I set up a simple dashboard in Node-RED to display the current state of the lamp and the last press action. This way, I can easily monitor everything from my phone or computer.
Overall, this project was a great learning experience. It taught me the importance of properly parsing JSON data and the value of using delay nodes to ensure smooth automation. I’m now confident in tackling more complex projects in Node-RED. If anyone has questions or needs help with similar setups, feel free to reach out!
Happy automating! ![]()