How to command ESPEASY GPIO thru MQTT Mosquitto

Moderators: rtenklooster, Voyager, BertB, Stuntteam

Post Reply
Message
Author
xmenne
Normal user
Posts: 14
Joined: 17 Jul 2019, 17:38
Location: Saint Ouen sur Loire France

How to command ESPEASY GPIO thru MQTT Mosquitto

#1 Post by xmenne » 05 Mar 2020, 12:08

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
Signed XMenne from France

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

#2 Post by grovkillen » 05 Mar 2020, 16:18

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

TD-er
Core team member
Posts: 4654
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: How to command ESPEASY GPIO thru MQTT Mosquitto

#3 Post by TD-er » 05 Mar 2020, 16:51

Also the R120 build is quite old, so not all current features may be present.

xmenne
Normal user
Posts: 14
Joined: 17 Jul 2019, 17:38
Location: Saint Ouen sur Loire France

Re: How to command ESPEASY GPIO thru MQTT Mosquitto

#4 Post by xmenne » 06 Mar 2020, 12:57

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
Signed XMenne from France

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

Re: How to command ESPEASY GPIO thru MQTT Mosquitto

#5 Post by dynamicdave » 06 Mar 2020, 15:12

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.

xmenne
Normal user
Posts: 14
Joined: 17 Jul 2019, 17:38
Location: Saint Ouen sur Loire France

Re: How to command ESPEASY GPIO thru MQTT Mosquitto

#6 Post by xmenne » 10 Mar 2020, 19:19

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 .
Last edited by xmenne on 12 Jan 2021, 18:19, edited 1 time in total.
Signed XMenne from France

xmenne
Normal user
Posts: 14
Joined: 17 Jul 2019, 17:38
Location: Saint Ouen sur Loire France

Re: How to command ESPEASY GPIO thru MQTT Mosquitto

#7 Post by xmenne » 11 Nov 2020, 18:29

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
##
Last edited by xmenne on 03 Dec 2020, 17:55, edited 1 time in total.
Signed XMenne from France

xmenne
Normal user
Posts: 14
Joined: 17 Jul 2019, 17:38
Location: Saint Ouen sur Loire France

Re: How to command ESPEASY GPIO thru MQTT Mosquitto

#8 Post by xmenne » 11 Nov 2020, 18:35

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
Signed XMenne from France

xmenne
Normal user
Posts: 14
Joined: 17 Jul 2019, 17:38
Location: Saint Ouen sur Loire France

Ring the bell project for chevret

#9 Post by xmenne » 16 Mar 2021, 18:37

Ring the bell project for chevret

Pushbutton is ESP20
Device is Switch Input - switch
Name is chevret_bouton_sonette_etage2_ESP20
Internal Pull up
Switch
Normal switch
IDX25
Values is State

Rules on ESP20
On chevret_bouton_sonette_etage2_ESP20#State=1 do
Publish %sysname%/IP,%ip% //pour besoin de test dans les logs
publish domoticz/out/ring_the_bell,1 // publication dans MQTT pour la sonette
endon
On chevret_bouton_sonette_etage2_ESP20#State=0 do
publish domoticz/out/ring_the_bell,0 // publication dans MQTT pour remettre
//la value ring_the_bell à zéro
endon
// manque le code pour empêcher un enfant de sonner pendant trop longtemps.
//Ou pendant les heures de sommeil

Sonette is ESP19
Device is Generic - MQTT Import
Name is sniff_the_pushbutton
MQTT Topic 1 is domoticz/out/ring_the_bell
Values is ring_the_bell

Rules on ESP19
on sniff#cmdMQTT=1 do
Publish %sysname%/IP,%ip% //pour besoin de test dans les logs
gpio,12,1 //Active la sonette
timerSet,1,1 //timer 1 set for 1 sec
endon
On Rules#Timer=1 do
gpio,12,0 //arret sonette
endon
// manque le code pour empêcher un enfant de sonner pendant trop longtemps.
//Ou pendant les heures de sommeil

We can also activate the bell from Domoticz

Sonette is ESP19
Device: Output - Domoticz MQTT Helper
Name: chevret_sonette_etage2_ESP19_GPIO12_D6
Actuator1st GPIO: GPIO-12 (D6)
IDX: 23

Domoticz Push Button for IDX23

Name is chevret Sonette 2etage
Switch Type is Push On Button
On Delay O sec.
Off Delay 1 sec.
Signed XMenne from France

xmenne
Normal user
Posts: 14
Joined: 17 Jul 2019, 17:38
Location: Saint Ouen sur Loire France

Domoticz et Mosquitto chez OVH

#10 Post by xmenne » 17 Mar 2021, 15:59

Voir Amazon cloud pour la config IP et User et Password
Install Domoticz on Debian10
Step 4-a: Updating Debian
First, we need to install sudo and add our pi user to the sudo group.
Assuming you have SSH access and you are logged on with the pi user, become root with the su command:
Execute this command to update Debian to the latest standards and automatically reboot your virtual machine when it’s completed.
apt update -y && apt upgrade -y && systemctl reboot
Step 5-a: Prepare Debian for Domoticz
So now we have Debian up and running as we like, we need to prepare Debian for Domoticz. Debian is less prepared and expanded by default than Raspbian for the Raspberry Pi. So we will have to ensure that Debian knows and can execute the commands for Domoticz. For this we need to install and prepare a number of things. Execute the following commands:
sudo apt install build-essential -y
sudo apt install cmake libboost-dev libboost-thread-dev libboost-system-dev libsqlite3-dev subversion curl libcurl4 libcurl4-openssl-dev libusb-dev zlib1g-dev libssl-dev git -y
Step 5-b: Install
Per advice by Domoticz forum user “dzjr” you should also install the pip3 package manually (thank you for the feedback dzjr!)
You can do so with the following command:
sudo apt install python3-pip -y
Step 6: Install Domoticz
We are finally there! Say yes to the dress! (don’t ask… I’m sitting next to my wife while writing this article and it’s really awful, awful television…).
We can now install Domoticz the regular way:
curl -sSL install.domoticz.com | sudo bash
NOTE: If you get a curl error, run Step 5-a again:
sudo apt install build-essential -y
sudo apt install cmake libboost-dev libboost-thread-dev libboost-system-dev libsqlite3-dev subversion curl libcurl4 libcurl4-openssl-dev libusb-dev zlib1g-dev libssl-dev git -y
And there she is, our Domoticz server is up and running.

La commande pour installer Mosquitto sous Linux est

sudo apt install mosquitto
Lien vers le fichier : cliquez ici
L'installation d'un client peut très utile pour faire des tests par la suite.
Ces tests se feront avec la commande mosquitto_sub ou mosquitto_pub
sudo apt-get install mosquitto-clients
Lien vers le fichier : cliquez ici
Vérifier qu'il répond bien avec la commande
systemctl status mosquitto[/list][/list]
Signed XMenne from France

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests