Add Smart Control to Your Awning with an ESP8266 and Home Assistant

By integrating an ESP8266 into our Becker Centronic awning remote, we have successfully automated our awning and enabled control within Home Assistant.

To automate the awning, we installed a USB-powered ESP8266 into the existing awning remote. This allows the remote to be triggered by the ESP8266, which adjusts the awning’s position. The microcontroller also powers the remote, eliminating the need for batteries and ensuring the system runs reliably and consistently. This not only saves you the hassle of constantly changing batteries, but it also reduces waste and helps to make your home more eco-friendly.

smart_awning

More details, Arduino code, and bill of materials can be found in our blog How to Add Smart Control to Your Awning with an ESP8266 and Home Assistant

1 Like

Can I see how you have the other side of your ESP8266 board wired up? Planning on a similar project to control a mosquito misting system.

Thanks for sharing, im trying to control a small fan doing the same and have a few questions. I my button has one pin on either side that provides a standard 5v and pressing the button seems to drop the voltage so this is normally closed but open with the button.
Would this work as you have connected this ? If so which lead did yo solder to ? I assume it doesn’t matter so long as it’s the connectors that interrupt the 5v signal ?
Thanks

Hello all,
Inspired by Freddie’s work, and having exactly the same awning remote control and also having exactly the same desire, to make my awning smart, I started to see if I could replicate this. I will, when all is finished, make a full report, but for now, the not so short version.

I started with the Wemos D1 mini as suggested by Freddie. I ended up buying all variants including the Pro, but none of the 6 variants would actually stay connected to my router. They would connect and … drop off again and then connect and so on. Turned out, these older boards can’t cope with ax / wifi6 / mesh networks. So that was 20 hours down the drain.
Then I looked for a esp32-C6 board which promised to be able to connect to wifi6. Another 20+ hours to get the esp-idf code up and running with Visual Studio Code. Jeej whoop whoop it connected!

Next up: open stop and close. Chatgpt was consulted and more hours later, I learned about push down or up buttons and all that stuff. Now I have code that, when in HA a button is pressed, for a second current is coming from a GPIO! Again a festive moment.

So I started to solder and tape and glue … first a test setup with a LED and that works. So GPIO → resistor → LED → GND.
When in HA the OPEN button is pushed, the LED comes on for a second.

But the awning, which I then tested, was not.

Chatgpt forgot to mention something like an optocoupler that does … magic.
There are youtube movies about this, please google them.
Finally, after buying many more stuff, Like different optocouplers (one tiny one with four legs and a bigger one with screw tight connecors), I GOT IT WORKING!!!

That is, I have a proof of concept.
One wire from a GPIO (18 in my case) to a diode into the optocoupler In1
One wire from the optocoupler G to GND on the ESP32
then on the other end of the optocoupler two wires that I was holding by one hand to the OPEN buttons 2 legs, then I pressed the button in HA and the awning was opening.

Now what I need to do is to find out how I’m all going to squeeze it something like a box that needs to be connected to the wires coming out of the rc.

Different than in Freddie’s example, I have 2 wires running to each button. Well not yet, but that is the setup. So it will be very crowded with wires. not sure yet how I’m going to do that. I like the idea of being able to disconnect that attachement box maybe?
Also, for now the esp32 board runs on USB C power. I need to figure out how to connect a battery and how I can make it charge without making the board explode.
And how to read the % empty/full of the battery and to display that in HA etc.

The summer will be way over when I have this finished.


image

image


Hi milsky99,
Fans usually don’t use encrypted IR signals. It is quite unlikely that with your remote, you would turn on all fans in the neighbourhood. So, try an IR blaster (aliexpress search for Tuya wifi smart IR remote control) first. That would make things easier.
In general, as I learned with my project to replicate the smart awning project, yes, you can make the esp32 board do a voltage drop or boost. So either it can be on continuously and off for a moment when the button is pushed, and the other way around (off continuously and on for a moment when you push a button).

My shopping list of what I have been using and some pictures of the lab setup:

ESP32-C6 ESP32-C6-DevKitC-1-N4 Development Board link

Hailege 2pcs PC817 4-Channel Optocoupler Insulation Module 817 Voltage Isolation Voltage Converter Module 3.6-30V Photoelectric Insulated Module

link

I chose this one as all 3 buttons need an optocoupler, this thing a) it screws the connecting wires in place which is nice and b) it is a 4 in 1. I know one too many, but it is a solid solution.

So far, when I push the OPEN button in HA, the LED on the optocoupler flashes shortly and then the LED ont the remote flashes and the awning actually opens.

This is NOT working for the STOP and CLOSE buttons for some awkward reason. It’s not the soldering, because when I short the + and - wires of the STOP or CLOSE button, the both function. Polarity I checked by switchin

ChatGPT suggest that the current could be “not enough” when the optocoupler is making the connection, but I doubt that, to be honest.

Any suggestions ???

The code has some flaws still.
For example as you can see, the % open is not yet properly displayed and there is more but here is what I have and what basically does what it needs to do: send a signal on a push in HA to a button on the remote and so operating the awning.

// main/awning_main.c
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_wifi.h"
#include "esp_event.h"
#include "nvs_flash.h"
#include "esp_log.h"
#include "esp_system.h"
#include "esp_err.h"
#include "secret.h"
#include "mqtt_client.h"
#include "driver/gpio.h" // Include the GPIO driver

#define TAG "awning_example"
#define GPIO_OPEN 18
#define GPIO_STOP 19
#define GPIO_CLOSE 21

static esp_mqtt_client_handle_t client;

// Event handler for catching system events
static void event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) {
    if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) {
        esp_wifi_connect();
    } else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) {
        esp_wifi_connect();
        ESP_LOGI(TAG, "Retry to connect to the AP");
    } else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
        ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data;
        ESP_LOGI(TAG, "got ip:" IPSTR, IP2STR(&event->ip_info.ip));
    }
}

void wifi_init_sta(void) {
    esp_netif_init();
    esp_event_loop_create_default();
    esp_netif_create_default_wifi_sta();

    wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
    esp_wifi_init(&cfg);

    esp_event_handler_instance_t instance_any_id;
    esp_event_handler_instance_t instance_got_ip;
    esp_event_handler_instance_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL, &instance_any_id);
    esp_event_handler_instance_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL, &instance_got_ip);

    wifi_config_t wifi_config = {
        .sta = {
            .ssid = WIFI_SSID,
            .password = WIFI_PASSWORD,
            .threshold.authmode = WIFI_AUTH_WPA2_PSK,
        },
    };

    esp_wifi_set_mode(WIFI_MODE_STA);
    esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config);
    esp_wifi_start();

    ESP_LOGI(TAG, "wifi_init_sta finished.");
    ESP_LOGI(TAG, "connect to ap SSID:%s password:%s", WIFI_SSID, WIFI_PASSWORD);
}

static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data) {
    esp_mqtt_event_handle_t event = event_data;
    client = event->client;
    switch (event_id) {
        case MQTT_EVENT_CONNECTED:
            ESP_LOGI(TAG, "MQTT_EVENT_CONNECTED");
            esp_mqtt_client_subscribe(client, "home/awning/set", 0);
            break;
        case MQTT_EVENT_DISCONNECTED:
            ESP_LOGI(TAG, "MQTT_EVENT_DISCONNECTED");
            break;
        case MQTT_EVENT_DATA:
            ESP_LOGI(TAG, "MQTT_EVENT_DATA");
            if (strncmp(event->topic, "home/awning/set", event->topic_len) == 0) {
                if (strncmp(event->data, "open", event->data_len) == 0) {
                    gpio_set_level(GPIO_OPEN, 1);
                    vTaskDelay(1000 / portTICK_PERIOD_MS);
                    gpio_set_level(GPIO_OPEN, 0);
                } else if (strncmp(event->data, "stop", event->data_len) == 0) {
                    gpio_set_level(GPIO_STOP, 1);
                    vTaskDelay(1000 / portTICK_PERIOD_MS);
                    gpio_set_level(GPIO_STOP, 0);
                } else if (strncmp(event->data, "close", event->data_len) == 0) {
                    gpio_set_level(GPIO_CLOSE, 1);
                    vTaskDelay(1000 / portTICK_PERIOD_MS);
                    gpio_set_level(GPIO_CLOSE, 0);
                }
            }
            break;
        default:
            break;
    }
}

void mqtt_app_start(void) {
esp_mqtt_client_config_t mqtt_cfg = {
    .broker = {
        .address.uri = MQTT_BROKER_URI,
    },
    .credentials = {
        .username = MQTT_USER,
        .authentication = {
            .password = MQTT_PASSWORD,
        }
    }
};

    client = esp_mqtt_client_init(&mqtt_cfg);
    esp_mqtt_client_register_event(client, ESP_EVENT_ANY_ID, mqtt_event_handler, client);
    esp_mqtt_client_start(client);
}

void app_main(void) {
    esp_err_t ret = nvs_flash_init();
    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
        ESP_ERROR_CHECK(nvs_flash_erase());
        ret = nvs_flash_init();
    }
    ESP_ERROR_CHECK(ret);

    wifi_init_sta();

    gpio_reset_pin(GPIO_OPEN);
    gpio_set_direction(GPIO_OPEN, GPIO_MODE_OUTPUT);
    gpio_reset_pin(GPIO_STOP);
    gpio_set_direction(GPIO_STOP, GPIO_MODE_OUTPUT);
    gpio_reset_pin(GPIO_CLOSE);
    gpio_set_direction(GPIO_CLOSE, GPIO_MODE_OUTPUT);

    mqtt_app_start();
}