• Stars
    star
    183
  • Rank 205,232 (Top 5 %)
  • Language
    C++
  • Created almost 4 years ago
  • Updated almost 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Direct communication between esp devices without home assistant

ESP-NOW Integration for ESPHomE

ESP_RC IS NOW A STANDALONE LIBRARY AND HAS BEEN MOVED TO https://github.com/iphong/lib-esp-rc

THIS REPO WILL ONLY FOCUS ON ESPHOME & HOMEASSISTANT INTEGRATION


This addon allow direct communication between your esphome devices.

The Problem

  • EspHome is no doubt the best platform for creating your own DIY smart devices, but it requires a WiFi router and HomeAssistant in order to communicate.

Other solutions

  • Using BT, RF or IR module, but this requires additional hardwares

Why esp-now?

  • Works with or without WiFi connection
  • Works with or without HomeAssistant
  • Instant startup time if not using wifi
  • No addition hardware needed
  • Easy to use pub/sub event model
  • Send and receive from multiple devices

Usage examples

ATTENTION: Make sure to use the latest arduino version as this uses the new esp-now broadcast feature. And it's recommended to use the same channel as your wifi router.

  1. A main device contains simple gpio switch and a light
esphome:
  ...
  arduino_version: LATEST
  includes:
  - esp_now_connect.h

output:
- platform: gpio
  pin: 13
  id: my_output

light:
- platform: binary
  output: my_output
  id: my_light
  name: My Light

switch:
- platform: gpio
  pin: 12
  id: my_switch
  on_turn_on:
  - lambda: EspRC.send("my_switch on");
  on_turn_off:
  - lambda: EspRC.send("my_switch off");

custom_component:
- lambda: |-
    EspRC.begin(2);
    EspRC.on("my_motion on", []() {
      id(my_light)->turn_on().perform();
    });
    EspRC.on("my_motion off", []() {
      id(my_light)->turn_off().perform();
    });
    EspRC.on("status my_switch", []() {
      if (id(my_switch).state) {
        EspRC.send("my_switch on");
      } else {
        EspRC.send("my_switch off");
      }
    });
    return {};
  1. A second device contains a motion sensor
esphome:
  ...
  arduino_version: LATEST
  includes:
  - esp_now_connect.h

binary_sensor:
- platform: gpio
  pin: 2
  id: my_motion
  on_press:
  - lambda: EspRC.send("my_motion on");
  on_release:
  - lambda: EspRC.send("my_motion off");

custom_component:
- lambda: |-
    EspRC.begin(2);
    return {};
  1. A third device contains a LED state indicator of the switch on device 1
esphome:
  ...
  arduino_version: LATEST
  includes:
  - esp_now_connect.h

output:
- platform: gpio
  pin: 13
  id: my_output

light:
- platform: binary
  output: my_output
  id: my_light
  name: My Light

custom_component:
- lambda: |-
    EspRC.begin(2);
    EspRC.on("my_switch on", []() {
      id(my_light)->turn_on().perform();
    });
    EspRC.on("my_switch off", []() {
      id(my_light)->turn_off().perform();
    });
    EspRC.send("status my_switch");
    return {};

CHANGE LOGS:

Update 1:

  1. To prevent conflict with EspRC namespace, i will use the namespace EspRC instead.
  2. You can now receive and send message with arguments but this method is having performance issues.
EspRC.on("bedroom light", [](String state) {
  if (state.equals("on")) {
    // do something
  } else {
    // do some thing else
  }
});
EspRC.on("bedroom temp", [](Int value) {
  // Do something with int value
});
EspRC.send("bedroom light", "on");
EspRC.send("bedroom temp", 28);

Update 2:

  1. A different way to get data. This method works better than the previous update
EspRC.on("bedroom light", []() {
  String state = EspRC.getValue();
  if (state.equals("on")) {
    // do something
  } else {
    // do some thing else
  }
});
EspRC.on("bedroom temp", []() {
  Int value = EspRC.getValue().toInt();
  // Do something with int value
});
EspRC.send("bedroom light", "on");
EspRC.send("bedroom temp", 28);

What's next

  • Adding PSK encryption support
  • Adding ESP32 support
  • Sending typed data as argument
  • Sending to a specific peer
  • and much more...

Acknowledgments

This project is part of my smarthome project that build entirely with esphome. There are more real life examples you might want to check it out at https://github.com/iphong/ha-config.

You are free to use and modify these code to better fit your project.

Cheers!!

More Repositories

1

lib-esp-rc

C++
47
star
2

esphome-tuya-curtain

ESPHome custom components for Tuya curtain includes feedback and position support
C++
32
star
3

react-portal-frame

Rendering components inside iframes using react portal.
JavaScript
24
star
4

ha-config

My Home Assistant build configuration file
C++
22
star
5

esp-visual-led

Realtime light shows using multiple esp8266
JavaScript
19
star
6

container-x

Simple and super lightweight state management for React application
JavaScript
7
star
7

ha-espcam

Integrating the ESP32 Cam with Home Assistant
JavaScript
7
star
8

event-x

Lightest javascript event emitters written the pure functional programming way
TypeScript
3
star
9

esp-web-bridge

ESP8266 Serial Bridge over WebSocket and AVR ISP Programmer
C
3
star
10

web-components

Web Components examples written in pure Javascript
JavaScript
3
star
11

lib-crossfire

TBS Crossfire related libraries
C++
2
star
12

backbone-x

JavaScript
2
star
13

hass-config

C++
2
star
14

lib-button

C++
1
star
15

touchjs

1
star
16

flex-ui

A light-weight CSS library for web app UI layout
CSS
1
star
17

besafe

JavaScript
1
star
18

motionjs

Javascript animation utilities
1
star
19

model-x

Pure functional observable data model
JavaScript
1
star
20

base-app

JavaScript
1
star
21

modulejs

Javascript module made easy
JavaScript
1
star
22

ide-settings

IDE Settings Sync
1
star
23

auto-fpv

Keep all fpv gears in sync
C++
1
star
24

react-model

A technique used to handle anything that emits events using render props
JavaScript
1
star
25

computejs

Spread your HTML5 app computation across multiple CPU cores using web workers.
JavaScript
1
star
26

core.io

Advanced web worker library, that opens up a whole new world of multi-core processing for web applications on modern browsers. From single threaded process stacking to multi-core cluster controller and load balancing. It's dependency free and its coming soon.
JavaScript
1
star