Sonoff

Description

ezvpn-mqtt-sonoff is a Docker container pre-configured to control your Sonoff smart switches in the IOhubTM environment.

ezvpn-mqtt-sonoff listens on an MQTT broker and sends commands to your sonoff to control it.

In IOhubTM architecture, ezvpn-mqtt-sonoff subscribes to an MQTT topic (sonoff/# by default) on the internal MQTT broker, then receiving an action, it sends the command to your Sonoff device.

sonoff schema

How to use it

ezvpn-mqtt-sonoff is a Docker container image pre-configured for communication with ezvpn-mqtt and the Sonoff devices. To use it, you first need a Sonoff compatible device. When used in combination with ezvpn-fld-exchanger, you have a flexible system to control your Sonoff devices on specific conditions triggered by events.

To control a Sonoff device through IOhubTM, the device must be set in DIY mode (DIY Mode)

How to trigger Sonoff functionalities

To trigger the available functions you have to send an optional json to a topic (with their names described below).

Every property in the json is optional and the json itself is optional; an empty message is accepted. The json payload has the following structure:

{
    "ip": "<sonoff device ip>",
    "port": "<sonoff device port>",
    "publish": "<answer topic>"
}
  • ip is the ip address of the sonoff you want to manage. If missing, SONOFF_DEFAULT_IP is used.
  • port is the port of the sonoff you want to manage. If missing, SONOFF_DEFAULT_PORT is used.
  • publish is the MQTT topic name used to send replies. If missing, SONOFF_DEFAULT_PUBLISH_TOPIC is used. If publish and SONOFF_DEFAULT_PUBLISH_TOPIC are both empty, nothing is published back to MQTT.

Functionalities

To trigger a Sonoff functionality, you have to send a message (if empty, default values are used) to a subtopic of MQTT_SUBSCRIBE_TOPIC.

  • Set on: send a message to a topic whose name ends with /on
  • Set off: send a message to a topic whose name ends with /off
  • Set on at power on: send a message to a topic whose name ends with /power-on-on
  • Set off at power on: send a message to a topic whose name ends with /power-on-off
  • Set the previous status at power on: send a message to a topic whose name ends with /power-on-stay
  • Get device info: send a message to a topic whose name ends with /info
  • Get device wifi info: send a message to a topic whose name ends with /wifi-signal

Environment variables

Input MQTT connection

  • MQTT_HOST: source MQTT host. Defaults to "127.0.0.1".
  • MQTT_PORT: source MQTT port. Defaults to 1883.
  • MQTT_SUBSCRIBE_TOPIC: IOhubTM MQTT topic to subscribe. Defaults to sonoff/#.
  • MQTT_WANT_QOS2: request to MQTT to upgrade each incoming message on MQTT_SUBSCRIBE_TOPIC to qos 2 (delivery guaranteed). MQTT will honor the request only if persistence is enabled.
  • SKIP_RETAIN: If true, discard all MQTT messages with retain flag set to true. Defaults to false.

Sonoff connection

  • SONOFF_DEFAULT_IP: Sonoff default device address. Used as default if ip is missing from the command payload. No default value.
  • SONOFF_DEFAULT_PORT: Sonoff default device port. Used as default if port missing from the command payload. Defaults to 8081 (Sonoff default port)
  • SONOFF_DEFAULT_PUBLISH_TOPIC: Used as default if publish is missing from the command payload. If defined, the incoming information (status, wifi signal, ...) are published on this topic.

Docker container details

Image: us-central1-docker.pkg.dev/ez-shared/iohub/iohub-mqtt-sonoff

Supported architecture: amd64

Changelog

v1.0.0
  • First Release