Firmware Sonoff openHAB configuration

Table of contents


It’s possible to connect Sonoff switch with this firmware to every home automation system which works with devices operating with MQTT Protocol. OpenHAB is one of such.

Required

  • Installed and configured MQTT binding in openHAB

In openHAB 1

  • you can install it using following command
sudo apt-get install openhab-addon-binding-mqtt

In openHAB 2

  • you can install it with PaperUI  or
  • add to /etc/openhab/services/addons.cfg configuration file entry „mqtt” at the end of configuration parameter:
    • binding = mqtt

Configuration of MQTT Binding in OpenHAB

In openHAB 1

  • Look in /etc/openhab/configuration/openhab.cfg configuration file section „MQTT Transport” and configure access to your MQTT Broker

Example:

mqtt:broker.url=tcp://localhost:1883
mqtt:broker.clientId=openHAB
mqtt:broker.user=openhab
mqtt:broker.pwd=password

In OpenHAB 2

  • In /etc/openhab/configurations/addons/mqtt.cfg configuration file configure access to your MQTT Broker

Example:

broker.url=tcp://localhost:1883
broker.clientId=openHAB
broker.user=openhab
broker.pwd=password

Items

Assuming in Sonoff switch configuration you entered MQTT Topic as /sonoff/light/

In the file *.items enter:

Switch  sonoff_light "Light" {mqtt=">[broker:/sonoff/light/cmd:command:ON:ON],>[broker:/sonoff/light/cmd:command:OFF:OFF]"}

If you installed DS18B20 sensor in your Sonoff switch add following as well

Number  sonoff_temperature    "Temperature [%.2f °C]"  { mqtt="<[broker:/sonoff/light/temperature:state:default]"}

Sitemap

To *.sitemap configuration file enter

Switch item=sonoff_light

If you installed DS18B20 sensor in your Sonoff switch add following as well

Text item=sonoff_temperatura

Additional information

If you going to control device connected to Sonoff switch manually by build-in button and it’s important for you that openHAB is aware about such events add following to your openHAB configuration:

To *.items configuration file

Switch sonoff_light_status {mqtt="<[broker:/sonoff/light/state:state:ON:ON],<[broker:/sonoff/light/state:state:OFF:OFF]"}

Add rule to your *.rules

rule "Manual switch change of sonoff_light"
when
    Item sonoff_light_status changed
then
   if (sonoff_light_status.state!=sonoff_light.state) {
     if (sonoff_light_status.state==ON) {
        sendCommand(sonoff_light,ON)
     } else {
        sendCommand(sonoff_light,OFF)
     }
   }
end