How to command ESPEASY GPIO thru MQTT Mosquitto
Moderators: rtenklooster, Voyager, BertB, Stuntteam
How to command ESPEASY GPIO thru MQTT Mosquitto
I have a mosquitto broker and Domoticz installed on Pi.
I have a ESPEasy R120 installed on ESP8266 WemosD1 Mini.
All installed recently end of 2019.
I am successfull to have one switch working via Domoticz Http .
http://192.168.1.24/control?cmd=GPIO,15,1 is working fine.
What I want to do is the same thing but thru MQTT.
I have tried several flavor of this configuration without success
ESP03 subscribe Template is >> ESP03/#
Then I Publish on MQTT >> mosquitto_pub -t ESP03/cmd -m gpio,15,1
Therefore I see that on MQTT >> ESP03/cmd gpio,15,1
as expected
The issue is that with several flavor of this command and subscribe template i have no effect on mys ESP and switch.
I have two question for any one who may have a similar configuration :
Where can I see some detailed log in ESPEasy ?
Where am i wrong in the way i write my command ?
Thks
I have a ESPEasy R120 installed on ESP8266 WemosD1 Mini.
All installed recently end of 2019.
I am successfull to have one switch working via Domoticz Http .
http://192.168.1.24/control?cmd=GPIO,15,1 is working fine.
What I want to do is the same thing but thru MQTT.
I have tried several flavor of this configuration without success
ESP03 subscribe Template is >> ESP03/#
Then I Publish on MQTT >> mosquitto_pub -t ESP03/cmd -m gpio,15,1
Therefore I see that on MQTT >> ESP03/cmd gpio,15,1
as expected
The issue is that with several flavor of this command and subscribe template i have no effect on mys ESP and switch.
I have two question for any one who may have a similar configuration :
Where can I see some detailed log in ESPEasy ?
Where am i wrong in the way i write my command ?
Thks
Signed XMenne from France
- grovkillen
- Core team member
- Posts: 3621
- Joined: 19 Jan 2017, 12:56
- Location: Hudiksvall, Sweden
- Contact:
Re: How to command ESPEASY GPIO thru MQTT Mosquitto
You can use the web log or the serial log to see what's going on.
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



Re: How to command ESPEASY GPIO thru MQTT Mosquitto
Also the R120 build is quite old, so not all current features may be present.
Re: How to command ESPEASY GPIO thru MQTT Mosquitto
Hello Thanks,
I uploaded latest version ESP EASY mega.
This is a big change and i will need time to discover the field of possible with this version.
May be i will find a way to avoid HTTP command to adress the GPIO with this Mega version
Need time as this is not my first activity
Thanks again
I uploaded latest version ESP EASY mega.
This is a big change and i will need time to discover the field of possible with this version.
May be i will find a way to avoid HTTP command to adress the GPIO with this Mega version
Need time as this is not my first activity

Thanks again
Signed XMenne from France
- dynamicdave
- Normal user
- Posts: 229
- Joined: 30 Jan 2017, 20:25
- Location: Hampshire, UK
Re: How to command ESPEASY GPIO thru MQTT Mosquitto
What I do in Node-RED is to use a MQTT-Out node (running Mosquitto) which is set-up with the IP address of your server
then set-up the topic in the MQTT-Out.
Something like... nodeXX/gpio/14
Where nodeXX is the 'Unit Name' as used in the ESP-Easy Config tab.
14 relates to the GPIO pin, which in this case is D5.
Pin mappings are...
D8 GPIO-15
D7 GPIO-13
D6 GPIO-12
D5 GPIO-14
I have about 40 Wemos D1 Mini devices and each one has a fixed IP address, like 192.168.1.41
So I name the Wemos D1 Mini with 'node41' and stick a label on the botton of the breadboard.
This means it's easy to workout the IP address when I pick-up a breadboard.
The Controller Subscribe setting in ESP-Easy looks like this... %sysname%/#
This means the Wemos named 'node41' will subscribe to... node41/#
To test it out (using Node-RED) you could connect an Inject node to the MQTT-Out node.
Set the Inject node to output a payload of a numeric value - either a 1 or 0 to operate the GPIO pin.
Hope this works for you.
then set-up the topic in the MQTT-Out.
Something like... nodeXX/gpio/14
Where nodeXX is the 'Unit Name' as used in the ESP-Easy Config tab.
14 relates to the GPIO pin, which in this case is D5.
Pin mappings are...
D8 GPIO-15
D7 GPIO-13
D6 GPIO-12
D5 GPIO-14
I have about 40 Wemos D1 Mini devices and each one has a fixed IP address, like 192.168.1.41
So I name the Wemos D1 Mini with 'node41' and stick a label on the botton of the breadboard.
This means it's easy to workout the IP address when I pick-up a breadboard.
The Controller Subscribe setting in ESP-Easy looks like this... %sysname%/#
This means the Wemos named 'node41' will subscribe to... node41/#
To test it out (using Node-RED) you could connect an Inject node to the MQTT-Out node.
Set the Inject node to output a payload of a numeric value - either a 1 or 0 to operate the GPIO pin.
Hope this works for you.
Re: How to command ESPEASY GPIO thru MQTT Mosquitto
Hello
Many thanks, you open my mind to new path to solution and it works now
What I did for the record
I updated ESP with ESPEasy Mega version
I discovered the new function MQTT Import
I create a new Device Generic MQTT import
Name = Task Name >> RelaisChevret
MQTT Topic1 >> domoticz/out/ESP11_Relai1
andValue Name >> Relai1
When you publish on your Broker
mosquitto_pub -h mqtt.xxxx.net -t domoticz/out/ESP11_Relai1 -m 1
Then your Device Value Relai1 is 1
After that I created Rules (also new for me)
On RelaisChevret#Relai1=1 do
GPIO,12,1
end on
and it works and this close this post I suppose.
I now have to work on Domoticz but it is another story.
Many thanks to you all , this forum is very helpful.
Hope i can help some one one day in return .
Many thanks, you open my mind to new path to solution and it works now
What I did for the record
I updated ESP with ESPEasy Mega version
I discovered the new function MQTT Import
I create a new Device Generic MQTT import
Name = Task Name >> RelaisChevret
MQTT Topic1 >> domoticz/out/ESP11_Relai1
andValue Name >> Relai1
When you publish on your Broker
mosquitto_pub -h mqtt.xxxx.net -t domoticz/out/ESP11_Relai1 -m 1
Then your Device Value Relai1 is 1
After that I created Rules (also new for me)
On RelaisChevret#Relai1=1 do
GPIO,12,1
end on
and it works and this close this post I suppose.
I now have to work on Domoticz but it is another story.
Many thanks to you all , this forum is very helpful.
Hope i can help some one one day in return .
Last edited by xmenne on 12 Jan 2021, 18:19, edited 1 time in total.
Signed XMenne from France
Re: How to command ESPEASY GPIO thru MQTT Mosquitto
The purpose of this MONIT configuration is to have Domoticz restart fully after an electrica shut down of my RASP.
Here we have the config for Web Server monit , config for alerting email and config for Restart Domoticz service
To modify the config go here
sudo nano /etc/monit/monitrc
to check Syntax
sudo monit -t
###################################################################"
set mailserver smtp.gmail.com port 587 # primary mailserver
username "xx.mennesson@gmail.com" password "M__7"
using tlsv1
with timeout 30 seconds
set alert xx.mennesson@gmail.com
#
#
# backup.bar.baz port 10025, # backup mailserver on port 10025
# localhost # fallback relay
#
#
## By default Monit will drop alert events if no mail servers are available.
## If you want to keep the alerts for later delivery retry, you can use the
## EVENTQUEUE statement. The base directory where undelivered alerts will be
## stored is specified by the BASEDIR option. You can limit the queue size
## by using the SLOTS option (if omitted, the queue is limited by space
## available in the back end filesystem).
#
set eventqueue
basedir /var/lib/monit/events # set the base directory where events will be stored
slots 100 # optionally limit the queue size
#
#
#
set httpd port 2812
use address 192.168.1.107 # only accept connection from localhost (drop if you use M/Monit)
allow 0.0.0.0/0.0.0.0 # allow localhost to connect to the server and
allow admin:monit # require user 'admin' with password 'monit'
#
#
# #with ssl { # enable SSL/TLS and set path to server certificate
# # pemfile: /etc/ssl/certs/monit.pem
# #}
#
###############################################################################
## Services
###############################################################################
###### Monitoring Domoticz selon PROJETSDIY.FRN
check process domoticz with pidfile /var/run/domoticz.pid
start program = "/etc/init.d/domoticz.sh start"
stop program = "/etc/init.d/domoticz.sh stop"
if failed
url http://127.0.0.1:8080/json.htm?type=com ... getversion
and content = '"status" : "OK"'
for 2 cycles
then restart
if 5 restarts within 5 cycles then exec "/sbin/reboot"
#
## Check that a process is running, in this case Apache, and that it respond
##
Here we have the config for Web Server monit , config for alerting email and config for Restart Domoticz service
To modify the config go here
sudo nano /etc/monit/monitrc
to check Syntax
sudo monit -t
###################################################################"
set mailserver smtp.gmail.com port 587 # primary mailserver
username "xx.mennesson@gmail.com" password "M__7"
using tlsv1
with timeout 30 seconds
set alert xx.mennesson@gmail.com
#
#
# backup.bar.baz port 10025, # backup mailserver on port 10025
# localhost # fallback relay
#
#
## By default Monit will drop alert events if no mail servers are available.
## If you want to keep the alerts for later delivery retry, you can use the
## EVENTQUEUE statement. The base directory where undelivered alerts will be
## stored is specified by the BASEDIR option. You can limit the queue size
## by using the SLOTS option (if omitted, the queue is limited by space
## available in the back end filesystem).
#
set eventqueue
basedir /var/lib/monit/events # set the base directory where events will be stored
slots 100 # optionally limit the queue size
#
#
#
set httpd port 2812
use address 192.168.1.107 # only accept connection from localhost (drop if you use M/Monit)
allow 0.0.0.0/0.0.0.0 # allow localhost to connect to the server and
allow admin:monit # require user 'admin' with password 'monit'
#
#
# #with ssl { # enable SSL/TLS and set path to server certificate
# # pemfile: /etc/ssl/certs/monit.pem
# #}
#
###############################################################################
## Services
###############################################################################
###### Monitoring Domoticz selon PROJETSDIY.FRN
check process domoticz with pidfile /var/run/domoticz.pid
start program = "/etc/init.d/domoticz.sh start"
stop program = "/etc/init.d/domoticz.sh stop"
if failed
url http://127.0.0.1:8080/json.htm?type=com ... getversion
and content = '"status" : "OK"'
for 2 cycles
then restart
if 5 restarts within 5 cycles then exec "/sbin/reboot"
#
## Check that a process is running, in this case Apache, and that it respond
##
Last edited by xmenne on 03 Dec 2020, 17:55, edited 1 time in total.
Signed XMenne from France
Re: How to command ESPEASY GPIO thru MQTT Mosquitto
The purpose of this Script LUA is to activate e relay from Domoticz thru MQTT:
How to rename the file if necessary
mv /home/pi/domoticz/scripts/lua/script_device_chevret_relai1.lua /home/pi/domoticz/scripts/lua/script_device_chevret_relai1_demo.lua
Quand il y a demo dans le nom d'un fichier le script ne l'execute pas
-[[
Intention of this script is to publish defined message using MQTT broker running on a localhost.
The script will trigger only when the status of the defined device is changed.
--]]
--------------------------------
------ Variables to edit ------
--------------------------------
devicename = "RelaisChevret"
deviceIDX = 18
debug = false
--------------------------------
-- End of variables to edit --
--------------------------------
commandArray = {}
if (devicechanged[devicename]) then
print(devicename.." MQTT script running...")
if (devicechanged[devicename] == "On") then
print(devicename.." turned on!")
os.execute('mosquitto_pub -h mqtt.leamicz.net -t domoticz/out/esp11_relai1 -m "1"')
elseif (devicechanged[devicename] == "Off") then
print(devicename.." turned off!")
os.execute('mosquitto_pub -h mqtt.leamicz.net -t domoticz/out/esp11_relai1 -m "0"')
end
end
for i, v in pairs(devicechanged) do print(" " .. i .. ' : ' .. v)
end
return commandArray
How to rename the file if necessary
mv /home/pi/domoticz/scripts/lua/script_device_chevret_relai1.lua /home/pi/domoticz/scripts/lua/script_device_chevret_relai1_demo.lua
Quand il y a demo dans le nom d'un fichier le script ne l'execute pas
-[[
Intention of this script is to publish defined message using MQTT broker running on a localhost.
The script will trigger only when the status of the defined device is changed.
--]]
--------------------------------
------ Variables to edit ------
--------------------------------
devicename = "RelaisChevret"
deviceIDX = 18
debug = false
--------------------------------
-- End of variables to edit --
--------------------------------
commandArray = {}
if (devicechanged[devicename]) then
print(devicename.." MQTT script running...")
if (devicechanged[devicename] == "On") then
print(devicename.." turned on!")
os.execute('mosquitto_pub -h mqtt.leamicz.net -t domoticz/out/esp11_relai1 -m "1"')
elseif (devicechanged[devicename] == "Off") then
print(devicename.." turned off!")
os.execute('mosquitto_pub -h mqtt.leamicz.net -t domoticz/out/esp11_relai1 -m "0"')
end
end
for i, v in pairs(devicechanged) do print(" " .. i .. ' : ' .. v)
end
return commandArray
Signed XMenne from France
Who is online
Users browsing this forum: No registered users and 6 guests