Successfully Configuring Sonoff Switches with Tasmota and openHAB2

Hi everyone, I wanted to share my recent experience configuring Sonoff Power Switches with Tasmota firmware on my openHAB2 setup. After spending several hours working through the configuration, I finally got everything up and running smoothly using the MQTT2 binding. Currently, I have seven Sonoff Power Switches integrated into my system, and I wanted to avoid configuring each one individually through the PaperUI.

A helpful hint from @Dim led me to set up my configuration entirely through files. This approach not only streamlines the setup process but also allows me to make simultaneous adjustments across all channels. While there isn’t extensive documentation available on this specific configuration, I decided to share my findings in the hope that it might be useful for others.

In my setup, I’ve included all available options, even those I’m not currently utilizing. These are commented out in the configuration files, but it’s reassuring to know they’re there if I need them in the future. For example, I’ve configured channels for VCC, Wi-Fi details, uptime, and device state, which provide a comprehensive overview of each switch’s status.

Here’s a snippet of my configuration for clarity:

Bridge mqtt:broker:MosquittoMqttBroker “Mosquitto MQTT Broker” @ “MQTT” [ host=“x.x.x.x”, secure=false, port=1883, qos=0, retain=false, clientid=“Oh2Mqtt2Thing”, username=“mymqttuser”, password=“mymqttpass” ]
{
// Sonoff Power Switch 01
Thing mqtt:topic:SonoffPs01 “Sonoff Power Switch 01” @ “MQTT”
{
Channels:
Type switch : switch “Power Switch” [ stateTopic=“tasmota/sonoff-ps01/POWER”, commandTopic=“tasmota/sonoff-ps01/cmnd/POWER”, on=“ON”, off=“OFF” ]
Type string : state01 “Switch State 01” [ stateTopic=“tasmota/sonoff-ps01/STATE”, transformationPattern=“JSONPATH:$.POWER”, on=“ON”, off=“OFF” ]
// Additional channels for VCC, Wi-Fi, uptime, etc.
}
}

This configuration creates a bridge to my Mosquitto broker and defines each Sonoff switch with its respective channels. The items are then mapped in my sonoff-power-switches.items file, ensuring each switch’s state and additional information are accessible within openHAB.

While this setup has been working well for me, I’m curious if there are more efficient ways to manage these configurations, especially as I plan to expand my setup further. I’d love to hear any tips or alternative approaches others might have for optimizing this process. Happy automating!

Cheers,
Sven