Door Contact sensors on Tasmota to Domoticz via MQTT

Moderator: leecollings

Post Reply
ardamayne
Posts: 2
Joined: Tuesday 10 July 2018 3:00
Target OS: Linux
Domoticz version:
Contact:

Door Contact sensors on Tasmota to Domoticz via MQTT

Post by ardamayne »

I have been using Domoticz for many years, and am likewise a big fan of Tasmota and use several ESP8266/ESP32-based devices in my environment. Using Tasmota's "Configure Domoticz" options, it is quite easy to create a dummy device in Domoticz and control the Tasmota device. Likewise, the Domoticz MQTT Discovery plugin on Github works well and devices simply show up when MQTT gets configured on Tasmota. Relays, great. Temp/hum sensors, great. However, one thing I had an embarrassingly large amount of trouble implementing was a simple door contact switch.

By default, Tasmota's switches are attached to relays to control them, and while they can be detached, they don't show up with the discovery plugin and there is no added field enter the idx under the "configure Domoticz" section in Tasmota. So, I can wire up a simple reed switch to a free GPIO of the ESP, but I couldn't get it's state into a Domoticz device. I was unable to find a simple solution and figured I'd need to do some normalization using Node-Red to get the MQTT messages from Tasmota parsed and sent to Domoticz using the JSON API- I had done something similar previously to get UPS stats from apcupsd into Domoticz.

When I finally got around to implementing this in earnest, I discovered this was easily accomplished with built-in tools using Tasmota's own documentation on switches.
Again, this isn't anything new or groundbreaking, I was just unable to find this information presented very clearly so I am attempting to do so. Maybe it wasn't laid out because it's so straightforward!
  • Create a virtual switch in Domoticz using the dummy hardware. Configure as a door contact.
  • Ensure the "MQTT Client Gateway with LAN Interface" hardware to Domoticz is pointed to the same MQTT server as Tasmota.
  • In Tasmota, configure the GPIO as a Switch with an unused switch number. Configure a Rule (below) using the Tasmota console to publish that switch's state using MQTT.
Per Tasmota's documentation, I am putting the switch in the default toggle mode, clearing the switch topic, then configuring and activating a Rule to publish an MQTT message to the domoticz/in topic using my Domoticz idx number when the switch is on (open) or off (closed). Turns out this simple publish is exactly what Tasmota does when configuring idx values under the "Configure Domoticz" section.
In this example, my Domoticz idx is 649 and I am using Switch 5 on Tasmota. Tasmota allows up to 4 rules active, and this is using Rule1.

Code: Select all

Backlog SwitchMode5 1; SwitchTopic5 0
Backlog Rule1 on Switch5#state=1 do Publish domoticz/in {"command": "switchlight", "idx": 649, "switchcmd": "On" } endon on Switch5#state=0 do Publish domoticz/in {"command": "switchlight", "idx": 649, "switchcmd": "Off" } endon; Rule1 1
User avatar
waltervl
Posts: 5382
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Door Contact sensors on Tasmota to Domoticz via MQTT

Post by waltervl »

It is a pity Tasmota dropped the MQTT Autodiscover protocol.
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 1 guest