commands via MQTT

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
dkeipp
New user
Posts: 3
Joined: 05 Mar 2019, 14:59

commands via MQTT

#1 Post by dkeipp » 13 Apr 2021, 14:24

Hi!

I try to send commands to my ESPEASY enabled D1mini.
I connected an DFplayer and when I send "play,1" via the "tools" menu it plays the corresponding sound.
When i trigger it via http "http://192.168.0.202/control?cmd=play,1" it works too

but I can't manage to work with mqtt. I tried all mqtt controller. The D1mini can successfull connect to the broker, I can see the LWT message.
But the D1mini does not react to messages send to it.
My sysname: ESPDingDong_1
Controller subscribe: /%sysname%/#
Controller publish: /%sysname%/pub/
Enabled: true
The DFPlayer device is named "Klingel"
So I tried to send following messages to my broker:
[topic | payload]
/ESPDingDong_1/cmd | play,1
/ESPDingDong_1 | play,1
/ESPDingDong_1/Klingel/play | 1
/ESPDingDong_1/Klingel | play,1

but nothing happens. no output on serial or in the log.
I can see that the D1mini subscribed to my broker, but on the D1mini I can't see any incoming messages
I think I'm doing somthing wrong. Can someone tell me what :lol:

Micha_he
Normal user
Posts: 369
Joined: 07 Feb 2018, 19:14
Location: Helmstedt, Germany

Re: commands via MQTT

#2 Post by Micha_he » 13 Apr 2021, 14:41

I mean, the first one '/ESPDingDong_1/cmd | play,1' (without the '|) should work.

The difference to my setup is only:
- My MQTT setup has no leading slash (should work with it too). I removed all of them, because they didn't correspond to the MQTT specifications.
- Controller Publish is set to default at me (%sysname%/%tskname%/%valname%)
- and I use an event for my devices (topic/payload = [device]/cmd event,[eventname]), but all commands should work.

Have you enabled your controller? If you reboot your ESPEasy-device, see you the connect-message from it ? You can see all topics with: 'mosquitto_sub -v -t "#" | ts'.
Last edited by Micha_he on 13 Apr 2021, 15:50, edited 1 time in total.

dkeipp
New user
Posts: 3
Joined: 05 Mar 2019, 14:59

Re: commands via MQTT

#3 Post by dkeipp » 13 Apr 2021, 15:39

THANK YOU!

I removed the leading slashes and it works now using the "home assistant" Controller.

great!

hestia
Normal user
Posts: 90
Joined: 06 Mar 2021, 08:27
Location: Paris

Re: commands via MQTT

#4 Post by hestia » 21 Apr 2021, 22:28

Hi,
I read the post, but couldn't get it work from domoticz to esp :-(
On the esp I have
1/ a controller with
Current Client ID: aquaOnOff_1
Controller Subscribe: %sysname%_%unit% = aquaOnOff_1
2/ an event
on TankLevelOKLow do

From domoticz I send
/aquaOnOff_1/cmd TankLevelOKLow,9

Nothing appears on the esp log

Tried before
1/ a controller with
Current Client ID: aquaOnOff_1
Controller Subscribe: domoticz/out
2/ idem

From domoticz I send
/domoticz/out/cmd TankLevelOKLow,9

Nothing appears on the esp log neither :-(

What did I miss ?

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

Re: commands via MQTT

#5 Post by TD-er » 21 Apr 2021, 22:54

Just make sure you are using the same topics on both ends (Domoticz and ESPEasy).

For example the leading slash really makes a difference.
- /bla -> Topic depth = 2, Root topic is ""/
- bla -> Topic depth = 1, Root topic is "bla"

Domoticz controller does not accept commands via a subtopic "cmd"
This is only supported in the OpenHAB MQTT controller.

hestia
Normal user
Posts: 90
Joined: 06 Mar 2021, 08:27
Location: Paris

Re: commands via MQTT

#6 Post by hestia » 22 Apr 2021, 09:41

Thanks for your reply
For example the leading slash really makes a difference.
- /bla -> Topic depth = 2, Root topic is ""/
- bla -> Topic depth = 1, Root topic is "bla"
I've changed the command in dz script

Code: Select all

sudo mosquitto_pub -t domoticz/out/cmd -m TankLevelOKLow,9
=> on the broker: domoticz/out/cmd TankLevelOKLow,9
But still nothing in the log of the espeasy
Domoticz controller does not accept commands via a subtopic "cmd"
I'm not sure to understand if it applies when the mqtt command is done by an os command in dz...
I my case

Code: Select all

 local mqttPub = 'sudo mosquitto_pub -t domoticz/out/cmd -m TankLevelOKLow,9'
        dz.log("mqttPub " .. mqttPub, dz.LOG_DEBUG)
        os.execute(mqttPub)
Because in the end the command is on the broker
If cmd command is not accepted by dz, what king of information is accepted from dz to espeasy?

I did it between 2 espeasy
1/ with domoticz/out
Publish domoticz/out/cmd,'{TankLevelOKLow,1}'
=> on the broker: domoticz/out/cmd {TankLevelOKLow,1}

2/ with %sysname%_%unit%
Publish aquaOnOff_1/cmd,'{TankLevelOKLow,1}'
=> on the broker: aquaOnOff_1/cmd {TankLevelOKLow,1}
And nothing appears on the aquaOnOff_1 log :-(
Screenshot 2021-04-22 093630.png
Screenshot 2021-04-22 093630.png (53.7 KiB) Viewed 5778 times
Screenshot 2021-04-22 093705.png
Screenshot 2021-04-22 093705.png (48.17 KiB) Viewed 5778 times

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

Re: commands via MQTT

#7 Post by TD-er » 22 Apr 2021, 10:03

Originally the controllers were designed to "send" data.
But MQTT is also capable of receiving data since you can subscribe to a topic.
So it is upto the controller to act on the received data.
The Domoticz MQTT controller does only accept commands for a very small set of plugins (e.g. Domoticz MQTT helper and switch and maybe one or two more)
The OpenHAB MQTT controller does also subscribe to the set subscription topic + "/cmd" and does accept almost any ESPEasy command.
So if you would like to receive commands, even though you use Domoticz, you should use OpenHAB MQTT controller.
This has the drawback that you cannot use the controller directly from a task as the OpenHAB MQTT controller does not send using the syntax required by Domoticz.
So you then must send to Domoticz via Rules and use the publish command to write messages in the specific syntax required by Domoticz.
Sadly you cannot have > 1 active MQTT controller right now.

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

Re: commands via MQTT

#8 Post by Ath » 22 Apr 2021, 10:52

You could use the Domoticz HTTP controller to send the outgoing data, and use the OpenHAB MQTT controller as described, receiving data and/or commands.
/Ton (PayPal.me)

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

Re: commands via MQTT

#9 Post by TD-er » 22 Apr 2021, 11:13

Ah yep, that's true.

hestia
Normal user
Posts: 90
Joined: 06 Mar 2021, 08:27
Location: Paris

Re: commands via MQTT

#10 Post by hestia » 22 Apr 2021, 20:58

Thanks for this clarification
the flows are the following and it works, so I don't want to change everything
Picture1.png
Picture1.png (30.25 KiB) Viewed 5749 times
So I think, I'm going to keep the http from domoticz to aquaOnOff, if not possible to have a full mqtt!
I'd like to change the flow between both espeasy, because they are side to side ; is there a solution to avoid wifi?
Perhaps another topic...

Post Reply

Who is online

Users browsing this forum: No registered users and 27 guests