First of all, this is based on a similar integration by iphong, which is now updated to MeshRC.
The purpose of this software is to enable communication between esp devices without a wifi connection. In the example the light acts as a slave and the hub controls the light. I have tried to make the communication as lightweight as possible and similar to service calls in HomeAssistant. The idea is explained in this diagram
light.yaml
example. This must be initialized by MeshRC::setupwifi(${wifichannel});
.All messages sent over esp-now are of the form:
This implementation is used to generate so-called channels, these are based on the mac addresses and allow us to easily set up communication with different nodes and easily direct the traffic.
I wanted to have some nice lights in my garden, they should be controllable by HomeAssistant so that they eventually would be able to react to movement.
Firstly, I decided to use cheap commercial solar lights and replace the hardware with some NeoPixel LEDs (WS2812 Ring). These LEDs would be controlled via an ESP chip from indoors. So all the data would travel underground to all the lights. All lights would be chained together so that every led in every light could be controlled individually. Unfortunately carrying the data over such a long distance underground proved almost impossible.
As a second attempt, I decided to give each light it's own ESP-01s controller. They are very cheap (~1 USD) and they have wifi capability. I do however not want to use WiFi for all lights (4 at the moment) in my garden, since this would put some stress on my home network. Hence I decided to use the esp-now protocol to communicate between a hub and the lights.
One of the downsides of esp-now is that it only works if you are connected to the right WiFi channel. To solve this, I added the possibility to use a second esp8266 as the transmitter of the esp-now signal. The hub communicates with this transmitter over UART (Serial), and the transmitter just relays the signal. Using this strategy, WiFi channels can no longer cause issues and it should even be possible to use an ESP32 with an Ethernet connection as a hub.
For this guide, I assume that you have esphome up and running and are familiar with how it all works. We need one microcontroller as a hub and one as a light.
Change the data in the examples, such that they are correct for your devices
substitutions:
devicename: light
wifichannel: "7"
MeshRC::setupwifi(<channel>);
). Make the following connections with the ESP-01s:HUB | ESP-01s (transmitter) |
---|---|
RX | TX |
TX | RX |
3v | 3v |
GND | GND |
substitutions:
devicename: hub
light_address_1: "{0xff,0xff,0xff,0xff,0xff,0xff};"