Sonoff firmware data exchange

Table of contents


Data exchange with Sonoff switch

Communication with Sonoff switch is made with MQTT protocol. MQTT is very light and easy data exchanging protocol based on mechanism of publishing messages and subscription to topics. It was designed especially  for data exchange in networks with low bandwidth, unstable infrastructure, long reply times, etc. Protocol deals well with all network problems and provides relative stability in such condition. It fits well to IoT, machine-2-machine communication and home automation.

Data exchange between devices and automation software requires MQTT Broker.

Required

  • Access to MQTT Broker

MQTT Mesages

Temat Wiadomość Działanie
/sonoff/abcdef/cmd Inbound ON Turns on Sonoff relay
/sonoff/abcdef/cmd Inbound OFF Turns off Sonoff relauy
/sonoff/abcdef/cmd Inbound reportStatus Returns current Sonoff state: ON – relay is turned on, OFF -relay is turned off
/sonoff/abcdef/cmd Inbound reboot Reboots Sonoff switch
/sonoff/abcdef/cmd Inbound configurationMode Switch Sonoff to configuration mode without AccessPoint
/sonoff/abcdef/state Outbound ON Sonoff publishes message ON to this topic whenever relay turns from OFF to ON
/sonoff/abcdef/state Outbound OFF Sonoff publishes message OFF to this topic whenever relay turns from ON to OFF
/sonoff/abcdef/temperature Outbound Number Sonoff sends temperature value to this topic

Information:

  • /sonoff/abcdef/ above is equal to MQTT Topic defined by you in the Configuration Panel

In order to use Sonoff switch it’s necessary to configure MQTT Broker parameters:

  • Host: IP address or host name of MQTT Broker
  • Port: MQTT Broker port, default 1883
  • User: User name (optional)
  • Password: User password (optional)
  • Topic: a main part of a MQTT topic. You can modify default value. Format:
    • /topic-name/sub-topic-name/…/ for example:
      • /sonoff/kitchen/
      • /sonoff/bedroom/light/
      • /sonoff/bedroom/tv/
      • /sonoff/bedroom/audio/
    • Each device using MQTT in your installation has to have unique topic

Information

  • Current version does not support SSL connection
  • I strongly recommend configuration of MQTT Broker which requires authentication
  • There is possibility to configure Sonoff switch with MQTT Broker which doesn’t require authentication

> Go now to openHAB configuration