Archiv für den Monat: November 2016

Use Sonoff S20 pins for Sensors with espeasy

The Sonoff S20 has only a 4 pin header (GND, TX, RX, VCC).

To use this pins (TX=GPIO1, RX=GPIO3) for sensors, the serial interface has to be disabled:
Tools – Advanced – Enable Serial port: uncheck

Now it is possible to use gpio1 and gpio3 for Devices:

This is the first test on a breadboard with DHT11
I don’t think that a humidity sensor makes any sense inside the socket. Therefore, I think I will use DS12B20 soldered on a female pin header in the final version.

And this is the result:

The values are also published via mqtt:

# mosquitto_sub -h -t "#" -v
/sonoff-s20/DHT11/Temperature 24.00
/sonoff-s20/DHT11/Humidity 33.00

Sonoff S20 and espeasy

Flash espeasy

Image can be found here.
To boot the sonoff into flash mode, press and hold the button while connecting it to power.

./ --port /dev/ttyUSB0 write_flash 0x000 ESPEasy_R120_1024.bin -fs 8m

Connect to wifi and configure

Connect to ESP_0 with password configesp and set up the wifi connection.

After connecting to wifi open the webinterface http://ip.of.sonoff/config and configure the name and unit number. The name of my sonoff is sonoff-s20.

Configure Hardware and Devices.

espeasy-hardware espeasy-button espeasy-relay

Enable rules: Tools – Advanced – Rules: Checked

Now there is a new menu entry named Rules

On Button#State=1 do
  if [Relay#State]=0

Now you can toggle the relay with the button.

MQTT usage

I use the protocol OpenHAB MQTT. So I can subscribe these events:

# mosquitto_sub -h my.mqtt.server -t "#" -v
/sonoff-s20/Relay/State 1
/sonoff-s20/Relay/State 0

To switch on and off you can publish these messages:

# mosquitto_pub -h -t "/sonoff-s20/gpio/12" -m "1"
# mosquitto_pub -h -t "/sonoff-s20/gpio/12" -m "0"

It is also possible to change „Relay“ to „gpio“ and „State“ to „12“. In this case, the subscribed and published strings are the same, but the rules also have to be modified. is the IP-Address of the MQTT-Server (for example, mosquitto).

openHAB configuration

After configuration of the mqtt-binding in openhab.cfg I created a new item-file

Switch sonoff01 "Sonoff Socket" {mqtt=">[mosquitto:/sonoff-s20/gpio/12:command:ON:1],>[mosquitto:/sonoff-s20/gpio/12:command:OFF:0],<[mosquitto:/sonoff-s20/Relay/State:state:MAP(]", autoupdate="false"}

I also created the file transforms/