@ -1,6 +1,29 @@ | |||||
# esphome-yeelight_bs2 | # esphome-yeelight_bs2 | ||||
# References | |||||
## Installation | |||||
Create a folder named `custom_components` in the folder where your | |||||
device's yaml configuration file is stored. Then clone the the Github | |||||
repo into that folder. For example on the command line: | |||||
``` | |||||
# mkdir custom_components | |||||
# cd custom_compnents | |||||
# git clone https://github.com/mmakaay/esphome-yeelight_bs2 | |||||
``` | |||||
Your folder structure should now look like: | |||||
``` | |||||
config | |||||
├── yourdevice.yaml | |||||
├── custom_components/ | |||||
│ ├── esphome-yeelight_bs2/ | |||||
│ . ├── README.md | |||||
. . ├── yeelight_bs2_light_output.h | |||||
. . | |||||
. | |||||
``` | |||||
Then add the required configuration to your device's yaml configuration file. | |||||
For an example file, taks a look at `doc/example.yaml` in this repository. | |||||
* Inspiration for some ESPHome settings: | |||||
https://www.reddit.com/r/Esphome/comments/j11ayw/working_configuration_for_xiaomi_mi_desk_lamp_1s/ |
@ -0,0 +1,53 @@ | |||||
i2c: | |||||
- id: eeprom_i2c | |||||
sda: 17 | |||||
scl: 18 | |||||
scan: True | |||||
- id: front_panel_i2c | |||||
sda: 21 | |||||
scl: 19 | |||||
scan: True | |||||
output: | |||||
- platform: gpio | |||||
id: master1 | |||||
pin: GPIO33 | |||||
- platform: gpio | |||||
id: master2 | |||||
pin: GPIO4 | |||||
- platform: ledc | |||||
id: led_r | |||||
pin: GPIO13 | |||||
frequency: "3000Hz" | |||||
- platform: ledc | |||||
id: led_g | |||||
pin: GPIO14 | |||||
frequency: "3000Hz" | |||||
- platform: ledc | |||||
id: led_b | |||||
pin: GPIO5 | |||||
frequency: "3000Hz" | |||||
- platform: ledc | |||||
id: led_w | |||||
pin: GPIO12 | |||||
frequency: "3000Hz" | |||||
light: | |||||
- platform: yeelight_bs2 | |||||
name: ${friendly_name} Custom Light | |||||
red: led_r | |||||
green: led_g | |||||
blue: led_b | |||||
white: led_w | |||||
master1: master1 | |||||
master2: master2 | |||||
default_transition_length: 1s | |||||
effects: | |||||
- random: | |||||
name: "Slow Random" | |||||
transition_length: 30s | |||||
update_interval: 30s | |||||
- random: | |||||
name: "Fast Random" | |||||
transition_length: 3s | |||||
update_interval: 4s |
@ -1,29 +0,0 @@ | |||||
# Some substitutions as used by the included yaml file. | |||||
substitutions: | |||||
name: bedside_lamp_office | |||||
friendly_name: Bedside Lamp Office | |||||
# Configuration options to connect the device to the network. | |||||
# The api is used for allowing connections from Home Assistant. | |||||
# The ota is used for over the air updates after the first deployment. | |||||
wifi: | |||||
ssid: !secret wifi_ssid | |||||
password: !secret wifi_password | |||||
ap: | |||||
ssid: ${friendly_name} | |||||
password: !secret wifi_ap_fallback_password | |||||
captive_portal: | |||||
api: | |||||
password: !secret api_password | |||||
ota: | |||||
password: !secret ota_password | |||||
# The rest of the configuration is included. | |||||
<<: !include esphome-yeelight_bs2/yeelight_bs2.yaml |
@ -1,23 +0,0 @@ | |||||
{ | |||||
"name": "esphome-YeelightBS2", | |||||
"version": "0.0.2", | |||||
"description": "ESPHome components to fully control a Yeelight Bedside Lamp v2 device.", | |||||
"keywords": "esphome, yeelight, bedside", | |||||
"repository": | |||||
{ | |||||
"type": "git", | |||||
"url": "https://github.com/mmakaay/esphome-yeelight_bs2.git" | |||||
}, | |||||
"authors": | |||||
[ | |||||
{ | |||||
"name": "Maurice Makaay", | |||||
"email": "account-github-yeelight_bs2@makaay.nl", | |||||
"maintainer": true | |||||
} | |||||
], | |||||
"license": "LGPL-3.0", | |||||
"frameworks": "arduino", | |||||
"platforms": "espressif32", | |||||
"homepage": "https://github.com/mmakaay/esphome-yeelight_bs2.git" | |||||
} |
@ -0,0 +1,41 @@ | |||||
import esphome.codegen as cg | |||||
import esphome.config_validation as cv | |||||
from esphome.components import light, output, gpio | |||||
from esphome.const import CONF_RED, CONF_GREEN, CONF_BLUE, CONF_WHITE, CONF_OUTPUT_ID | |||||
CONF_MASTER1 = "master1" | |||||
CONF_MASTER2 = "master2" | |||||
rgbww_ns = cg.esphome_ns.namespace("rgbww") | |||||
YeelightBS2LightOutput = rgbww_ns.class_("YeelightBS2LightOutput", light.LightOutput) | |||||
CONFIG_SCHEMA = light.RGB_LIGHT_SCHEMA.extend( | |||||
{ | |||||
cv.GenerateID(CONF_OUTPUT_ID): cv.declare_id(YeelightBS2LightOutput), | |||||
cv.Required(CONF_RED): cv.use_id(output.FloatOutput), | |||||
cv.Required(CONF_GREEN): cv.use_id(output.FloatOutput), | |||||
cv.Required(CONF_BLUE): cv.use_id(output.FloatOutput), | |||||
cv.Required(CONF_WHITE): cv.use_id(output.FloatOutput), | |||||
cv.Required(CONF_WHITE): cv.use_id(output.FloatOutput), | |||||
cv.Required(CONF_MASTER1): cv.use_id(gpio.output.GPIOBinaryOutput), | |||||
cv.Required(CONF_MASTER2): cv.use_id(gpio.output.GPIOBinaryOutput), | |||||
} | |||||
) | |||||
def to_code(config): | |||||
var = cg.new_Pvariable(config[CONF_OUTPUT_ID]) | |||||
yield light.register_light(var, config) | |||||
red = yield cg.get_variable(config[CONF_RED]) | |||||
cg.add(var.set_red(red)) | |||||
green = yield cg.get_variable(config[CONF_GREEN]) | |||||
cg.add(var.set_green(green)) | |||||
blue = yield cg.get_variable(config[CONF_BLUE]) | |||||
cg.add(var.set_blue(blue)) | |||||
white = yield cg.get_variable(config[CONF_WHITE]) | |||||
cg.add(var.set_white(white)) | |||||
master1 = yield cg.get_variable(config[CONF_MASTER1]) | |||||
cg.add(var.set_master1(master1)) | |||||
master2 = yield cg.get_variable(config[CONF_MASTER2]) | |||||
cg.add(var.set_master2(master2)) |
@ -1,69 +0,0 @@ | |||||
esphome: | |||||
name: $name | |||||
platform: ESP32 | |||||
board: esp32doit-devkit-v1 | |||||
platformio_options: | |||||
platform: espressif32@1.11.0 | |||||
platform_packages: |-4 | |||||
framework-arduinoespressif32 @ https://github.com/pauln/arduino-esp32.git#solo-no-mac-crc/1.0.4 | |||||
includes: | |||||
- esphome-yeelight_bs2/yeelight_bs2.h | |||||
# Enable logging | |||||
logger: | |||||
# The front panel of the device uses I2C for communication | |||||
# with the ESP32 main board. The panel uses address 0x2C. | |||||
# There are two I2C busses attached to the ESP32: | |||||
# SDA 17/SCL 18 and SDA 21/SCL 19. The latter is the | |||||
# correct one for the front panel. The former is probably | |||||
# an EEPROM of some sorts. | |||||
i2c: | |||||
- id: eeprom_i2c | |||||
sda: 17 | |||||
scl: 18 | |||||
scan: True | |||||
- id: front_panel_i2c | |||||
sda: 21 | |||||
scl: 19 | |||||
scan: True | |||||
output: | |||||
- platform: gpio | |||||
id: master1 | |||||
pin: GPIO33 | |||||
- platform: gpio | |||||
id: master2 | |||||
pin: GPIO4 | |||||
- platform: ledc | |||||
id: led_r | |||||
pin: GPIO13 | |||||
- platform: ledc | |||||
id: led_g | |||||
pin: GPIO14 | |||||
- platform: ledc | |||||
id: led_b | |||||
pin: GPIO5 | |||||
- platform: ledc | |||||
id: led_w | |||||
pin: GPIO12 | |||||
light: | |||||
- platform: custom | |||||
lambda: |- | |||||
auto bs2light = new esphome::rgbww::YeelightBedsideLampV2LightOutput( | |||||
led_r, led_g, led_b, led_w, master1, master2); | |||||
App.register_component(bs2light); | |||||
return {bs2light}; | |||||
lights: | |||||
- name: ${friendly_name} RGBW Light | |||||
default_transition_length: 0s | |||||
effects: | |||||
- random: | |||||
name: "Slow Random" | |||||
transition_length: 30s | |||||
update_interval: 30s | |||||
- random: | |||||
name: "Fast Random" | |||||
transition_length: 3s | |||||
update_interval: 4s |