How To Activate An Output w/MQTT & No Rules

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
prairietech
Normal user
Posts: 31
Joined: 20 Oct 2017, 23:47

How To Activate An Output w/MQTT & No Rules

#1 Post by prairietech » 21 May 2019, 14:23

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.

User avatar
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

#2 Post by grovkillen » 21 May 2019, 14:56

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 :idea: :idea: :idea:

prairietech
Normal user
Posts: 31
Joined: 20 Oct 2017, 23:47

Re: How To Activate An Output w/MQTT & No Rules

#3 Post by prairietech » 21 May 2019, 16:45

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.

User avatar
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

#4 Post by grovkillen » 21 May 2019, 16:53

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

Code: Select all

UnitName/cmd
Payload

Code: Select all

GPIO,14,1
And

Code: Select all

GPIO,14,0
Please observer that the subscription topic is set in the controller settings.

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 :idea: :idea: :idea:

prairietech
Normal user
Posts: 31
Joined: 20 Oct 2017, 23:47

Re: How To Activate An Output w/MQTT & No Rules

#5 Post by prairietech » 21 May 2019, 17:03

But how is the 8266 that will be controlling the relay configured? What kind of device type settings are used?

User avatar
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

#6 Post by grovkillen » 21 May 2019, 17:22

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 :idea: :idea: :idea:

prairietech
Normal user
Posts: 31
Joined: 20 Oct 2017, 23:47

Re: How To Activate An Output w/MQTT & No Rules

#7 Post by prairietech » 21 May 2019, 19:27

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.

User avatar
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

#8 Post by grovkillen » 21 May 2019, 20:05

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.
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 :idea: :idea: :idea:

prairietech
Normal user
Posts: 31
Joined: 20 Oct 2017, 23:47

Re: How To Activate An Output w/MQTT & No Rules

#9 Post by prairietech » 26 May 2019, 16:20

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.

User avatar
dynamicdave
Normal user
Posts: 257
Joined: 30 Jan 2017, 20:25
Location: Hampshire, UK

Re: How To Activate An Output w/MQTT & No Rules

#10 Post by dynamicdave » 26 May 2019, 18:34

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.
Attachments
ScreenShot096.png
ScreenShot096.png (20.29 KiB) Viewed 14056 times

prairietech
Normal user
Posts: 31
Joined: 20 Oct 2017, 23:47

Re: How To Activate An Output w/MQTT & No Rules

#11 Post by prairietech » 26 May 2019, 18:50

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.

User avatar
dynamicdave
Normal user
Posts: 257
Joined: 30 Jan 2017, 20:25
Location: Hampshire, UK

Re: How To Activate An Output w/MQTT & No Rules

#12 Post by dynamicdave » 26 May 2019, 19:07

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:

Code: Select all

if (msg.payload == "1")
{
    msg.payload = 1;
}
else if (msg.payload == "0")
{
    msg.payload = 0;
}
return msg;
Attachments
ScreenShot098.png
ScreenShot098.png (9.36 KiB) Viewed 14044 times
ScreenShot097.png
ScreenShot097.png (26.91 KiB) Viewed 14044 times

vedika
New user
Posts: 1
Joined: 27 May 2019, 12:02

Re: How To Activate An Output w/MQTT & No Rules

#13 Post by vedika » 27 May 2019, 12:08

A Debian 8 server with a non-root, sudo-enabled user as detailed in Output. Rule added Rule added (v6).

User avatar
dynamicdave
Normal user
Posts: 257
Joined: 30 Jan 2017, 20:25
Location: Hampshire, UK

Re: How To Activate An Output w/MQTT & No Rules

#14 Post by dynamicdave » 27 May 2019, 15:52

Hi @vedika - your message doesn't seem to relate to this thread.
Did you post it in the wrong topic/thread?

Cheers from David.

prairietech
Normal user
Posts: 31
Joined: 20 Oct 2017, 23:47

Re: How To Activate An Output w/MQTT & No Rules

#15 Post by prairietech » 27 May 2019, 16:26

David, Could you post the Node Red flow so I could see how you set up each node in the flow?

User avatar
dynamicdave
Normal user
Posts: 257
Joined: 30 Jan 2017, 20:25
Location: Hampshire, UK

Re: How To Activate An Output w/MQTT & No Rules

#16 Post by dynamicdave » 27 May 2019, 18:30

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.

prairietech
Normal user
Posts: 31
Joined: 20 Oct 2017, 23:47

Re: How To Activate An Output w/MQTT & No Rules

#17 Post by prairietech » 27 May 2019, 18:33

Sent my email to you via a private message.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 29 guests