DIY Home Automation Project: Remote On-Off Button for Easy Access to Switches

DIY Home Automation Project: Remote On-Off Button for Easy Access to Switches

As parents, we understand the importance of creating a safe and accessible environment for our children. However, there are times when certain aspects of our homes may not be designed with their convenience in mind. One common issue is when switches are placed too high up, making it difficult for little ones to reach and operate them independently. But fear not! In this article, we’ll explore a simple and innovative DIY home automation project that utilizes Arduino, Home Assistant, and Broadlink to create a remote on-off button. Say goodbye to the frustration of unreachable switches and empower your child with the ability to control lights and devices effortlessly.

Understanding the Technical Design

To achieve our goal, we’ll be using the following components:

  1. Arduino: A microcontroller board that serves as the brain of our project. It allows us to read inputs and control outputs based on programmed instructions. You can also use another WiFi-equipped board, such as ESP8266-based boards (like the WEMOS).
  2. Push Button: This component acts as a trigger, allowing your child to easily turn the switch on or off with a simple press.
  3. Broadlink: A smart home device that can send infrared or RF signals to control various appliances. We’ll utilize its capabilities to interact with the switch.
  4. Home Assistant: An open-source home automation platform that integrates various smart devices, allowing us to control and manage them from a central hub.

Project Implementation

  1. Wiring: Connect the push button to the Arduino following the specified pin configurations. Ensure that the connections are secure and double-check the wiring to avoid any potential issues.
  2. Arduino Programming: Write a code that reads the input from the push button and sends a corresponding API call to Home Assistant whenever the button is pressed. This API call will trigger the action to toggle the switch connected to the Broadlink device.
  3. Home Assistant Configuration: Set up Home Assistant on your preferred device (e.g., Raspberry Pi, computer, or NAS). Integrate the Broadlink device into Home Assistant and configure it to control the switch you want to automate.
  4. API Call Integration: In Home Assistant, create an automation that listens for the API call triggered by the Arduino. When the call is received, configure it to toggle the state of the corresponding switch. This way, pressing the button will send the API call to Home Assistant, effectively turning the switch on or off.
  5. Testing and Fine-Tuning: Once everything is set up, test the system to ensure the remote on-off button works as expected. Make any necessary adjustments or refinements to the code or configuration if needed.

Example of the code

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>

const char* ssid = "SSID";
const char* password = "SSID-PASSWORD";
String serverName = "http://<SERVER-NAME>/api/services/switch/";
String authBearer = "ABCDEFG";
String entity = "switch.test";
const int button = 5;

int state = LOW;      // the current state of the output pin
int lastButtonState;    // the previous state of button
int currentButtonState; // the current state of button

void setup() {
    Serial.begin(9600); 
    pinMode(button, INPUT_PULLUP);
    WiFi.begin(ssid, password);
    Serial.println("Connecting");
    while(WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
    }
    Serial.println("");
    Serial.print("Connected to WiFi network with IP Address: ");
    Serial.println(WiFi.localIP()); 
}

void loop() {
    lastButtonState    = currentButtonState;  // save the last state
    currentButtonState = digitalRead(button); // read new state
  
    if(lastButtonState == HIGH && currentButtonState == LOW) {
        Serial.println("The button is pressed");
        // toggle state of LED
        state = !state;

        if(WiFi.status()== WL_CONNECTED){
            WiFiClient client;
            HTTPClient http;
            String serverPath = serverName;
            if (state) {
                serverPath += "turn_on";
            } else {
                serverPath += "turn_off";
            }
      
            http.begin(client, serverPath.c_str());
            http.addHeader("Authorization", "Bearer " + authBearer);
            http.addHeader("Content-Type", "application/json");
            int httpResponseCode = http.POST("{\"entity_id\": \""+entity+"\"}");
      
            if (httpResponseCode>0) {
                Serial.print("HTTP Response code: ");
                Serial.println(httpResponseCode);
            }  else {
                Serial.print("Error code: ");
                Serial.println(httpResponseCode);
            }
            // Free resources
            http.end();
        } else {
            Serial.println("WiFi Disconnected");
        }
    }
    delay(200);   
}

By undertaking this DIY home automation project, you can provide your child with the power to control switches that were previously out of their reach. The combination of Arduino, Home Assistant, and Broadlink allows for a seamless and convenient solution. Not only does this project make your child’s life easier, but it also teaches them about technology, problem-solving, and creative thinking.

Remember to prioritize safety throughout the process by ensuring proper electrical connections and supervising your child’s interaction with the remote on-off button. With a little effort and ingenuity, you can transform your home into a more accessible and child-friendly environment. So, say goodbye to those high-up switches and empower your child to take control with this fantastic DIY home automation project!