Basic MQTT comunication

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Przemo2014
New user
Posts: 6
Joined: 09 Jul 2022, 12:59

Basic MQTT comunication

#1 Post by Przemo2014 » 09 Jul 2022, 14:13

Hello All,
I am trying MQTT communicate between ESPEasy and Domoticz. From Domoticz I send MQTT message as below:

mosquitto_pub -u mylogin -P mypass -t domoticz/out -m {"idx" : 323, "nvalue" : 1,}

in ESPEasy logs i got:

266188840: inputswitchstate is deprecatedinputSwitchState,3,1.00
266188844: EVENT: TDevice#State=0

via ESPEasy Rueles I try to read value of the nvalue argument send in MQTT message as below:

on TDevice#State do
if [%eventvalue%] = 0
Let,3,1
else
Let,3,0
endif
endon

How to properly read the value of the nvalue argument ?
And second query is what should be send in MQTT message in order to event value was 1 no 0 (266188844: EVENT: TDevice#State=0) ?

Kind Regards
Przemo

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Basic MQTT comunication

#2 Post by Ath » 09 Jul 2022, 14:23

What version of ESPEasy (bin filename please) are you using? As that "deprecated" message has been resolved some time ago, AFAIK.

In what plugin are you expecting to receive that value? Did you enable the (Domoticz MQTT) Controller for that plugin and set the matching idx value?

Have you changed your Unit ID from 0 to something else in the range 1..254? The Unit ID should not be 0.
/Ton (PayPal.me)

Przemo2014
New user
Posts: 6
Joined: 09 Jul 2022, 12:59

Re: Basic MQTT comunication

#3 Post by Przemo2014 » 09 Jul 2022, 22:30

ESPEasy ver: ESP_Easy_mega_20220427_normal_ESP8266_4M1M.bin


#In what plugin are you expecting to receive that value?
I try to find out how via MQTT send the value from Domoticz to Wemos D1 and receive via rules in ESPEasy

#Did you enable the (Domoticz MQTT) Controller for that plugin and set the matching idx value?
Yes in the ESP I added MQTT Controller and add MQTT Helper in devices and Switch Input with the same idx.

#Have you changed your Unit ID from 0 to something else in the range 1..254? The Unit ID should not be 0.
If you mean Unit Number of the ESPEasy I had 0 but after changing on 1 I have the same result. Still I am not able to read the value via ESPEasy rules

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

Re: Basic MQTT comunication

#4 Post by TD-er » 09 Jul 2022, 22:49

The OpenHAB MQTT controller does allow for receiving commands.
The Domoticz MQTT controller is much more basic compared to the OpenHAB one.
However you still need the formatting for Domoticz or else you end up formatting it yourself in rules using publish.

You can also use the MQTT import plugin, which can be configured to subscribe to a topic and then receive data.
Not sure if it was already merged in the April build, but there has been some improvement lately on the MQTT import plugin to allow for parsing JSON messages too, to fetch some specific values.
Before these changes you could only receive numerical values as published messages.

Przemo2014
New user
Posts: 6
Joined: 09 Jul 2022, 12:59

Re: Basic MQTT comunication

#5 Post by Przemo2014 » 10 Jul 2022, 16:30

I set MQTT import plugin in the same way like on the webpage https://letscontrolit.com/wiki/index.ph ... QTT_Import
and I try to send MQTT message:

sudo mosquitto_pub -u myid -P mypass -t "cmdMQTT" -m "{"TaskName":"sniff", "cmdMQTT":1.00, "Value2":2.00, "Value3":3.00, "Value4":4.00}"

On the ESPEasy device in logs I got:

64429055: IMPT : Bad Import MQTT Command cmdMQTT
64429056: ERR : Illegal Payload {TaskName:sniff, cmdMQTT:1.00, Value2:2.00, Value3:3.00, Value4:4.00} sniff

Where I make mistake in the MQTT message ? How is proper format ?

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

Re: Basic MQTT comunication

#6 Post by TD-er » 10 Jul 2022, 17:19

Please don't use the wiki, as it is outdated.
Please use the ReadTheDocs: https://espeasy.readthedocs.io/en/lates ... #p037-page

Przemo2014
New user
Posts: 6
Joined: 09 Jul 2022, 12:59

Re: Basic MQTT comunication

#7 Post by Przemo2014 » 10 Jul 2022, 20:33

I checked the link don't find out how is the proper message in order to changing the value.
When I send:
sudo mosquitto_pub -u myid -P mypass -t "cmdMQTT" -m "svalue":"28.1;17.8;2;1010.3;0"

in logs is illegal payload:
Conn. IP Init
78857950: IMPT : Bad Import MQTT Command cmdMQTT
78857950: ERR : Illegal Payload svalue:28.1;17.8;2;1010.3;0 sniff

can you support me by example message ?

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Basic MQTT comunication

#8 Post by Ath » 10 Jul 2022, 21:05

Have you monitored the correct command from Domoticz, that is sent when the device in Domoticz is switched on/off? (it seems like you are using a switch, but it's not fully clear to me yet what you intend to do)
/Ton (PayPal.me)

Przemo2014
New user
Posts: 6
Joined: 09 Jul 2022, 12:59

Re: Basic MQTT comunication

#9 Post by Przemo2014 » 10 Jul 2022, 22:52

I don't use any switch to send MQTT message. Message is send via scripts create in Domoticz. My point is to find out how I can send the MQTT message from domoticz script and to receive via ESPEasy in the rules. The main problem is that I don't know how is proper message send via MQTT which allow to change values in "MQTT import" plugin ?

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

Re: Basic MQTT comunication

#10 Post by TD-er » 11 Jul 2022, 00:29

The MQTT import plugin can handle either "plain" numerical values, or JSON formatted data.
What you're sending is not proper JSON.

This is when using JSON syntax:

Code: Select all

{"svalue": [28.1,17.8,2,1010.3,0]}

Przemo2014
New user
Posts: 6
Joined: 09 Jul 2022, 12:59

Re: Basic MQTT comunication

#11 Post by Przemo2014 » 11 Jul 2022, 15:11

I checked your syntax and the same illegal payload is return in the logs:

145948876: IMPT : Bad Import MQTT Command cmdMQTT
145948876: ERR : Illegal Payload {svalue: [28.05, 25.03, 0, 1009.01, 0]} sniff

when I sent message like:
...-m "28.22;10.22;11.22;23.34"
then only first value was changed. If you use MQTT import plugin can you check how message is send in order to update other values ?

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Basic MQTT comunication

#12 Post by Ath » 11 Jul 2022, 17:11

Przemo2014 wrote: 10 Jul 2022, 22:52 ...to find out how I can send the MQTT message from domoticz script and to receive via ESPEasy in the rules. The main problem is that I don't know how is proper message send via MQTT which allow to change values in "MQTT import" plugin ?
That's why I suggested to go with the flow, and configure a matching item in Domoticz to send out messages, and monitor that using your MQTT tools. Then you will get the correct syntax, for free and without any hassle :D
/Ton (PayPal.me)

Post Reply

Who is online

Users browsing this forum: No registered users and 20 guests