Publish MQTT mwessages to toggle relay on/off

Moderators: grovkillen, Stuntteam, TD-er, enesbcs

Post Reply
Message
Author
roystervi
New user
Posts: 4
Joined: 12 May 2021, 21:06

Publish MQTT mwessages to toggle relay on/off

#1 Post by roystervi » 12 May 2021, 21:49

Hi all am trying to use RPIEasy to operate some relays for a sprinkler system on a raspberry pi3.
The problem am having is when trying to publish a message with mqtt to trigger a relay. I want to remotely toggle a relay on/off using MQTT commands
I tried to use MQTT Explorer, I can see the topics but I can't seem to PUBLISH messages to trigger a relay on and off,
How can I Publish messages in RPIEasy on a raspberry.
I can publish messages on a esp8266 but not on a raspberry.
Last edited by roystervi on 13 May 2021, 20:39, edited 1 time in total.

User avatar
enesbcs
Normal user
Posts: 587
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: Publish MQTT mwessages

#2 Post by enesbcs » 13 May 2021, 18:57

roystervi wrote: 12 May 2021, 21:49 How can I Publish messages in RPIEasy on a raspberry.
Please be a little more specific.
Do you want to send an mqtt message FROM rpieasy to a sprinkler system, or do you want to RECEIVE mqtt messages and change a GPIO state according it?

If you want to receive, you can add a Generic MQTT controller, and can send generic ESPEasy commands: "<MQTT subscribe template>/cmd" like gpio,12,1 ...
But you can also add P029 Output helper plugins which can be controlled from mqtt like "<MQTT subscribe template>/set" with payload 0/1
Template has to be set inside controller settings, it is unitname/taskname/valuename as default.

Or if you are using Domoticz, the DomoticzMQTT controller works simply. After you added a P029 Output helper, set the IDX to a valid Domoticz switch device, the gpio which assigned to the specific task can be controlled immediately without playing templates.

roystervi
New user
Posts: 4
Joined: 12 May 2021, 21:06

Re: Publish MQTT mwessages

#3 Post by roystervi » 13 May 2021, 20:28

Have you ever use MQTT explorer to monitor your MQTT host ?
YEs I like to use my home automation sys to control a relay on my Raspberry pi that has rpieasy install ON IT via mqtt... am using Generic MQTT controller and gpio is set to output
here is an example whereby if I use a esp8266 this code below work fine
but when I use rpieasy on a raspberry pi this code does not work. only the topic I can see but the relay does not toggle
Am using home assistant

What is the "P029 Output helper plugins" and where can I fine it?

switch:
- platform: mqtt
name: "driveway relay"
state_topic: "garageesp/drivewaysw/Switch"
command_topic: "garageesp/gpio/15"
payload_on: "1"
payload_off: "0"
optimistic: true
retain: true
qos: 0

User avatar
enesbcs
Normal user
Posts: 587
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: Publish MQTT mwessages

#4 Post by enesbcs » 13 May 2021, 21:29

roystervi wrote: 13 May 2021, 20:28 Have you ever use MQTT explorer to monitor your MQTT host ?
Not sure why i want to do that.
roystervi wrote: 13 May 2021, 20:28 Am using home assistant
Well, I am a Domoticz user.
roystervi wrote: 13 May 2021, 20:28 What is the "P029 Output helper plugins" and where can I fine it?
The same place where every plugin exists: in Devices tab
Image
roystervi wrote: 13 May 2021, 20:28 command_topic: "garageesp/gpio/15"
^
There are no such thing in RPIEasy. RPIEasy is not ESPEasy. You can use direct commands (compatible) or tasks/devices (preferred way) to manipulate GPIOs remotely.
roystervi wrote: 13 May 2021, 20:28 garageesp/drivewaysw/Switch/set
^
This accepts 0/1 payload as i wrote previously. This is how it works since 2018.
Although you can alter template at controller and name a P029 task as "gpio" and a value like "15" if you prefer this naming scheme...

Image

This is also working since 2018 in RPIEasy and in ESPEasy: (compatible mode)
<MQTT subscribe template>/cmd with payload: <command>
https://www.letscontrolit.com/wiki/inde ... _Reference

roystervi
New user
Posts: 4
Joined: 12 May 2021, 21:06

Re: SLOVED:

#5 Post by roystervi » 16 May 2021, 06:11

SLOVED:

If anyone using HA and and need to send MQTT commands from HA to RPIEasy on a rspberry pi
1st I went into Controllers and use "Generic MQTT" then enter in my HA MQTT host info
2nd I went into DEVICES and choose "Output - Output Helper" -- Give it a "name", select the "gpio" -- select "Send to Controller" and saved.
3rd In HARDWARE go to "Pinout&Ports" The gpio you use in the 2nd step in the dropdown menu make that gpio an "outout" if you using a relay.
4th Getting the Topic and Publish command. the Topic and Publish command is the same and it goes like this. %sysname%/Name/Values/set
My example: state_topic: "RPIEasy/zone2/State/set" and command_topic: "RPIEasy/zone2/State/set"
Also you can use MQTT explorer to test publish send and receive before using the code in your Yaml file


switch:
- platform: mqtt
name: "testing rpieasy"
state_topic: "RPIEasy/zone2/State/set"
command_topic: "RPIEasy/zone2/State/set"
payload_on: "1"
payload_off: "0"
optimistic: true
retain: true
qos: 0

NOTE: This instructions is for HA users.
If you don't know what HA is, this instructions is not for you.
I got mines to work so I thought I share with fellow HA users.
See you in the FB forum.
any question its "Bobby Walters" in "DR Zzzzzz"" or the Hookups"

sonalford
New user
Posts: 1
Joined: 11 Aug 2021, 11:35

Re: Publish MQTT mwessages to toggle relay on/off

#6 Post by sonalford » 11 Aug 2021, 11:39

Yes, I prefer to utilize my home automation system to operate a relay on my Raspberry Pi using MQTT, which has been installed... I'm using a Generic MQTT controller with a set to output. Here's an example where the code below works great when I use an esp8266, but not when I use it super mario bros

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests