Switch commands to ESPEasy via MQTT

Moderator: leecollings

Post Reply
TeBry
Posts: 8
Joined: Thursday 21 October 2021 15:51
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Switch commands to ESPEasy via MQTT

Post by TeBry »

Hi all,
I am using Domoticz 2021.1 on raspberry pi 3B+ for controlling a heat pump and floor heating among other things. I have several distributed ESP32 with ESPEasy installed, and failing to figure out how to control switches in ESPEasy via MQTT, I ended up using http commands to gpio ports. They have been relatively reliable, but have recently been very unstable. Timers not working, and manual switching ends up with Domoticz switching them back.
Since I already use Mosquitto installed locally as an MQTT broker, I want to try the MQTT way to control switches in ESPEasy.
However, I still can't find out how I do that the easiest way. ESPEasy has a Domoticz MQTT controller (helper) and can subscribe to domoticz/out and publish to domoticz/in. With a virtual on/off switch in Domoticz, how do I actually publish the on/off events to MQTT? Do I need a dzvents script or shell script and send commands with mosquitto_pub, or is there a more "embedded" way?
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Switch commands to ESPEasy via MQTT

Post by waltervl »

If MQTT hardware is activated every domoticz action will be published in topic Domoticz/out
Install mqtt explorer to see what is published.
Domoticz will react on payloads in domoticz/in.

See the wiki, be aware that some described functions are on beta only.
https://www.domoticz.com/wiki/MQTT
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
TeBry
Posts: 8
Joined: Thursday 21 October 2021 15:51
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Switch commands to ESPEasy via MQTT

Post by TeBry »

waltervl, you're right! I figured out now, and MQTT Explorer was a great tip.

MQTT hardware is activated in Domoticz, and there is traffic for every event.

So I have ESPEasy with plugin 029 Output included (https://www.letscontrolit.com/wiki/inde ... lugin_list).
I configure the Domoticz MQTT controller/protocol in ESPEasy, and use the Output - Domoticz MQTT Helper for every device I want to control.
The idx is set automatically by Domoticz and needs to be identical in the device. The GPIO port to be controlled is set in the device.
Then I have an issue with some inverted logic. For those devices, I leave the GPIO port blank in the device, and use Rules to set the GPIO:

on GV_Haakon#Output do
if [GV_Haakon#Output]=0
gpio,5,1
else
gpio,5,0
endif
endon

BTW, it turns out that the switches with the strange "springback" flaw continue to reset itself regardless of the http command. It needed to be fixed by deleting and creating new switches, so I could still have done this with http. However, MQTT seems more solid.

Easy Peasy - thanks for your help!
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Switch commands to ESPEasy via MQTT

Post by waltervl »

Good Job!
For the next version of Domoticz MQTT autodiscover is implemented to get things even easier.
So in Espeasy use the HA MQTT autodiscover Controller: https://espeasy.readthedocs.io/en/lates ... #c005-page

Then the Espeasy device will announce itself to Domoticz on MQTT and Domoticz will create the appropriate devices and can communicate with the Espeasy device without any further configuration in Domoticz or Espeasy.

Install a current beta to try out.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
TeBry
Posts: 8
Joined: Thursday 21 October 2021 15:51
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Switch commands to ESPEasy via MQTT

Post by TeBry »

Sounds very nifty! Have a great weekend!
Ries
Posts: 40
Joined: Tuesday 01 December 2015 8:47
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Netherlands
Contact:

Re: Switch commands to ESPEasy via MQTT

Post by Ries »

I have an espeasy co2 sensor. Mqtt. Autodiscover.

It gives errors though, in 2022.1

Any suggestions?
Attachments
9F8013A2-C761-48EA-8214-06B0059E782C.png
9F8013A2-C761-48EA-8214-06B0059E782C.png (298.24 KiB) Viewed 3206 times
E2DF998D-71ED-4F77-9B7C-C48CEFB25CED.png
E2DF998D-71ED-4F77-9B7C-C48CEFB25CED.png (380.11 KiB) Viewed 3206 times
Version 3.9639
Platform: Jessie lite
Hardware: Raspberry pi 3B; RFXCOM; Weather Underground; Dummy; OpenZwave USB; Fritzbox Callmonitor via LAN interface; System Alive Checker (Ping); Philips Hue Bridge; Atag One Thermostat
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Switch commands to ESPEasy via MQTT

Post by waltervl »

Ries wrote: Sunday 27 February 2022 16:56 I have an espeasy co2 sensor. Mqtt. Autodiscover.

It gives errors though, in 2022.1

Any suggestions?
You are using Tasmota and not EspEasy. Look/search in Tasmota for set option 19 to get this running with MQTT Autodiscover.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests