In my last blog post, I talked about building a voice-activated calorie tracking app. Now, I’m shifting my focus to home automation, specifically automating my 40-inch wooden gate so my robotic lawn mower can run on a schedule without me having to manually open it.
The Problem
My robotic lawn mower is great, but there’s one problem—it can’t open my fence gate by itself. Right now, I have to go outside and manually open the gate before running the mower, which makes scheduling it impractical.
The goal is to integrate everything into Home Assistant using a WiFi-enabled microcontroller for control.
Planned Solution
To keep costs low while ensuring reliability, I plan to use:
- VEVOR Linear Actuator 12V
A 12-inch high load actuator rated at 330lbs/1500N with a speed of 0.19"/s, complete with a mounting bracket and IP54 protection. - WiFi Microcontroller-Based Relay Board
Instead of Z-Wave, I'll be using a microcontroller with WiFi connectivity to control the power supply to the actuator. - Relay Board for Polarity Switching
A dedicated relay board that not only controls the actuator’s power but also allows for quick and safe reversal of polarity. This addition simplifies the wiring and improves reliability by ensuring smooth transitions between opening and closing the gate. - 12V 5A DC Power Adapter to power the actuator.
- L-Brackets & Hinges for mounting.
The idea is that Home Assistant will send a command over WiFi to the microcontroller, which will then trigger the relay board to apply power to the linear actuator with the correct polarity to push the gate open. After a set time, the microcontroller will reverse the polarity—effectively reversing the power—to cause the actuator to retract and close the gate.
Additional Components & Future Enhancements
I'm also planning to integrate several other smart home components to further enhance the automation setup:
- YETLEBOX Outdoor Waterproof Electrical Box Junction Box
A weatherproof, IP67 ABS plastic enclosure with mounting plate and wall bracket (5.9"x5.9"x3.5") to keep my wiring safe and organized. - NOYITO AC to DC Power Supply Module
A dual output industrial power module (DC 12V 8A, 5V 1A) to ensure a stable power supply for the system. - SwitchBot Smart Electric Motorized Blinds Kit - 3Pack
This kit, with 2.4G WiFi remote control, solar power, and compatibility with Alexa, Google Home, and Siri, will let me experiment with automating other parts of my home. Maybe an automation that opens the blinds so I can keep my eye on the mower. - SenseCAP Watcher for Mower Detection
A powerful monitoring device that can be configured to recognize specific objects and trigger alarms based on user-defined tasks. To enhance its object recognition capabilities, I’m leveraging custom models from the SenseCraft AI model repository. I've already hooked it up to llama3 and lava running locally, which should provide a robust framework for identifying when the mower is in position and ready to start. - 2 Channel DC 5V Relay Module with Optocoupler Relay Board
Compatible with Arduino, Raspberry Pi, and MEGA2560, this module will provide additional control for interfacing various components.
Programming the ESP32-C6
Once the hardware is set up, it’s time to get the code running on the ESP32-C6. Below is the code that powers the actuator control using HomeSpan and the ESP32-C6. This code manages WiFi connectivity, actuator control via relay pins, and polarity switching to open and close the gate.
How to Upload the Code:
-
Set Up Your Environment:
- Install the Arduino IDE (or use PlatformIO in VSCode).
- Install the ESP32 board definitions via the Board Manager—ensure your setup supports the ESP32-C6.
- Use the Library Manager to install required libraries like HomeSpan, Ticker, and any others needed.
-
Create a New Sketch:
- Open the Arduino IDE and create a new sketch (e.g.,
).MowerDoorActuator.ino
- Copy and paste the code below into your sketch.
- Open the Arduino IDE and create a new sketch (e.g.,
-
Select Your Board and Port:
- In the Tools menu, select the ESP32-C6 board and the appropriate COM port.
-
Compile and Upload:
- Click the Upload button. The IDE will compile the code and flash it onto the ESP32-C6’s onboard memory.
- Once uploaded, the board will automatically boot and run the code on startup.
Code:
#include "HomeSpan.h" #include "Arduino.h" #include "WiFi.h" #include "Ticker.h" // Define relay control pins #define RELAY1_PIN 19 // Controls one direction #define RELAY2_PIN 20 // Controls the other direction Ticker StopActuatorTicker; // WiFi Credentials "keyword">const char* ssid = "xxx WiFi"; "keyword">const char* password = "xxx123"; void connectToWiFi() { WiFi.begin(ssid, password); Serial.print("Connecting to WiFi"); "keyword">while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println("\nConnected to WiFi"); Serial.print("IP Address: "); Serial.println(WiFi.localIP()); } void extendActuator() { digitalWrite(RELAY1_PIN, LOW); digitalWrite(RELAY2_PIN, HIGH); } void retractActuator() { digitalWrite(RELAY1_PIN, HIGH); digitalWrite(RELAY2_PIN, LOW); } void stopActuator() { digitalWrite(RELAY1_PIN, HIGH); digitalWrite(RELAY2_PIN, HIGH); } struct ActuatorSwitch : Service::Switch { SpanCharacteristic *power; ActuatorSwitch() : Service::Switch() { power = new Characteristic::On(); } boolean update() override { StopActuatorTicker.detach(); // Cancel any previously scheduled stopActuator call "keyword">if (power->getNewVal()) { retractActuator(); StopActuatorTicker.once_ms(90 * 1000, stopActuator); } "keyword">else { extendActuator(); StopActuatorTicker.once_ms(90 * 1000, stopActuator); } "keyword">return true; } }; void setup() { Serial.begin(115200); connectToWiFi(); homeSpan.setPairingCode("83722189"); homeSpan.begin(Category::GarageDoorOpeners, "Mower Door"); pinMode(RELAY1_PIN, OUTPUT); pinMode(RELAY2_PIN, OUTPUT); stopActuator(); new SpanAccessory(); new Service::AccessoryInformation(); new Characteristic::Identify(); new Characteristic::Manufacturer("XXX"); new Characteristic::Model("MowerDoorActuator"); new Characteristic::SerialNumber("12345678"); new ActuatorSwitch(); } void loop() { homeSpan.poll(); } Next Steps Select the Right Actuator – I’ve chosen the VEVOR Linear Actuator "keyword">for its robust 12-inch stroke, high load capacity, and IP54 protection. Install the ESP32-C6 Microcontroller and Relay Board – I’ll set up a WiFi-enabled microcontroller alongside a dedicated relay board that simplifies polarity switching, ensuring seamless integration with Home Assistant. Mount and Wire the Actuator and Relay Board – Attach the actuator to the gate and connect it to the relay board. The use of a dedicated relay board improves reliability and safety by streamlining the switching process. Integrate Additional Components – I’ll set up the YETLEBOX enclosure and NOYITO power supply to ensure safe, reliable wiring, and later experiment with the SwitchBot blinds and SenseCAP Watcher "keyword">for expanded functionality. Create an Automation in Home Assistant – Configure a trigger so that when the lawn mower starts, the gate opens automatically and, after a set period, the polarity is reversed to close the gate. What I’m Looking Forward To This will be my first time working with Arduino and C++, and I’m excited to see how well the ESP32-C6 integration combined with a dedicated relay board works "keyword">for this kind of automation. With these additional components and improvements, I’m not only aiming "keyword">for a seamless gate operation but also planning to expand my smart home ecosystem—possibly even integrating smart blinds and enhanced mower detection "keyword">for a fully automated outdoor setup.