Converting ESP32 Arduino IDE sketches to ESPHOME code

I have an off-grid battery backup system at my home. It is located in the upstairs of my home and once the grid power is failed, the off-grid inverter automatically takes over the power supply to the home. To indicate the source of the power supply, there are 2 panel lights fixed on the instrument panel where the automatic transfer switch is located. The red light indicates the grid power and the green light indicates the battery backup power. These lights are lit whenever the home uses the respective power source. (only one power source is used at a time).

As this mechanism is located upstairs in my house, when we are on the ground floor, it is a little confusing to determine which power source is in use. Therefore, I decided to use two ESP-WROOM-32 modules to indicate the power source for the ground floor. Here, one ESP32 is acting as the transmitter (located upstairs) and the other one as the receiver (downstairs). The receiver acts as a web server and the transmitter pushes the status of the grid power supply to the receiver. (Here I used a relay to detect the availability of the electricity in the grid supply). Codes of both the transmitter and the receiver are given below.

A. Transmitter:

#include <WiFi.h>
#include <HTTPClient.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

const char* ssid = “WiFi-SSID”;
const char* password = “PASSWORD”;
const char* receiverIP = "192.168.0.70";  // Receiver's static IP

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET    -1
#define SCREEN_ADDRESS 0x3C // Address of the OLED screen
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

const int buttonPin = 4;
const int ledPin = 13;
const int ledPinG = 2; 
bool lastButtonState = LOW;

// Image of a battery
static const uint8_t image_battery[1024] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x07, 0x8f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x07, 0x8f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x07, 0x8f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x0f, 0x8f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x1f, 0x8f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x3f, 0x8f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x3f, 0x0f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x38, 0x0f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x38, 0x0f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x38, 0x0f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x38, 0x0f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x38, 0x0f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x38, 0x0f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x38, 0x0f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x38, 0x0f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x38, 0x0f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x38, 0x0f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x38, 0x0f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x3c, 0x0f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x3f, 0x8f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x3f, 0x8f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x1f, 0x8f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x07, 0x8f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x07, 0x8f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x07, 0x8f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x07, 0x8f, 0xff, 0x8f, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

// Image of a high tension power post 
static const uint8_t image_electric_pole[1024] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x01, 0xc0, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x03, 0xe0, 0x00, 0x07, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x0f, 0x80, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x0f, 0x80, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x0f, 0x80, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x1f, 0x80, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x1b, 0x80, 0x00, 0x37, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x80, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x1b, 0x80, 0x00, 0x37, 0x00, 0x00, 0x00, 0x03, 0xff, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x3b, 0x80, 0x00, 0x77, 0x00, 0x00, 0x00, 0x1f, 0xee, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x3b, 0x80, 0x00, 0x67, 0x00, 0x00, 0x01, 0xfe, 0x0e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x33, 0x80, 0x00, 0xe7, 0x00, 0x00, 0x1f, 0xf0, 0x1c, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x73, 0x80, 0x00, 0xe7, 0x00, 0x00, 0xff, 0xf0, 0x38, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x73, 0x80, 0x00, 0xc7, 0x00, 0x07, 0xfb, 0xf0, 0x38, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x63, 0x80, 0x01, 0xc7, 0x00, 0x3f, 0xc7, 0xb0, 0x70, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0xe3, 0x80, 0x01, 0xc7, 0x03, 0xfc, 0x0e, 0x30, 0xe0, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0xe3, 0x80, 0x03, 0x87, 0x3f, 0xf0, 0x1c, 0x30, 0xc0, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0xc3, 0x80, 0x03, 0x87, 0xff, 0xf0, 0x38, 0x31, 0xc0, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x01, 0xc3, 0x80, 0x03, 0xff, 0xf3, 0xb0, 0x70, 0x33, 0x80, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x01, 0xc3, 0x8f, 0xff, 0xff, 0x8f, 0x30, 0xf0, 0x33, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xe7, 0x1e, 0x31, 0xc0, 0x37, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x01, 0xff, 0xfe, 0x3f, 0x07, 0x3c, 0x33, 0x80, 0x3e, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x01, 0x83, 0xe0, 0x7f, 0x07, 0x70, 0x37, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x01, 0x83, 0xf8, 0xf7, 0x07, 0xe0, 0x3e, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x01, 0x83, 0xbf, 0xc7, 0x07, 0xc0, 0x3e, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x01, 0x83, 0x9f, 0x87, 0x07, 0x80, 0x38, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x01, 0x83, 0x9f, 0x87, 0x07, 0x80, 0x38, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x01, 0x83, 0xbf, 0xc7, 0x07, 0xc0, 0x3c, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x01, 0x83, 0xf8, 0xf7, 0x07, 0xe0, 0x3e, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x01, 0x83, 0xf0, 0x7f, 0x07, 0x70, 0x37, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x01, 0xff, 0xfe, 0x3f, 0x07, 0x3c, 0x33, 0x80, 0x3e, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xe7, 0x1e, 0x31, 0xc0, 0x37, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x01, 0xc3, 0x8f, 0xff, 0xff, 0x8f, 0x30, 0xe0, 0x33, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x01, 0xc3, 0x80, 0x07, 0xff, 0xf3, 0xb0, 0x70, 0x33, 0x80, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0xc3, 0x80, 0x03, 0x87, 0xff, 0xf0, 0x38, 0x31, 0xc0, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0xe3, 0x80, 0x03, 0x87, 0x3f, 0xf0, 0x1c, 0x30, 0xc0, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0xe3, 0x80, 0x01, 0xc7, 0x03, 0xfc, 0x0e, 0x30, 0xe0, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x63, 0x80, 0x01, 0xc7, 0x00, 0x3f, 0xc7, 0x30, 0x70, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x73, 0x80, 0x00, 0xc7, 0x00, 0x07, 0xfb, 0xf0, 0x38, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x73, 0x80, 0x00, 0xe7, 0x00, 0x00, 0xff, 0xf0, 0x38, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x33, 0x80, 0x00, 0xe7, 0x00, 0x00, 0x1f, 0xf0, 0x1c, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x3b, 0x80, 0x00, 0x67, 0x00, 0x00, 0x01, 0xfe, 0x0c, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x3b, 0x80, 0x00, 0x77, 0x00, 0x00, 0x00, 0x3f, 0xee, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x1b, 0x80, 0x00, 0x37, 0x00, 0x00, 0x00, 0x03, 0xff, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x1b, 0x80, 0x00, 0x37, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x80, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x1f, 0x80, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x80, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x0f, 0x80, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x0f, 0x80, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x0f, 0x80, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x03, 0xe0, 0x00, 0x07, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x01, 0xc0, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

void setup() {
  Serial.begin(115200);
  
  // Set pin modes
  pinMode(buttonPin, INPUT_PULLUP);
  pinMode(ledPin, OUTPUT);	// Red LED (Grid power on)
  pinMode(ledPinG, OUTPUT);	// Green LED (Battery power on)

  // Initialize OLED display
  if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
    Serial.println(F("SSD1306 allocation failed"));
  }
  delay(2000); // alowe 2s to initialise the display
  display.clearDisplay(); 
  
  // Connect to Wi-Fi
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
  }
  Serial.println("Connected to WiFi");
}

void loop() {
  bool buttonState = digitalRead(buttonPin);

  // Check if the button state has changed
  if (buttonState != lastButtonState) {
    lastButtonState = buttonState;

    // Update local LED
    digitalWrite(ledPin, buttonState ? HIGH : LOW);
    digitalWrite(ledPinG, buttonState ? LOW : HIGH);

    // Display image based on button state
    if (buttonState) {
      display.clearDisplay();
      display.drawBitmap(0, 0, image_electric_pole, 128, 64, 1); // Grid power
      display.display();
    } else {
      display.clearDisplay();
      display.drawBitmap(0, 0, image_battery, 128, 64, 1); // Battery power
      display.display();
    }

    // Send HTTP request to receiver
    if (WiFi.status() == WL_CONNECTED) {
      HTTPClient http;
      String url = String("http://") + receiverIP + "/setLED?state=" + (buttonState ? "1" : "0");
      http.begin(url);
      int httpResponseCode = http.GET();
      if (httpResponseCode > 0) {
        Serial.println("Sent request to receiver successfully.");
      } else {
        Serial.print("Error in sending request: ");
        Serial.println(httpResponseCode);
      }
      http.end();
    } else {
      Serial.println("WiFi not connected");
    }
  }
  
  delay(100);  // Debounce delay

B. Receiver:

#include <WiFi.h>
#include <WebServer.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

const char* ssid = "WiFi-SSID";
const char* password = "PASSWORD";

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET    -1
#define SCREEN_ADDRESS 0x3C
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

const int ledPin = 13;
const int ledPinG = 2;
WebServer server(80);

// Image of a battery
static const uint8_t image_battery[1024] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x07, 0x8f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x07, 0x8f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x07, 0x8f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x0f, 0x8f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x1f, 0x8f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x3f, 0x8f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x3f, 0x0f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x38, 0x0f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x38, 0x0f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x38, 0x0f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x38, 0x0f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x38, 0x0f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x38, 0x0f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x38, 0x0f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x38, 0x0f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x38, 0x0f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x38, 0x0f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x38, 0x0f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x3c, 0x0f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x3f, 0x8f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x3f, 0x8f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x1f, 0x8f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x07, 0x8f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x07, 0x8f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x07, 0x8f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x07, 0x8f, 0xff, 0x8f, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

// Image of a high tension power post 
static const uint8_t image_electric_pole[1024] = {
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x01, 0xc0, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x03, 0xe0, 0x00, 0x07, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x0f, 0x80, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x0f, 0x80, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x0f, 0x80, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x1f, 0x80, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x1b, 0x80, 0x00, 0x37, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x80, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x1b, 0x80, 0x00, 0x37, 0x00, 0x00, 0x00, 0x03, 0xff, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x3b, 0x80, 0x00, 0x77, 0x00, 0x00, 0x00, 0x1f, 0xee, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x3b, 0x80, 0x00, 0x67, 0x00, 0x00, 0x01, 0xfe, 0x0e, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x33, 0x80, 0x00, 0xe7, 0x00, 0x00, 0x1f, 0xf0, 0x1c, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x73, 0x80, 0x00, 0xe7, 0x00, 0x00, 0xff, 0xf0, 0x38, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x73, 0x80, 0x00, 0xc7, 0x00, 0x07, 0xfb, 0xf0, 0x38, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x63, 0x80, 0x01, 0xc7, 0x00, 0x3f, 0xc7, 0xb0, 0x70, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0xe3, 0x80, 0x01, 0xc7, 0x03, 0xfc, 0x0e, 0x30, 0xe0, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0xe3, 0x80, 0x03, 0x87, 0x3f, 0xf0, 0x1c, 0x30, 0xc0, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0xc3, 0x80, 0x03, 0x87, 0xff, 0xf0, 0x38, 0x31, 0xc0, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x01, 0xc3, 0x80, 0x03, 0xff, 0xf3, 0xb0, 0x70, 0x33, 0x80, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x01, 0xc3, 0x8f, 0xff, 0xff, 0x8f, 0x30, 0xf0, 0x33, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xe7, 0x1e, 0x31, 0xc0, 0x37, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x01, 0xff, 0xfe, 0x3f, 0x07, 0x3c, 0x33, 0x80, 0x3e, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x01, 0x83, 0xe0, 0x7f, 0x07, 0x70, 0x37, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x01, 0x83, 0xf8, 0xf7, 0x07, 0xe0, 0x3e, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x01, 0x83, 0xbf, 0xc7, 0x07, 0xc0, 0x3e, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x01, 0x83, 0x9f, 0x87, 0x07, 0x80, 0x38, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x01, 0x83, 0x9f, 0x87, 0x07, 0x80, 0x38, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x01, 0x83, 0xbf, 0xc7, 0x07, 0xc0, 0x3c, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x01, 0x83, 0xf8, 0xf7, 0x07, 0xe0, 0x3e, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x01, 0x83, 0xf0, 0x7f, 0x07, 0x70, 0x37, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x01, 0xff, 0xfe, 0x3f, 0x07, 0x3c, 0x33, 0x80, 0x3e, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xe7, 0x1e, 0x31, 0xc0, 0x37, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x01, 0xc3, 0x8f, 0xff, 0xff, 0x8f, 0x30, 0xe0, 0x33, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x01, 0xc3, 0x80, 0x07, 0xff, 0xf3, 0xb0, 0x70, 0x33, 0x80, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0xc3, 0x80, 0x03, 0x87, 0xff, 0xf0, 0x38, 0x31, 0xc0, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0xe3, 0x80, 0x03, 0x87, 0x3f, 0xf0, 0x1c, 0x30, 0xc0, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0xe3, 0x80, 0x01, 0xc7, 0x03, 0xfc, 0x0e, 0x30, 0xe0, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x63, 0x80, 0x01, 0xc7, 0x00, 0x3f, 0xc7, 0x30, 0x70, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x73, 0x80, 0x00, 0xc7, 0x00, 0x07, 0xfb, 0xf0, 0x38, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x73, 0x80, 0x00, 0xe7, 0x00, 0x00, 0xff, 0xf0, 0x38, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x33, 0x80, 0x00, 0xe7, 0x00, 0x00, 0x1f, 0xf0, 0x1c, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x3b, 0x80, 0x00, 0x67, 0x00, 0x00, 0x01, 0xfe, 0x0c, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x3b, 0x80, 0x00, 0x77, 0x00, 0x00, 0x00, 0x3f, 0xee, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x1b, 0x80, 0x00, 0x37, 0x00, 0x00, 0x00, 0x03, 0xff, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x1b, 0x80, 0x00, 0x37, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x80, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x1f, 0x80, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x80, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x0f, 0x80, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x0f, 0x80, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x0f, 0x80, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x03, 0xe0, 0x00, 0x07, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x01, 0xc0, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

void handleSetLED() {
  if (server.hasArg("state")) {
    int state = server.arg("state").toInt();
    digitalWrite(ledPin, state == 1 ? HIGH : LOW);
    digitalWrite(ledPinG, state == 1 ? LOW : HIGH);

    // Update display based on received state
    if (state == 1) {
      display.clearDisplay();
      display.drawBitmap(0, 0, image_electric_pole, 128, 64, 1); //Grid power
      display.display();
    } else {
      display.clearDisplay();
      display.drawBitmap(0, 0, image_battery, 128, 64, 1); // Battery power
      display.display();
    }

    server.send(200, "text/plain", "LED state set");
    Serial.println("LED state changed by transmitter");
  } else {
    server.send(400, "text/plain", "Bad request");
  }
}

void setup() {
  Serial.begin(115200);
  
  // Set pin modes
  pinMode(ledPin, OUTPUT);
  pinMode(ledPinG, OUTPUT);

  // Initialize OLED display
  if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
    Serial.println(F("SSD1306 allocation failed"));
  }
  delay(2000); // alowe 2s to initialise the display
  display.clearDisplay();
  
  // Connect to Wi-Fi
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...")
  }
  Serial.println("Connected to WiFi");

  // Configure server routes
  server.on("/setLED", handleSetLED);
  server.begin();
}

void loop() {
  server.handleClient();
}

Both these sketches worked fine when I flashed the ESP32 modules with Arduino IDE. (Each ESP32 has 128x64 OLED displays and they show a battery or a high-tension power post respectively).

Now I want to do the same after connecting both ESP32 modules with ESPHOME. As I’m not used to coding in yml format, can anyone help me convert the above two sketches to ESPHOME codes?

Thank you.

You could leave the transmitter code as it is.
So start building the receiver.
You need web_server component, two gpio switches for example for LEDs and display component.

1 Like

Thank you Karosm.
I read the documents you shared and some other documents as well, and I could develop the code for the receiver. However, it seems the code I wrote is not working properly even though it is uploaded to the ESP32 through ESPHome.

The code is given below.

substitutions:
  name: esphome-web-356990
  friendly_name: Power_state_receiver

esphome:
  name: ${name}
  friendly_name: ${friendly_name}
  min_version: 2024.6.0
  name_add_mac_suffix: false
  project:
    name: esphome.web
    version: dev

esp32:
  board: esp32dev
  framework:
    type: arduino

wifi:
  ssid: “WiFi-SSID”
  password: "PASSWORD"

  # Optional manual IP
  manual_ip:
    static_ip: 192.168.0.70
    gateway: 192.168.0.1
    subnet: 255.255.255.0

# Allow provisioning Wi-Fi via serial
improv_serial:

# In combination with the `ap` this allows the user
# to provision wifi credentials to the device via WiFi AP.
captive_portal:

dashboard_import:
  package_import_url: github://esphome/example-configs/esphome-web/esp32.yaml@main
  import_full_config: true

# Sets up Bluetooth LE (Only on ESP32) to allow the user
# to provision wifi credentials to the device.
esp32_improv:
  authorizer: none



# Enable Home Assistant API
api:
  services:
    # Service to control the display's image based on trigger
    - service: set_display
      variables:
        show_battery: bool
      then:
        - if:
            condition:
              lambda: 'return show_battery;'
            then:
              - display.page.show: battery_image
            else:
              - display.page.show: electric_pole_image

ota:
- platform: esphome

# Enable Web Server for additional access
web_server:
  port: 80

logger:

# GPIO pin configurations
output:
  - platform: gpio
    pin: 13
    id: led_red
  - platform: gpio
    pin: 2
    id: led_green

# OLED Display setup
i2c:
  sda: 21
  scl: 22
  scan: true

font:
  - file: "fonts/Roboto-Regular.ttf"
    id: font1
    size: 16

display:
  - platform: ssd1306_i2c
    model: "SSD1306 128x64"
    rotation: 0
    address: 0x3C
    id: oled_display
    pages:
      - id: battery_image
        lambda: |-
          it.fill(COLOR_OFF);  
          it.image(0, 0, id(battery_icon));
      - id: electric_pole_image
        lambda: |-
          it.fill(COLOR_OFF);  
          it.image(0, 0, id(electric_pole_icon));

# Battery icon image definition
image:
  - file: "Images/battery_icon.png"
    id: battery_icon
    type: BINARY

# Electric pole icon image definition
  - file: "Images/electric_pole_icon.png"
    id: electric_pole_icon
    type: BINARY

Both images are 128x64 pixel png files.

Could you please help me correct the issue in my code?

Thank you so much.

I would start with some simple code just for web server and switches.
Is this your first Esphome project?

Try this. Mod your wifi credentials.
Flash it and observe if errors.
Open webserver on your browser (192.168.0.70)
Try the switches.

substitutions:
  name: esphome-web-356990
  friendly_name: Power_state_receiver

esphome:
  name: ${name}
  friendly_name: ${friendly_name}
  min_version: 2024.6.0
 

esp32:
  board: esp32dev
  framework:
    type: arduino

wifi:
  ssid: “WiFi-SSID”
  password: "PASSWORD"

  # Optional manual IP
  manual_ip:
    static_ip: 192.168.0.70
    gateway: 192.168.0.1
    subnet: 255.255.255.0

captive_portal:

api:

ota:
- platform: esphome

# Enable Web Server for additional access
web_server:
  port: 80

logger:

# GPIO pin configurations
switch:
  - platform: gpio
    pin: 13
    id: led_red
  - platform: gpio
    pin: 2
    id: led_green

# OLED Display setup
i2c:
  sda: 21
  scl: 22
  scan: true

font:
  - file: "fonts/Roboto-Regular.ttf"
    id: font1
    size: 16

display:
  - platform: ssd1306_i2c
    model: "SSD1306 128x64"
    rotation: 0
    address: 0x3C
    id: oled_display
    lambda: |-
      it.print(0, 0, id(font1), "Hello World!");
1 Like

Thank you Karosm.
Yes. This is my first code in Esphome. But I felt the state of it and I’m happy to learn it.
I’ll flash the code and let you know the results by today evening.

Yes. the code works and shows the “Hello Wold” in the display.

And web server? Toggling LEDs?

That part doesn’t work. LEDs are not lit at all.

Don’t make me pump…
Are you able to enter in web server UI with your browser??

Yes. I can access the server UI.

Just missing the switches…
Try to give them a name:

Still the same. No LEDs came up.

Try this, I just added two other type of switches for testing…

Do you get some warnings when you compile the code?

1 Like

No warnings while compiling the code. Code was successfully flashed and all 4 switches are working.

# GPIO pin configurations
#switch:
 # - platform: gpio
  #  pin: 13
  # id: led_red
  # name: "redSwitch"
 # - platform: gpio
  #  pin: 2
  #  id: led_green
  #  name: "greenSwitch"

switch:
  - platform: gpio
    pin: GPIO13
    id: led_red
    name: "redSwitch"
  - platform: gpio
    pin: GPIO2
    id: led_green
    name: "greenSwitch"
  - platform: template
    name: "Test template"
    id: testswitch
    optimistic: True
  - platform: restart
    name: "X RESTART"

No idea why it didn’t show the switches before?
Ok, try the images and display like you had on your first trial.
You have to have Images folder is same folder with your yaml.

Then modify your transmitter Arduino sketch to make a POST request.
You could put IF condition for the buttonState to post either /led_red/turn_on or turn_off

 if(WiFi.status()== WL_CONNECTED){   //Check WiFi connection status
  
   HTTPClient http; 
// make condition for either turn_on or turn_off
   String url = "http://192.168.0.70/switch/led_red/turn_on";
   String url = "http://192.168.0.70/switch/led_red/turn_off";
  
   http.begin(url);  //Specify destination for HTTP request
   http.addHeader("Content-Type", "text/plain");             //Specify content-type header
   int httpResponseCode = http.POST("POSTING from ESP32");   //Send the actual POST request, nothing in this case
    
   http.end();
1 Like

Thank you. Before going into icons, I tested LED status change with the button press.

void loop() {
  bool buttonState = digitalRead(buttonPin);
  String led = ""; 

  // Check if the button state has changed
  if (buttonState != lastButtonState) {
    lastButtonState = buttonState;

    // Turn on LED locally if button is pressed
    digitalWrite(ledPin, buttonState ? HIGH : LOW);
    digitalWrite(ledPinG, buttonState ? LOW : HIGH); 

    // Send HTTP request to receiver
    if(WiFi.status()== WL_CONNECTED){
      if (lastButtonState == HIGH) {
        led = "turn_on";
      }else {
        led = "turn_off";
      }
      Serial.print("LED : ");
      Serial.println(led);

      HTTPClient http; 
      String url = String("http://") + receiverIP + "/switch/greenSwitch/" + (led); 
      http.begin(url);
      http.addHeader("Content-Type", "text/plain"); 
      int httpResponseCode = http.POST("POSTING from ESP32");
      if (httpResponseCode > 0) {
        Serial.println("Sent request to receiver successfully.");
        Serial.print("URL : ");
      Serial.println(url);
      } else {
        Serial.print("Error in sending request: ");
        Serial.println(httpResponseCode);
      }
      http.end();
    } else {
      Serial.println("WiFi not connected");
    }
  }
  delay(100);  // Debounce delay
}

This generates a correct URL.

LED : turn_off
Sent request to receiver successfully.
URL : http://192.168.0.70/switch/greenSwitch/turn_off
LED : turn_on
Sent request to receiver successfully.
URL : http://192.168.0.70/switch/greenSwitch/turn_on

But it does not change the LED status in the receiver. BUT, once I copy the generated URL and send it through the web browser in my PC, it changes the LED state like a charm!.

Could you please point me out what is wrong in the code?

I don’t see anything wrong in your code. (Neither I understand why the gpio switch didn’t show up at the beginning…)
Try with fixed url like I posted.
Increase delay().

PS. on this forum if you replay to specific post, the person who wrote it receives notification.
If you reply to the topic , no-one receives notification.

1 Like

Thank you. And sorry for the delay in reply.
Finally, I could both the transmitter and receiver got into with your help. As the POST method did not work for me, I had to use the GET method to send the HTTP command. Now both work as expected. I’ll include both codes here for anyone with a similar requirement.

1.) Transmitter: (code for ESP32 in Arduino IDE)

#include <WiFi.h>
#include <HTTPClient.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

const char* ssid = "*********";
const char* password = "*************";
const char* receiverIP = "192.168.0.70";  // Receiver's static IP

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET    -1
#define SCREEN_ADDRESS 0x3C // Address of the OLED screen
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

const int buttonPin = 4;
const int redLedPin = 13;
const int geenLedPin = 27; 
bool lastButtonState = LOW;

static const uint8_t image_battery[1024] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x07, 0x8f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x07, 0x8f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x07, 0x8f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x0f, 0x8f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x1f, 0x8f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x3f, 0x8f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x3f, 0x0f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x38, 0x0f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x38, 0x0f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x38, 0x0f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x38, 0x0f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x38, 0x0f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x38, 0x0f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x38, 0x0f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x38, 0x0f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x38, 0x0f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x38, 0x0f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x38, 0x0f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x3c, 0x0f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x3f, 0x8f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x3f, 0x8f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x1f, 0x8f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x07, 0x8f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x07, 0x8f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x07, 0x8f, 0xff, 0xcf, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x07, 0x8f, 0xff, 0x8f, 0xff, 0x9f, 0xff, 0x1f, 0xff, 0x1e, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

static const uint8_t image_electric_pole[1024] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x01, 0xc0, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x03, 0xe0, 0x00, 0x07, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x0f, 0x80, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x0f, 0x80, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x0f, 0x80, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x1f, 0x80, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x1b, 0x80, 0x00, 0x37, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x80, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x1b, 0x80, 0x00, 0x37, 0x00, 0x00, 0x00, 0x03, 0xff, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x3b, 0x80, 0x00, 0x77, 0x00, 0x00, 0x00, 0x1f, 0xee, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x3b, 0x80, 0x00, 0x67, 0x00, 0x00, 0x01, 0xfe, 0x0e, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x33, 0x80, 0x00, 0xe7, 0x00, 0x00, 0x1f, 0xf0, 0x1c, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x73, 0x80, 0x00, 0xe7, 0x00, 0x00, 0xff, 0xf0, 0x38, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x73, 0x80, 0x00, 0xc7, 0x00, 0x07, 0xfb, 0xf0, 0x38, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x63, 0x80, 0x01, 0xc7, 0x00, 0x3f, 0xc7, 0xb0, 0x70, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0xe3, 0x80, 0x01, 0xc7, 0x03, 0xfc, 0x0e, 0x30, 0xe0, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0xe3, 0x80, 0x03, 0x87, 0x3f, 0xf0, 0x1c, 0x30, 0xc0, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0xc3, 0x80, 0x03, 0x87, 0xff, 0xf0, 0x38, 0x31, 0xc0, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x01, 0xc3, 0x80, 0x03, 0xff, 0xf3, 0xb0, 0x70, 0x33, 0x80, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x01, 0xc3, 0x8f, 0xff, 0xff, 0x8f, 0x30, 0xf0, 0x33, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xe7, 0x1e, 0x31, 0xc0, 0x37, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x01, 0xff, 0xfe, 0x3f, 0x07, 0x3c, 0x33, 0x80, 0x3e, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x01, 0x83, 0xe0, 0x7f, 0x07, 0x70, 0x37, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x01, 0x83, 0xf8, 0xf7, 0x07, 0xe0, 0x3e, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x01, 0x83, 0xbf, 0xc7, 0x07, 0xc0, 0x3e, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x01, 0x83, 0x9f, 0x87, 0x07, 0x80, 0x38, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x01, 0x83, 0x9f, 0x87, 0x07, 0x80, 0x38, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x01, 0x83, 0xbf, 0xc7, 0x07, 0xc0, 0x3c, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x01, 0x83, 0xf8, 0xf7, 0x07, 0xe0, 0x3e, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x01, 0x83, 0xf0, 0x7f, 0x07, 0x70, 0x37, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x01, 0xff, 0xfe, 0x3f, 0x07, 0x3c, 0x33, 0x80, 0x3e, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xe7, 0x1e, 0x31, 0xc0, 0x37, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x01, 0xc3, 0x8f, 0xff, 0xff, 0x8f, 0x30, 0xe0, 0x33, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x01, 0xc3, 0x80, 0x07, 0xff, 0xf3, 0xb0, 0x70, 0x33, 0x80, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0xc3, 0x80, 0x03, 0x87, 0xff, 0xf0, 0x38, 0x31, 0xc0, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0xe3, 0x80, 0x03, 0x87, 0x3f, 0xf0, 0x1c, 0x30, 0xc0, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0xe3, 0x80, 0x01, 0xc7, 0x03, 0xfc, 0x0e, 0x30, 0xe0, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x63, 0x80, 0x01, 0xc7, 0x00, 0x3f, 0xc7, 0x30, 0x70, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x73, 0x80, 0x00, 0xc7, 0x00, 0x07, 0xfb, 0xf0, 0x38, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x73, 0x80, 0x00, 0xe7, 0x00, 0x00, 0xff, 0xf0, 0x38, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x33, 0x80, 0x00, 0xe7, 0x00, 0x00, 0x1f, 0xf0, 0x1c, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x3b, 0x80, 0x00, 0x67, 0x00, 0x00, 0x01, 0xfe, 0x0c, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x3b, 0x80, 0x00, 0x77, 0x00, 0x00, 0x00, 0x3f, 0xee, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x1b, 0x80, 0x00, 0x37, 0x00, 0x00, 0x00, 0x03, 0xff, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x1b, 0x80, 0x00, 0x37, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x80, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x1f, 0x80, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x80, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x0f, 0x80, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x0f, 0x80, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x0f, 0x80, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x03, 0xe0, 0x00, 0x07, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x01, 0xc0, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

void setup() {
  Serial.begin(115200);
  
  // Set pin modes
  pinMode(buttonPin, INPUT_PULLUP);
  pinMode(redLedPin, OUTPUT);
  pinMode(geenLedPin, OUTPUT); 

  // Initialize OLED display
  if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
    Serial.println(F("SSD1306 allocation failed"));
  }
  delay(2000); // alowe 2s to initialise the display
  display.clearDisplay(); 

  // Connect to Wi-Fi
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
    display.clearDisplay();
    display.setTextSize(1);
    display.setTextColor(WHITE);
    display.setCursor(0, 10);
    display.println("Connecting to WiFi...");
    display.display();
  }
  Serial.println("Connected to WiFi");
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0, 10);
  display.println("WiFi connected");
  display.display();
}

void loop() {
  bool buttonState = digitalRead(buttonPin);

  // Check if the button state has changed
  if (buttonState != lastButtonState) {
    lastButtonState = buttonState;

    // Turn on LED locally if the button is pressed
    digitalWrite(redLedPin, buttonState ? HIGH : LOW);
    digitalWrite(geenLedPin, buttonState ? LOW : HIGH); 

    // Display image based on button state
    if (buttonState) {
      display.clearDisplay();
      display.drawBitmap(0, 0, image_electric_pole, 128, 64, 1); // Grid power
      display.display();
    } else {
      display.clearDisplay();
      display.drawBitmap(0, 0, image_battery, 128, 64, 1); // Battery power
      display.display();
    }
    // Send HTTP request to receiver
    if (WiFi.status() == WL_CONNECTED) {
      HTTPClient http;
      if (lastButtonState == LOW){
        String url = String("http://") + receiverIP + "/switch/greenswitch/turn_on"; 
        http.begin(url);
        int httpResponseCode = http.GET();
        if (httpResponseCode > 0) {
          Serial.println("Sent request to receiver successfully-ON.");
        } else {
          Serial.print("Error in sending request-ON: ");
          Serial.println(httpResponseCode);
          display.clearDisplay();
          display.setTextSize(1);
          display.setTextColor(WHITE);
          display.setCursor(0, 10);
          display.println("Receiver not found!");
          display.display();                  
        }        
      }else {
        String url = String("http://") + receiverIP + "/switch/greenswitch/turn_off"; 
        http.begin(url);
        int httpResponseCode = http.GET();
        if (httpResponseCode > 0) {
          Serial.println("Sent request to receiver successfully-OFF.");
        } else {
          Serial.print("Error in sending request-OFF: ");
          Serial.println(httpResponseCode); 
          display.clearDisplay();
          display.setTextSize(1);
          display.setTextColor(WHITE);
          display.setCursor(0, 10);
          display.println("Receiver not found!");
          display.display();       
        } 
      }
      http.end();
    } else {
      Serial.println("WiFi not connected");
      display.clearDisplay();
      display.setTextSize(1);
      display.setTextColor(WHITE);
      display.setCursor(0, 10);
      display.println("WiFi not connected!");
      display.display();       
    }
  }
  delay(100);  // Debounce delay
}

2.) Receiver: (Code for ESP32 in ESPHOME)

substitutions:
  name: esphome-web-356990
  friendly_name: Power_receiver_70

esphome:
  name: ${name}
  friendly_name: ${friendly_name}
  min_version: 2024.6.0
 
esp32:
  board: esp32dev
  framework:
    type: arduino

wifi:
  ssid: "********"
  password: "*************"

  # Optional manual IP
  manual_ip:
    static_ip: 192.168.0.70
    gateway: 192.168.0.1
    subnet: 255.255.255.0

captive_portal:

api:

ota:
- platform: esphome

# Enable Web Server for additional access
web_server:
  port: 80

logger:

# GPIO pin configurations
switch:
  - platform: gpio
    pin: GPIO13
    id: led_red
    name: "redSwitch"
  - platform: gpio
    pin: GPIO27
    id: led_green
    name: "greenSwitch"
    on_turn_off: 
      then:
        - switch.turn_on: led_red
        - component.update: oled_display
    on_turn_on: 
      then:
        - switch.turn_off: led_red
        - component.update: oled_display

# OLED Display setup
i2c:
  sda: 21
  scl: 22
  scan: true

font:
  - file: "fonts/Roboto-Regular.ttf"
    id: font1
    size: 16

# Image definition
image:
  # Battery icon image
  - file: "Images/battery_icon.png"
    id: battery_icon
    resize: 128x64
    type: BINARY
  # Electric pole icon image
  - file: "Images/hightension_power_icon.png"
    id: electric_pole_icon
    resize: 128x64
    type: BINARY    

display:
  - platform: ssd1306_i2c
    model: "SSD1306 128x64"
    rotation: 0
    invert: True
    address: 0x3C
    id: oled_display
    pages:
      - id: battery_image
        lambda: |-
          it.fill(COLOR_OFF);
          if(id(led_green).state){   
            it.image(0, 0, id(battery_icon));
          }else{ 
            it.image(0, 0, id(electric_pole_icon));
          }

Now I’m going to connect the Button switch with the 230v panel light that is going to lit when the battery power is in use, through an EL817 optocoupler circuit.

I used ESPHOME for the receiver as I can now capture the power failure events in my Home Assistant for future automations.

@Karosm I’m extremely grateful to you for the immense support you gave me on this work.

Thank you once again.

That’s strange, since Esphome documentation gives:
“To actually control the state of a component you need to send a POST request with a method like turn_on .”
And I have always been using succesfully POST…

Edit: I tried for my curiosity, with GET, I only get state of the switch even if I’m using turn_on.
If yours is switching with GET, there has to be some changes on Esphome, mine is quite outdated version.

1 Like