A short description (mostly notes to myself) how to make a sonoff device work with fhem and alexa..
- Pin strip 2.54 with 4-5 pins (one is unused, 4 is enough)
- A ftdi usb/serial converter - most should work, it shoul dprovide 3.3V, gnd, rx and tx
- An Amazon Echo or echo dot
- FHEM obviously
- Arduino IDE for programming - here I used the latest zip for non admin install (version 1.8.5)
- mosquitto as an MQTT broker - downloaded the latest source - v1.4.14
arduino-1.8.5 --portable] ----packages\esp8266\hardware\... ----sketchbook\ ------librariers\(all libs from the tasmota source) ------sonoff (the sonoff source itself) </pre>]
After this, you have to edit the portable\sketchbook\sonoff\user_config.h to add your SSID/pass, MQTT gateway IP and other pertinent stuff (TLS yes/no, etc).
Then you can start the Arduino IDE, load the sonoff.ino (same folder), and verify the build (aka compile).
If all is well you can proceed with flashing, making sure you have selected:Board: "Generic ESP8266 Module" Flash Mode: "DOUT" !!!! Flash Frequency: "40MHz" Upload Using: "Serial" CPU Frequency: "80MHz" Flash Size: "1M (no SPIFFS)" !!!! Debug Port: "Disabled" Debug Level: "None" Reset Method: "ck" Upload Speed: "115200" Port: Your COM port connected to sonoff
You should now have a sonoff which connects to wifi, gets an ip (check your dhcp server) and you can access it's webinterface at that ip address.
- Configure module - you can set the type, and what additional HW you have connected to pins
- Configure wifi - self explanatory
- Configure MQTT -> you can redefine the host ip, and port. the client (aka sonoff) user and pass: I used the default DVES_USER, and the topic (this is the one you'll access later from fhem). I used "sonoff_kitchen" as the topic.
- Configure Other -> set emulation to Belkin WeMo (single device) or Hue Bridge (multi device) - I used WeMo
After configuring and saving the sonoff/Tasmota will restart with the new settings.
In order to work with FHEM we need to bridge the sonoff through an MQTT broker.
I used mosquitto (dl link above), which I didn't find as a package for my ancient NAS running debian 5/lenny. Compiling mosquitto was pretty straight-forward, I had to install: cmake libssl-dev uuid-dev
I had to disable TLS-PSK, as the ssl version I had was also very old and I'd get compile errors
I also had to comment #WITH_SRV=yes - that's for server lookup, also didn't work - some missing headers/libs.
After that it's just:
make sudo make install
Next I created a runscript for mosquitto (/etc/init.d/mosquitto) available here. After changing /etc/mosquitto.conf.sample to mosquitto.conf, adapting it (had nothing to configure really) I managed to run the mosquitto broker.
Immediately I saw the sonoff connecting to it, and using mosquitto_sub (command line subscriber) I could subscribe to it and watch the current state)
- for the broker:
define myBroker MQTT 192.168.1.3:1883 attr myBroker room MQTT
- and for the sonoff:
define Sonoff_bucatarie MQTT_DEVICE attr Sonoff_bucatarie IODev myBroker attr Sonoff_bucatarie devStateIcon ON:FS20.on OFF:FS20.off attr Sonoff_bucatarie publishSet ON OFF cmnd/sonoff_kitchen/POWER attr Sonoff_bucatarie room MQTT attr Sonoff_bucatarie stateFormat Lumina attr Sonoff_bucatarie subscribeReading_Lumina stat/sonoff_kitchen/POWER attr Sonoff_bucatarie subscribeReading_Sensor tele/sonoff_kitchen/SENSOR attr Sonoff_bucatarie subscribeReading_Status tele/sonoff_kitchen/STATE attr Sonoff_bucatarie webCmd ON:OFF