Browse Source

Moved to a proper ESPHome component structure.

pull/1/head
Maurice Makaay 3 years ago
parent
commit
6c5c6ca5cc
42 changed files with 143 additions and 139 deletions
  1. +3
    -0
      .gitignore
  2. +26
    -3
      README.md
  3. +0
    -0
      __init__.py
  4. +53
    -0
      doc/example.yaml
  5. +0
    -0
      doc/reverse_engineering/Component Chip on front panel - KF8TS2716 Data Sheet.pdf
  6. +0
    -0
      doc/reverse_engineering/Component KL3 diode.webp
  7. +0
    -0
      doc/reverse_engineering/Component RT8471 Hysteric high brightness LED driver with internal switch.pdf
  8. +0
    -0
      doc/reverse_engineering/Component VBA4338 Dual P-channel mosfet datasheet.pdf
  9. +0
    -0
      doc/reverse_engineering/ESP32 pinout.xcf
  10. +0
    -0
      doc/reverse_engineering/I2C protocol/i2c_commands.txt
  11. +0
    -0
      doc/reverse_engineering/I2C protocol/traces/button on - button off - button on.txt
  12. +0
    -0
      doc/reverse_engineering/I2C protocol/traces/button on hold a while - release.txt
  13. +0
    -0
      doc/reverse_engineering/I2C protocol/traces/color button hold - release.txt
  14. +0
    -0
      doc/reverse_engineering/I2C protocol/traces/color button touch - release 3x.txt
  15. +0
    -0
      doc/reverse_engineering/I2C protocol/traces/remote 1% to 100%.txt
  16. +0
    -0
      doc/reverse_engineering/I2C protocol/traces/remote 100% to 80%.txt
  17. +0
    -0
      doc/reverse_engineering/I2C protocol/traces/remote 20% to 1%.txt
  18. +0
    -0
      doc/reverse_engineering/I2C protocol/traces/remote 40% to 20%.txt
  19. +0
    -0
      doc/reverse_engineering/I2C protocol/traces/remote 60% to 40%.txt
  20. +0
    -0
      doc/reverse_engineering/I2C protocol/traces/remote 80% to 60%.txt
  21. +0
    -0
      doc/reverse_engineering/I2C protocol/traces/remote off.txt
  22. +0
    -0
      doc/reverse_engineering/I2C protocol/traces/remote on.txt
  23. +0
    -0
      doc/reverse_engineering/I2C protocol/traces/slider slide 1% to 100%.txt
  24. +0
    -0
      doc/reverse_engineering/I2C protocol/traces/slider touch - release at about 30%.txt
  25. +0
    -0
      doc/reverse_engineering/I2C protocol/traces/slider touch increasing brightnesses 0 - 100 7x.txt
  26. +0
    -0
      doc/reverse_engineering/IC connected to I2C on GPIO 17+18.xcf
  27. +0
    -0
      doc/reverse_engineering/Original firmware boot messages.txt
  28. +0
    -0
      doc/reverse_engineering/PulseView setup for RGB tests.pvs
  29. +0
    -0
      doc/reverse_engineering/RGB_mapping.py
  30. +0
    -0
      doc/reverse_engineering/Reboot crashes on ESPHome.txt
  31. +0
    -0
      doc/reverse_engineering/Trace bottom left.xcf
  32. +0
    -0
      doc/reverse_engineering/Trace bottom right.xcf
  33. +0
    -0
      doc/reverse_engineering/Trace for IC connected to I2C on GPIO 17+18.xcf
  34. +0
    -0
      doc/reverse_engineering/Trace front panel connector.xcf
  35. +0
    -0
      doc/reverse_engineering/Trace top left.xcf
  36. +0
    -0
      doc/reverse_engineering/Trace top right.xcf
  37. +0
    -0
      doc/reverse_engineering/Yeelight GPIO measurements.xlsx
  38. +0
    -29
      example-device.yaml
  39. +0
    -23
      library.json
  40. +41
    -0
      light.py
  41. +0
    -69
      yeelight_bs2.yaml
  42. +20
    -15
      yeelight_bs2_light_output.h

+ 3
- 0
.gitignore View File

@ -20,3 +20,6 @@ tags
# OpenOffice temp files # OpenOffice temp files
**/.~* **/.~*
# Python cache files
__pycache__

+ 26
- 3
README.md View File

@ -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
__init__.py View File


+ 53
- 0
doc/example.yaml View File

@ -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

doc/Component Chip on front panel - KF8TS2716 Data Sheet.pdf → doc/reverse_engineering/Component Chip on front panel - KF8TS2716 Data Sheet.pdf View File


doc/Component KL3 diode.webp → doc/reverse_engineering/Component KL3 diode.webp View File


doc/Component RT8471 Hysteric high brightness LED driver with internal switch.pdf → doc/reverse_engineering/Component RT8471 Hysteric high brightness LED driver with internal switch.pdf View File


doc/Component VBA4338 Dual P-channel mosfet datasheet.pdf → doc/reverse_engineering/Component VBA4338 Dual P-channel mosfet datasheet.pdf View File


doc/ESP32 pinout.xcf → doc/reverse_engineering/ESP32 pinout.xcf View File


doc/I2C protocol/i2c_commands.txt → doc/reverse_engineering/I2C protocol/i2c_commands.txt View File


doc/I2C protocol/traces/button on - button off - button on.txt → doc/reverse_engineering/I2C protocol/traces/button on - button off - button on.txt View File


doc/I2C protocol/traces/button on hold a while - release.txt → doc/reverse_engineering/I2C protocol/traces/button on hold a while - release.txt View File


doc/I2C protocol/traces/color button hold - release.txt → doc/reverse_engineering/I2C protocol/traces/color button hold - release.txt View File


doc/I2C protocol/traces/color button touch - release 3x.txt → doc/reverse_engineering/I2C protocol/traces/color button touch - release 3x.txt View File


doc/I2C protocol/traces/remote 1% to 100%.txt → doc/reverse_engineering/I2C protocol/traces/remote 1% to 100%.txt View File


doc/I2C protocol/traces/remote 100% to 80%.txt → doc/reverse_engineering/I2C protocol/traces/remote 100% to 80%.txt View File


doc/I2C protocol/traces/remote 20% to 1%.txt → doc/reverse_engineering/I2C protocol/traces/remote 20% to 1%.txt View File


doc/I2C protocol/traces/remote 40% to 20%.txt → doc/reverse_engineering/I2C protocol/traces/remote 40% to 20%.txt View File


doc/I2C protocol/traces/remote 60% to 40%.txt → doc/reverse_engineering/I2C protocol/traces/remote 60% to 40%.txt View File


doc/I2C protocol/traces/remote 80% to 60%.txt → doc/reverse_engineering/I2C protocol/traces/remote 80% to 60%.txt View File


doc/I2C protocol/traces/remote off.txt → doc/reverse_engineering/I2C protocol/traces/remote off.txt View File


doc/I2C protocol/traces/remote on.txt → doc/reverse_engineering/I2C protocol/traces/remote on.txt View File


doc/I2C protocol/traces/slider slide 1% to 100%.txt → doc/reverse_engineering/I2C protocol/traces/slider slide 1% to 100%.txt View File


doc/I2C protocol/traces/slider touch - release at about 30%.txt → doc/reverse_engineering/I2C protocol/traces/slider touch - release at about 30%.txt View File


doc/I2C protocol/traces/slider touch increasing brightnesses 0 - 100 7x.txt → doc/reverse_engineering/I2C protocol/traces/slider touch increasing brightnesses 0 - 100 7x.txt View File


doc/IC connected to I2C on GPIO 17+18.xcf → doc/reverse_engineering/IC connected to I2C on GPIO 17+18.xcf View File


doc/Original firmware boot messages.txt → doc/reverse_engineering/Original firmware boot messages.txt View File


doc/PulseView setup for RGB tests.pvs → doc/reverse_engineering/PulseView setup for RGB tests.pvs View File


doc/RGB_mapping.py → doc/reverse_engineering/RGB_mapping.py View File


doc/Reboot crashes on ESPHome.txt → doc/reverse_engineering/Reboot crashes on ESPHome.txt View File


doc/Trace bottom left.xcf → doc/reverse_engineering/Trace bottom left.xcf View File


doc/Trace bottom right.xcf → doc/reverse_engineering/Trace bottom right.xcf View File


doc/Trace for IC connected to I2C on GPIO 17+18.xcf → doc/reverse_engineering/Trace for IC connected to I2C on GPIO 17+18.xcf View File


doc/Trace front panel connector.xcf → doc/reverse_engineering/Trace front panel connector.xcf View File


doc/Trace top left.xcf → doc/reverse_engineering/Trace top left.xcf View File


doc/Trace top right.xcf → doc/reverse_engineering/Trace top right.xcf View File


doc/Yeelight GPIO measurements.xlsx → doc/reverse_engineering/Yeelight GPIO measurements.xlsx View File


+ 0
- 29
example-device.yaml View File

@ -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

+ 0
- 23
library.json View File

@ -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"
}

+ 41
- 0
light.py View File

@ -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))

+ 0
- 69
yeelight_bs2.yaml View File

@ -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

src/YeelightBedsideLampV2LightOutput.h → yeelight_bs2_light_output.h View File

@ -1,6 +1,9 @@
#pragma once #pragma once
#include "esphome.h"
#include "esphome/core/component.h"
#include "esphome/components/output/float_output.h"
#include "esphome/components/light/light_output.h"
#include "esphome/components/gpio/output/gpio_binary_output.h"
#define CONSTANT_BRIGHTNESS true #define CONSTANT_BRIGHTNESS true
@ -22,17 +25,19 @@ namespace esphome
{ {
namespace rgbww namespace rgbww
{ {
class YeelightBedsideLampV2LightOutput : public Component, public LightOutput
class YeelightBS2LightOutput : public Component, public light::LightOutput
{ {
public: public:
YeelightBedsideLampV2LightOutput(
FloatOutput *r, FloatOutput *g, FloatOutput *b, FloatOutput *w,
esphome::gpio::GPIOBinaryOutput *m1, esphome::gpio::GPIOBinaryOutput *m2) : red_(r), green_(g), blue_(b), white_(w), master1_(m1), master2_(m2) {}
LightTraits get_traits() override
void set_red(output::FloatOutput *red) { red_ = red; }
void set_green(output::FloatOutput *green) { green_ = green; }
void set_blue(output::FloatOutput *blue) { blue_ = blue; }
void set_white(output::FloatOutput *white) { white_ = white; }
void set_master1(gpio::GPIOBinaryOutput *master1) { master1_ = master1; }
void set_master2(gpio::GPIOBinaryOutput *master2) { master2_ = master2; }
light::LightTraits get_traits() override
{ {
auto traits = LightTraits();
auto traits = light::LightTraits();
traits.set_supports_rgb(true); traits.set_supports_rgb(true);
traits.set_supports_color_temperature(true); traits.set_supports_color_temperature(true);
traits.set_supports_brightness(true); traits.set_supports_brightness(true);
@ -43,7 +48,7 @@ namespace esphome
return traits; return traits;
} }
void write_state(LightState *state) override
void write_state(light::LightState *state) override
{ {
auto values = state->current_values; auto values = state->current_values;
@ -103,11 +108,11 @@ namespace esphome
} }
} }
private:
FloatOutput *red_;
FloatOutput *green_;
FloatOutput *blue_;
FloatOutput *white_;
protected:
output::FloatOutput *red_;
output::FloatOutput *green_;
output::FloatOutput *blue_;
output::FloatOutput *white_;
esphome::gpio::GPIOBinaryOutput *master1_; esphome::gpio::GPIOBinaryOutput *master1_;
esphome::gpio::GPIOBinaryOutput *master2_; esphome::gpio::GPIOBinaryOutput *master2_;
// Used for a bug hack. // Used for a bug hack.

Loading…
Cancel
Save