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.
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.
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 {};
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 {};
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 {};
Update 1:
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:
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);
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!!