Enhancing Power State Monitoring with Sonoff Switches and Node-Red

I’ve been working on improving the power state monitoring for my Sonoff switches integrated with Home Assistant. After noticing that the power states weren’t updating correctly after a restart, I decided to dive into a solution using Node-Red. Here’s how I tackled the issue and the results I achieved.After some research, I realized that while Sonoff switches send telemetry data via MQTT, Home Assistant doesn’t automatically update the power states from these messages. This meant that after a restart, all switches were marked as ‘off’ until manually toggled—a frustrating issue.I decided to leverage Node-Red for a custom solution. By reformatting the MQTT telemetry messages, I could ensure that the power states are updated in real-time. This approach not only keeps the power states accurate but also eliminates the need for an external MQTT broker like Mosquitto, simplifying my setup.Here’s a quick overview of the Node-Red flow I implemented:1. MQTT Input Node: Subscribes to all MQTT messages.2. Function Node: Filters and reformats telemetry messages to extract power states.3. Switch Node: Ensures only reformatted messages are processed.4. MQTT Output Node: Publishes the reformatted messages to update Home Assistant.This setup has been a game-changer. Within minutes of a restart, all power states are correctly reflected, and I no longer have to deal with retained messages causing issues.If you’re facing similar challenges, I encourage you to try this approach. It’s a great example of how Node-Red can bridge gaps in smart home integrations. Let me know if you have any questions or need further clarification!