My Sonoff Smart Garage
I wanted to explore setting up one of my garages using the Sonoff SV which was inspired by a YouTube video from DrZzs (https://youtu.be/QMepwpyjMCY).
This project was an attempt to enable my garage to work with Home Assistant using MQTT. I tried out the Sonoff SV for my first time use of that model on something practical and could benefit from the relay switch built-in.
Figure 1.1 – View of the first Sonoff SV implementation using a magnet reed switch.
1. My Amazon Gear
- Sonoff SV – https://amzn.to/2AzqXnh
- Wired Door Sensor Magnetic Switch – https://amzn.to/2LQETO6
- USB to TTL Serial Converter – https://amzn.to/2C58P4u
2. Tools and Software
- Soldering Iron
- Jumper Wires
- Glue Gun (Optional)
- Soap Box
- MQTT Broker (Local Hassio)
- ESPEasy Mega
- Sonoff.bin (Version 6.4.1)
Documentation for building the Garage “Smart”
- Project captured on Hackster.io: https://www.hackster.io/mikereams/my-first-smart-garage-2dca85
- Code Repository (Arduino Sketch only): https://github.com/solventarchitect/MQTT_Sonoff/blob/master/door_reed_sensor.ino
3. Sonoff Build
I recently upgraded to the latest Sonoff-Tasmota 6.4.1 which includes integration with Home Assistant – keep it in mind it will change the publish and subscribe settings. I also opted to allow the Sonoff rules to turnoff the relay after 1 second rather than via MQTT in Home Assistant.
If using a Mini USB to flash like I am, then you will need to install CP210x USB to UART Bridge VCP Drivers from – https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers
4. Run the following Sonoff Post-Commands:
Assuming you already connected to WiFi at this point. The following commands were used after flashing the Sonoff SV (6.4.1). I created a rule from having to require an outside process to turn off the relay (which worked in Home Assistant).
Note: Always best practice to set a static IP at the router for this device.
- Backlog SwitchMode1 0;SwitchMode2 2;Switchretain 1;Powerretain 1;switchtopic2 garagestate
- rule1 on Power1#state=1 do backlog power1 1; ruletimer1 1 endon on rules#timer=1 do power1 off endon
- rule1 1
- SetOption19 1
- This enables Home-Assistant automatic discovery and creates the mqtt structure for hassio
- SetOption19 0
- This disables Home-Assistant automatic discovery as I chose to use custom mqtt sensors – just wanted to match the same structure as other devices without auto discovery involved
- SetOption30 0
- Zero (0) will Automatic announcement as ‘switch’ for relays and ‘light’ for PWM in Home-Assistant MQTT discovery message.
- One (1) will Enforce Home-Assistant discovery as ‘light’ platform also for relays
Diagram of pre-production Go-Live