How To Activate An Output w/MQTT & No Rules
Moderators: grovkillen, Stuntteam, TD-er
-
- Normal user
- Posts: 31
- Joined: 20 Oct 2017, 23:47
How To Activate An Output w/MQTT & No Rules
Can anyone give me some guidance on how to activate an output using MQTT without writing a rule?
I already have a broker running and can read inputs. Just can't figure out how to send a MQTT topic to turn on an output.
I already have a broker running and can read inputs. Just can't figure out how to send a MQTT topic to turn on an output.
- grovkillen
- Core team member
- Posts: 3621
- Joined: 19 Jan 2017, 12:56
- Location: Hudiksvall, Sweden
- Contact:
Re: How To Activate An Output w/MQTT & No Rules
What do you mean? Send commands back to the unit?
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you
-
- Normal user
- Posts: 31
- Joined: 20 Oct 2017, 23:47
Re: How To Activate An Output w/MQTT & No Rules
I have two ESP8266s with Mega and would like to be able to send it MQTT commands via Node Red to activate output pins to control relays.
A MQTT broker is installed on a RPi and I can receive MQTT topics like temp and switch closures coming from one 8266. However I can not figure out how to send MQTT commands to the second 8266 to activate outputs for a relay. I didn't use any rules to read temp, humidity and switch closures and it was pretty easy. But I'm struggling to do the same without rules to turn on a relay.
A MQTT broker is installed on a RPi and I can receive MQTT topics like temp and switch closures coming from one 8266. However I can not figure out how to send MQTT commands to the second 8266 to activate outputs for a relay. I didn't use any rules to read temp, humidity and switch closures and it was pretty easy. But I'm struggling to do the same without rules to turn on a relay.
- grovkillen
- Core team member
- Posts: 3621
- Joined: 19 Jan 2017, 12:56
- Location: Hudiksvall, Sweden
- Contact:
Re: How To Activate An Output w/MQTT & No Rules
Let's say you got your relay connected to GPIO 14 and the name of the unit is UnitName. Given that you use a MQTT controller on that unit you can trigger the relay like this:
Topic
Payload
And
Please observer that the subscription topic is set in the controller settings.
It's documented here:
https://espeasy.readthedocs.io/en/lates ... mmand.html
Topic
Code: Select all
UnitName/cmd
Code: Select all
GPIO,14,1
Code: Select all
GPIO,14,0
It's documented here:
https://espeasy.readthedocs.io/en/lates ... mmand.html
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you
-
- Normal user
- Posts: 31
- Joined: 20 Oct 2017, 23:47
Re: How To Activate An Output w/MQTT & No Rules
But how is the 8266 that will be controlling the relay configured? What kind of device type settings are used?
- grovkillen
- Core team member
- Posts: 3621
- Joined: 19 Jan 2017, 12:56
- Location: Hudiksvall, Sweden
- Contact:
Re: How To Activate An Output w/MQTT & No Rules
You don't need to configure a relay since it's only GPIO high/low. But if you want you can configure it as a switch.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you
-
- Normal user
- Posts: 31
- Joined: 20 Oct 2017, 23:47
Re: How To Activate An Output w/MQTT & No Rules
That's where I get confused. To me a switch is an input signal to the 8266. I have been using output since it is a signal coming out of the 8266 to the relay.
- grovkillen
- Core team member
- Posts: 3621
- Joined: 19 Jan 2017, 12:56
- Location: Hudiksvall, Sweden
- Contact:
Re: How To Activate An Output w/MQTT & No Rules
Yeah, I totally understand you. But think of it like this: a switch is essentially a manual relay OR a relay is essentially a switch.
Or just forget about that and think of it like this:
You can control a relay using the command GPIO. High to activate it and low to release it. But if you want to monitor that GPIO state you can use a task/device for it and here's where the switch plugin come in. It simply monitor the state of the GPIO, not really caring much if it set from the inside (using the GPIO command) or outside (closing a circuit with a button or whatever type of latch).
Conclusion, do you want to CONTROL a relay USE THE GPIO COMMAND. If you want to MONITOR a relay USE THE SWITCH PLUGIN.
PS. if you are okay with rules you can use variables and monitorgpio commands to monitor a GPIO without the need to use a plugin.
Or just forget about that and think of it like this:
You can control a relay using the command GPIO. High to activate it and low to release it. But if you want to monitor that GPIO state you can use a task/device for it and here's where the switch plugin come in. It simply monitor the state of the GPIO, not really caring much if it set from the inside (using the GPIO command) or outside (closing a circuit with a button or whatever type of latch).
Conclusion, do you want to CONTROL a relay USE THE GPIO COMMAND. If you want to MONITOR a relay USE THE SWITCH PLUGIN.
PS. if you are okay with rules you can use variables and monitorgpio commands to monitor a GPIO without the need to use a plugin.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you
-
- Normal user
- Posts: 31
- Joined: 20 Oct 2017, 23:47
Re: How To Activate An Output w/MQTT & No Rules
After spending hours of trying different topic phrases without success, I have given up on MQTT and switched to HTTP. I had success with the very first HTTP command.
But I will keep looking for examples or tutorials from someone else that has been able to get this to working using Node Red.
But I will keep looking for examples or tutorials from someone else that has been able to get this to working using Node Red.
- dynamicdave
- Normal user
- Posts: 257
- Joined: 30 Jan 2017, 20:25
- Location: Hampshire, UK
Re: How To Activate An Output w/MQTT & No Rules
Hi,
This might help you.
I have a set of three MQTT-In nodes (driven from some touch-buttons on a Wemos D1 Mini) to three function nodes in Node-RED that connects to a set of three MQTT-Out nodes to control a set of three LEDs (on the Wemos D1 Mini).
The first MQTT-Out node has its topic configured as...
/wemos46/gpio/13
The next two as 12 and 14.
Note:
You can remove the leading slash character '/' providing you do the same in the ESP Easy MQTT Controller setup.
I think the current trend is NOT to start the topic with a slash character.
Each Function-node sends msg.payload = 1 to turn the output/LED ON, and msg.payload = 0 to turn it off.
I can post the Node-RED flow if that would help you.
Cheers from David.
This might help you.
I have a set of three MQTT-In nodes (driven from some touch-buttons on a Wemos D1 Mini) to three function nodes in Node-RED that connects to a set of three MQTT-Out nodes to control a set of three LEDs (on the Wemos D1 Mini).
The first MQTT-Out node has its topic configured as...
/wemos46/gpio/13
The next two as 12 and 14.
Note:
You can remove the leading slash character '/' providing you do the same in the ESP Easy MQTT Controller setup.
I think the current trend is NOT to start the topic with a slash character.
Each Function-node sends msg.payload = 1 to turn the output/LED ON, and msg.payload = 0 to turn it off.
I can post the Node-RED flow if that would help you.
Cheers from David.
- Attachments
-
- ScreenShot096.png (20.29 KiB) Viewed 14928 times
-
- Normal user
- Posts: 31
- Joined: 20 Oct 2017, 23:47
Re: How To Activate An Output w/MQTT & No Rules
David, anything you could post would be greatly appreciated!!
Node Red flow and screen shots of the ESP Easy Device menus especially.
I'm especially interested in how the Device settings page in ESP Easy is setup. As well as how you configured the mqtt out node and the node that is issuing the payload command.
If I could just see a working example, I can reconfigure it to work with my application.
Node Red flow and screen shots of the ESP Easy Device menus especially.
I'm especially interested in how the Device settings page in ESP Easy is setup. As well as how you configured the mqtt out node and the node that is issuing the payload command.
If I could just see a working example, I can reconfigure it to work with my application.
- dynamicdave
- Normal user
- Posts: 257
- Joined: 30 Jan 2017, 20:25
- Location: Hampshire, UK
Re: How To Activate An Output w/MQTT & No Rules
Hi
I haven't got the Wemos node that I mentioned above - I'ved used it for another project, sorry.
Here are a couple of screenshots of the 'Config' and 'Controller' settings for another node (node29) (hope that doesn't confuse you too much).
Hope this helps you.
Please note that I'm not using the forward slash in the subscribe and pubish settings.
Also note that 192.168.1.140 is the IP address of the Raspberry Pi that is running Node-RED and Mosquitto (MQTT broker).
Also note the node is called 'node29' so the first MQTT-Out node has its topic configured as...
node29/gpio/13
The contents of the Function node looks like this:
I haven't got the Wemos node that I mentioned above - I'ved used it for another project, sorry.
Here are a couple of screenshots of the 'Config' and 'Controller' settings for another node (node29) (hope that doesn't confuse you too much).
Hope this helps you.
Please note that I'm not using the forward slash in the subscribe and pubish settings.
Also note that 192.168.1.140 is the IP address of the Raspberry Pi that is running Node-RED and Mosquitto (MQTT broker).
Also note the node is called 'node29' so the first MQTT-Out node has its topic configured as...
node29/gpio/13
The contents of the Function node looks like this:
Code: Select all
if (msg.payload == "1")
{
msg.payload = 1;
}
else if (msg.payload == "0")
{
msg.payload = 0;
}
return msg;
- Attachments
-
- ScreenShot098.png (9.36 KiB) Viewed 14916 times
-
- ScreenShot097.png (26.91 KiB) Viewed 14916 times
Re: How To Activate An Output w/MQTT & No Rules
A Debian 8 server with a non-root, sudo-enabled user as detailed in Output. Rule added Rule added (v6).
- dynamicdave
- Normal user
- Posts: 257
- Joined: 30 Jan 2017, 20:25
- Location: Hampshire, UK
Re: How To Activate An Output w/MQTT & No Rules
Hi @vedika - your message doesn't seem to relate to this thread.
Did you post it in the wrong topic/thread?
Cheers from David.
Did you post it in the wrong topic/thread?
Cheers from David.
-
- Normal user
- Posts: 31
- Joined: 20 Oct 2017, 23:47
Re: How To Activate An Output w/MQTT & No Rules
David, Could you post the Node Red flow so I could see how you set up each node in the flow?
- dynamicdave
- Normal user
- Posts: 257
- Joined: 30 Jan 2017, 20:25
- Location: Hampshire, UK
Re: How To Activate An Output w/MQTT & No Rules
For some reason phpBB, the Forum Software, won't let me attach a file type .json or .txt -- his boo.
Give me your email address and I'll email it to you.
David.
Give me your email address and I'll email it to you.
David.
-
- Normal user
- Posts: 31
- Joined: 20 Oct 2017, 23:47
Re: How To Activate An Output w/MQTT & No Rules
Sent my email to you via a private message.
Who is online
Users browsing this forum: No registered users and 1 guest