Dead simple firmware for Sonoff switches - just MQTT client, button handler and OTA. Suitable for HomeBridge integration.
You will need following to compile this sketch
- ESP8266 Arduino Core - tested versions 2.3.0 and 2.4.2
- MQTT library
- TaskScheduler library
- WiFiManager library
- OneButton library
- OneWire library - only if you have DS18B20 connected
Use following settings in Arduino IDE
- Board: Generic ESP8266 module
- Flash mode: DIO
- Flash size: 1M (no or 64k SPIFFS)
- CPU Frequency: 80MHz
- Flash Frequency: 40MHz
You need to adjust your MQTT server settings in the code.
Do not attempt to flash this firmware (or do any crazy stuff) when your Sonoff is connected to mains voltage!
- Solder wires or pin header to programming connector/pads
- Connect wires to your favorite USB-Serial converter (VCC-3V3, RX-TX, TX-RX, GND-GND)
- Press button on Sonoff
- Connect USB-Serial to your PC (thus enabling ESP flash mode)
- Upload code with Arduino IDE
Use homebridge-mqttthing plugin.
Sample config for this firmware (replace chipId in topics with your chip ID):
"accessories": [
{
"accessory": "mqttthing",
"type": "switch",
"name": "Sonoffator",
"integerValue": true,
"topics": {
"getOnline": "hb/sonoffator-3b8a49/online",
"getOn": "hb/sonoffator-3b8a49/state",
"setOn": "hb/sonoffator-3b8a49/set"
}
}
]