MQTT Node-Red Smartplug - Easy (?)

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
martinus
Normal user
Posts: 129
Joined: 15 Feb 2020, 16:57

MQTT Node-Red Smartplug - Easy (?)

#1 Post by martinus » 14 Apr 2020, 17:42

Tried to figure out the easy way to control a smartplug using MQTT and local pushbutton control with feedback to node-red, without using any rules and just two simple to understand topics:

Code: Select all

TestUnit/SmartPlug/Set
TestUnit/SmartPlug/State
So instead of using existing options like /sysname/GPIO/<pin> or /sysname/CMD with the entire command GPIO <pin>,<value> as payload, i decided to add a small feature to the C005 MQTT plugin so that it matches incoming topics with the list of active tasks by name, conforming to <sysname>/<taskname> structure that's also used for publishing the state. This way, the payload for set/state is equal (1/0) and Node-Red understands this without any additional tweaking.

And created a new dedicated SmartPlug plugin that combines the Relay/Led/Pushbutton to make things more easy.

The plugin needed to configure the pins to use on the smartplug:
SmartPlug.png
SmartPlug.png (15.32 KiB) Viewed 4609 times

Simple Node Red flow for the dashboard:
NodeRedFlow.png
NodeRedFlow.png (11.1 KiB) Viewed 4609 times

Simple lean and mean dashboard:
NodeRedDashboard.png
NodeRedDashboard.png (8.94 KiB) Viewed 4609 times

The button on the dashboard uses the feedback, so it only flips when it has received the actual state back from the ESP.
And using the local button flips the switch on Node-red as well.
When the local button is used, it will control the relay/led locally, so it will still work when the network is down.

I'm used to Domoticz (HTTP controller) only, so most of this stuff (MQTT, Node-Red) is fairly new to me.
Maybe this approach is even more than required, so pls guide me if it can be improved.

happytm
Normal user
Posts: 107
Joined: 15 Aug 2016, 17:53

Re: MQTT Node-Red Smartplug - Easy (?)

#2 Post by happytm » 15 Apr 2020, 21:30

I learned a lot watching these node-red detailed examples videos at https://www.youtube.com/watch?v=mW9LKlm ... MzlweP9FdQ

He used to be active on ESPEasy forum.All his ready to use node-red flows are at https://flows.nodered.org/user/nygma2004

Thanks.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 138 guests