You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

138 lines
5.7 KiB

Introduced a HUB component + front panel IRQ handling A HUB component was introduced. This HUB component has all the knowledge about the Yeelight Bedside Lamp 2 hardware. It known what pins are used, that PWM frequencies to use, what pins to switch in binary mode, etc. etc. No configuration is required for this HUB component. It's automatically loaded when the light component is loaded. The light component will use the HUB component to access the pins that are required for driving the LED circuitry. Note that this simplifies the configuration by A LOT. There's no need anymore to configure the pinouts in the YAML file. This is a logical route to take, since we're talking about a factory-produced PCB with a soldered on ESP32 chip, which uses the same GPIO's and settings on all produced devices (I presume). It would be quite redundant to force every user into configuring these pinouts themselves. ** Beware to update your device yaml configuration ** There are a few pinouts left to move into the HUB. I will do that in the next commit. Your device yaml configuration can be simplified along with these changes. Some of the keys in the existing light configuration block will no longer work and will have to be removed (red, green, blue, white). ** Further development ** The HUB will be extended make it the central component that also handles the I2C communication. This way, there is a central place to regulate the traffic to and from the front panel. We will be able to build upon this by implementing extra, fully separated components that handle for example the front panel light level, the power button, the color button and the slider. ** Interrupt handler for the I2C IRQ trigger pin ** One requirement for the I2C communication has already been implemented: an interrupt handler for the GPIO that is used by the front panel to signal the ESP that a new touch or release event is avilable to be read. It doens't do anything functionally right now, but if you watch the log file, you will see that touch events are detected and that they trigger some log messages.
3 years ago
Introduced a HUB component + front panel IRQ handling A HUB component was introduced. This HUB component has all the knowledge about the Yeelight Bedside Lamp 2 hardware. It known what pins are used, that PWM frequencies to use, what pins to switch in binary mode, etc. etc. No configuration is required for this HUB component. It's automatically loaded when the light component is loaded. The light component will use the HUB component to access the pins that are required for driving the LED circuitry. Note that this simplifies the configuration by A LOT. There's no need anymore to configure the pinouts in the YAML file. This is a logical route to take, since we're talking about a factory-produced PCB with a soldered on ESP32 chip, which uses the same GPIO's and settings on all produced devices (I presume). It would be quite redundant to force every user into configuring these pinouts themselves. ** Beware to update your device yaml configuration ** There are a few pinouts left to move into the HUB. I will do that in the next commit. Your device yaml configuration can be simplified along with these changes. Some of the keys in the existing light configuration block will no longer work and will have to be removed (red, green, blue, white). ** Further development ** The HUB will be extended make it the central component that also handles the I2C communication. This way, there is a central place to regulate the traffic to and from the front panel. We will be able to build upon this by implementing extra, fully separated components that handle for example the front panel light level, the power button, the color button and the slider. ** Interrupt handler for the I2C IRQ trigger pin ** One requirement for the I2C communication has already been implemented: an interrupt handler for the GPIO that is used by the front panel to signal the ESP that a new touch or release event is avilable to be read. It doens't do anything functionally right now, but if you watch the log file, you will see that touch events are detected and that they trigger some log messages.
3 years ago
Introduced a HUB component + front panel IRQ handling A HUB component was introduced. This HUB component has all the knowledge about the Yeelight Bedside Lamp 2 hardware. It known what pins are used, that PWM frequencies to use, what pins to switch in binary mode, etc. etc. No configuration is required for this HUB component. It's automatically loaded when the light component is loaded. The light component will use the HUB component to access the pins that are required for driving the LED circuitry. Note that this simplifies the configuration by A LOT. There's no need anymore to configure the pinouts in the YAML file. This is a logical route to take, since we're talking about a factory-produced PCB with a soldered on ESP32 chip, which uses the same GPIO's and settings on all produced devices (I presume). It would be quite redundant to force every user into configuring these pinouts themselves. ** Beware to update your device yaml configuration ** There are a few pinouts left to move into the HUB. I will do that in the next commit. Your device yaml configuration can be simplified along with these changes. Some of the keys in the existing light configuration block will no longer work and will have to be removed (red, green, blue, white). ** Further development ** The HUB will be extended make it the central component that also handles the I2C communication. This way, there is a central place to regulate the traffic to and from the front panel. We will be able to build upon this by implementing extra, fully separated components that handle for example the front panel light level, the power button, the color button and the slider. ** Interrupt handler for the I2C IRQ trigger pin ** One requirement for the I2C communication has already been implemented: an interrupt handler for the GPIO that is used by the front panel to signal the ESP that a new touch or release event is avilable to be read. It doens't do anything functionally right now, but if you watch the log file, you will see that touch events are detected and that they trigger some log messages.
3 years ago
Introduced a HUB component + front panel IRQ handling A HUB component was introduced. This HUB component has all the knowledge about the Yeelight Bedside Lamp 2 hardware. It known what pins are used, that PWM frequencies to use, what pins to switch in binary mode, etc. etc. No configuration is required for this HUB component. It's automatically loaded when the light component is loaded. The light component will use the HUB component to access the pins that are required for driving the LED circuitry. Note that this simplifies the configuration by A LOT. There's no need anymore to configure the pinouts in the YAML file. This is a logical route to take, since we're talking about a factory-produced PCB with a soldered on ESP32 chip, which uses the same GPIO's and settings on all produced devices (I presume). It would be quite redundant to force every user into configuring these pinouts themselves. ** Beware to update your device yaml configuration ** There are a few pinouts left to move into the HUB. I will do that in the next commit. Your device yaml configuration can be simplified along with these changes. Some of the keys in the existing light configuration block will no longer work and will have to be removed (red, green, blue, white). ** Further development ** The HUB will be extended make it the central component that also handles the I2C communication. This way, there is a central place to regulate the traffic to and from the front panel. We will be able to build upon this by implementing extra, fully separated components that handle for example the front panel light level, the power button, the color button and the slider. ** Interrupt handler for the I2C IRQ trigger pin ** One requirement for the I2C communication has already been implemented: an interrupt handler for the GPIO that is used by the front panel to signal the ESP that a new touch or release event is avilable to be read. It doens't do anything functionally right now, but if you watch the log file, you will see that touch events are detected and that they trigger some log messages.
3 years ago
Introduced a HUB component + front panel IRQ handling A HUB component was introduced. This HUB component has all the knowledge about the Yeelight Bedside Lamp 2 hardware. It known what pins are used, that PWM frequencies to use, what pins to switch in binary mode, etc. etc. No configuration is required for this HUB component. It's automatically loaded when the light component is loaded. The light component will use the HUB component to access the pins that are required for driving the LED circuitry. Note that this simplifies the configuration by A LOT. There's no need anymore to configure the pinouts in the YAML file. This is a logical route to take, since we're talking about a factory-produced PCB with a soldered on ESP32 chip, which uses the same GPIO's and settings on all produced devices (I presume). It would be quite redundant to force every user into configuring these pinouts themselves. ** Beware to update your device yaml configuration ** There are a few pinouts left to move into the HUB. I will do that in the next commit. Your device yaml configuration can be simplified along with these changes. Some of the keys in the existing light configuration block will no longer work and will have to be removed (red, green, blue, white). ** Further development ** The HUB will be extended make it the central component that also handles the I2C communication. This way, there is a central place to regulate the traffic to and from the front panel. We will be able to build upon this by implementing extra, fully separated components that handle for example the front panel light level, the power button, the color button and the slider. ** Interrupt handler for the I2C IRQ trigger pin ** One requirement for the I2C communication has already been implemented: an interrupt handler for the GPIO that is used by the front panel to signal the ESP that a new touch or release event is avilable to be read. It doens't do anything functionally right now, but if you watch the log file, you will see that touch events are detected and that they trigger some log messages.
3 years ago
Introduced a HUB component + front panel IRQ handling A HUB component was introduced. This HUB component has all the knowledge about the Yeelight Bedside Lamp 2 hardware. It known what pins are used, that PWM frequencies to use, what pins to switch in binary mode, etc. etc. No configuration is required for this HUB component. It's automatically loaded when the light component is loaded. The light component will use the HUB component to access the pins that are required for driving the LED circuitry. Note that this simplifies the configuration by A LOT. There's no need anymore to configure the pinouts in the YAML file. This is a logical route to take, since we're talking about a factory-produced PCB with a soldered on ESP32 chip, which uses the same GPIO's and settings on all produced devices (I presume). It would be quite redundant to force every user into configuring these pinouts themselves. ** Beware to update your device yaml configuration ** There are a few pinouts left to move into the HUB. I will do that in the next commit. Your device yaml configuration can be simplified along with these changes. Some of the keys in the existing light configuration block will no longer work and will have to be removed (red, green, blue, white). ** Further development ** The HUB will be extended make it the central component that also handles the I2C communication. This way, there is a central place to regulate the traffic to and from the front panel. We will be able to build upon this by implementing extra, fully separated components that handle for example the front panel light level, the power button, the color button and the slider. ** Interrupt handler for the I2C IRQ trigger pin ** One requirement for the I2C communication has already been implemented: an interrupt handler for the GPIO that is used by the front panel to signal the ESP that a new touch or release event is avilable to be read. It doens't do anything functionally right now, but if you watch the log file, you will see that touch events are detected and that they trigger some log messages.
3 years ago
Introduced a HUB component + front panel IRQ handling A HUB component was introduced. This HUB component has all the knowledge about the Yeelight Bedside Lamp 2 hardware. It known what pins are used, that PWM frequencies to use, what pins to switch in binary mode, etc. etc. No configuration is required for this HUB component. It's automatically loaded when the light component is loaded. The light component will use the HUB component to access the pins that are required for driving the LED circuitry. Note that this simplifies the configuration by A LOT. There's no need anymore to configure the pinouts in the YAML file. This is a logical route to take, since we're talking about a factory-produced PCB with a soldered on ESP32 chip, which uses the same GPIO's and settings on all produced devices (I presume). It would be quite redundant to force every user into configuring these pinouts themselves. ** Beware to update your device yaml configuration ** There are a few pinouts left to move into the HUB. I will do that in the next commit. Your device yaml configuration can be simplified along with these changes. Some of the keys in the existing light configuration block will no longer work and will have to be removed (red, green, blue, white). ** Further development ** The HUB will be extended make it the central component that also handles the I2C communication. This way, there is a central place to regulate the traffic to and from the front panel. We will be able to build upon this by implementing extra, fully separated components that handle for example the front panel light level, the power button, the color button and the slider. ** Interrupt handler for the I2C IRQ trigger pin ** One requirement for the I2C communication has already been implemented: an interrupt handler for the GPIO that is used by the front panel to signal the ESP that a new touch or release event is avilable to be read. It doens't do anything functionally right now, but if you watch the log file, you will see that touch events are detected and that they trigger some log messages.
3 years ago
Introduced a HUB component + front panel IRQ handling A HUB component was introduced. This HUB component has all the knowledge about the Yeelight Bedside Lamp 2 hardware. It known what pins are used, that PWM frequencies to use, what pins to switch in binary mode, etc. etc. No configuration is required for this HUB component. It's automatically loaded when the light component is loaded. The light component will use the HUB component to access the pins that are required for driving the LED circuitry. Note that this simplifies the configuration by A LOT. There's no need anymore to configure the pinouts in the YAML file. This is a logical route to take, since we're talking about a factory-produced PCB with a soldered on ESP32 chip, which uses the same GPIO's and settings on all produced devices (I presume). It would be quite redundant to force every user into configuring these pinouts themselves. ** Beware to update your device yaml configuration ** There are a few pinouts left to move into the HUB. I will do that in the next commit. Your device yaml configuration can be simplified along with these changes. Some of the keys in the existing light configuration block will no longer work and will have to be removed (red, green, blue, white). ** Further development ** The HUB will be extended make it the central component that also handles the I2C communication. This way, there is a central place to regulate the traffic to and from the front panel. We will be able to build upon this by implementing extra, fully separated components that handle for example the front panel light level, the power button, the color button and the slider. ** Interrupt handler for the I2C IRQ trigger pin ** One requirement for the I2C communication has already been implemented: an interrupt handler for the GPIO that is used by the front panel to signal the ESP that a new touch or release event is avilable to be read. It doens't do anything functionally right now, but if you watch the log file, you will see that touch events are detected and that they trigger some log messages.
3 years ago
Introduced a HUB component + front panel IRQ handling A HUB component was introduced. This HUB component has all the knowledge about the Yeelight Bedside Lamp 2 hardware. It known what pins are used, that PWM frequencies to use, what pins to switch in binary mode, etc. etc. No configuration is required for this HUB component. It's automatically loaded when the light component is loaded. The light component will use the HUB component to access the pins that are required for driving the LED circuitry. Note that this simplifies the configuration by A LOT. There's no need anymore to configure the pinouts in the YAML file. This is a logical route to take, since we're talking about a factory-produced PCB with a soldered on ESP32 chip, which uses the same GPIO's and settings on all produced devices (I presume). It would be quite redundant to force every user into configuring these pinouts themselves. ** Beware to update your device yaml configuration ** There are a few pinouts left to move into the HUB. I will do that in the next commit. Your device yaml configuration can be simplified along with these changes. Some of the keys in the existing light configuration block will no longer work and will have to be removed (red, green, blue, white). ** Further development ** The HUB will be extended make it the central component that also handles the I2C communication. This way, there is a central place to regulate the traffic to and from the front panel. We will be able to build upon this by implementing extra, fully separated components that handle for example the front panel light level, the power button, the color button and the slider. ** Interrupt handler for the I2C IRQ trigger pin ** One requirement for the I2C communication has already been implemented: an interrupt handler for the GPIO that is used by the front panel to signal the ESP that a new touch or release event is avilable to be read. It doens't do anything functionally right now, but if you watch the log file, you will see that touch events are detected and that they trigger some log messages.
3 years ago
  1. import esphome.codegen as cg
  2. import esphome.config_validation as cv
  3. from esphome import pins
  4. from esphome.components.ledc.output import LEDCOutput
  5. from esphome.components.gpio.output import GPIOBinaryOutput
  6. from esphome.components.i2c import I2CComponent, I2CDevice
  7. from esphome.core import CORE
  8. from esphome.const import (
  9. CONF_RED, CONF_GREEN, CONF_BLUE, CONF_WHITE, CONF_TRIGGER_PIN,
  10. CONF_SDA, CONF_SCL, CONF_ADDRESS, CONF_PLATFORM
  11. )
  12. CODEOWNERS = ["@mmakaay"]
  13. CONF_RED_ID = "red_id"
  14. CONF_GREEN_ID = "green_id"
  15. CONF_BLUE_ID = "blue_id"
  16. CONF_WHITE_ID = "white_id"
  17. CONF_MASTER1 = "master1"
  18. CONF_MASTER1_ID = "master1_id"
  19. CONF_MASTER2 = "master2"
  20. CONF_MASTER2_ID = "master2_id"
  21. CONF_FP_I2C_ID = "front_panel_i2c_id"
  22. CONF_LIGHT_HAL_ID = "light_hal_id"
  23. CONF_FRONT_PANEL_HAL_ID = "front_panel_hal_id"
  24. CONF_ON_BRIGHTNESS = "on_brightness"
  25. CONF_LEDS = "leds"
  26. AUTO_LOAD = ["ledc", "output", "i2c"]
  27. xiaomi_ns = cg.esphome_ns.namespace("xiaomi")
  28. bslamp2_ns = xiaomi_ns.namespace("bslamp2")
  29. LightHAL = bslamp2_ns.class_("LightHAL", cg.Component)
  30. FrontPanelHAL = bslamp2_ns.class_("FrontPanelHAL", cg.Component, I2CDevice)
  31. FrontPanelLEDs = bslamp2_ns.enum("FrontPanelLEDs")
  32. FRONT_PANEL_LED_OPTIONS = {
  33. "NONE": FrontPanelLEDs.LED_NONE,
  34. "ALL": FrontPanelLEDs.LED_ALL,
  35. "POWER": FrontPanelLEDs.LED_POWER,
  36. "COLOR": FrontPanelLEDs.LED_COLOR,
  37. "1": FrontPanelLEDs.LED_1,
  38. "2": FrontPanelLEDs.LED_2,
  39. "3": FrontPanelLEDs.LED_3,
  40. "4": FrontPanelLEDs.LED_4,
  41. "5": FrontPanelLEDs.LED_5,
  42. "6": FrontPanelLEDs.LED_6,
  43. "7": FrontPanelLEDs.LED_7,
  44. "8": FrontPanelLEDs.LED_8,
  45. "9": FrontPanelLEDs.LED_9,
  46. "10": FrontPanelLEDs.LED_10,
  47. }
  48. CONFIG_SCHEMA = cv.COMPONENT_SCHEMA.extend({
  49. # RGBWW Light
  50. cv.GenerateID(CONF_LIGHT_HAL_ID): cv.declare_id(LightHAL),
  51. cv.GenerateID(CONF_RED_ID): cv.declare_id(LEDCOutput),
  52. cv.Optional(CONF_RED, default="GPIO13"): pins.validate_gpio_pin,
  53. cv.GenerateID(CONF_GREEN_ID): cv.declare_id(LEDCOutput),
  54. cv.Optional(CONF_GREEN, default="GPIO14"): pins.validate_gpio_pin,
  55. cv.GenerateID(CONF_BLUE_ID): cv.declare_id(LEDCOutput),
  56. cv.Optional(CONF_BLUE, default="GPIO5"): pins.validate_gpio_pin,
  57. cv.GenerateID(CONF_WHITE_ID): cv.declare_id(LEDCOutput),
  58. cv.Optional(CONF_WHITE, default="GPIO12"): pins.validate_gpio_pin,
  59. cv.GenerateID(CONF_MASTER1_ID): cv.declare_id(GPIOBinaryOutput),
  60. cv.Optional(CONF_MASTER1, default="GPIO33"): pins.validate_gpio_pin,
  61. cv.GenerateID(CONF_MASTER2_ID): cv.declare_id(GPIOBinaryOutput),
  62. cv.Optional(CONF_MASTER2, default="GPIO4"): pins.validate_gpio_pin,
  63. # Front panel I2C
  64. cv.GenerateID(CONF_FRONT_PANEL_HAL_ID): cv.declare_id(FrontPanelHAL),
  65. cv.GenerateID(CONF_FP_I2C_ID): cv.use_id(I2CComponent),
  66. cv.Optional(CONF_SDA, default="GPIO21"): pins.validate_gpio_pin,
  67. cv.Optional(CONF_SCL, default="GPIO19"): pins.validate_gpio_pin,
  68. cv.Optional(CONF_ADDRESS, default="0x2C"): cv.i2c_address,
  69. cv.Optional(CONF_TRIGGER_PIN, default="GPIO16"): cv.All(
  70. pins.validate_gpio_pin,
  71. pins.validate_has_interrupt
  72. ),
  73. })
  74. async def make_gpio(number, mode="OUTPUT"):
  75. return await cg.gpio_pin_expression({ "number": number, "mode": mode });
  76. async def make_gpio_binary_output(id_, number):
  77. gpio_var = await make_gpio(number)
  78. output_var = cg.new_Pvariable(id_)
  79. cg.add(output_var.set_pin(gpio_var))
  80. return await cg.register_component(output_var, {})
  81. async def make_ledc_output(id_, number, frequency, channel):
  82. gpio_var = await make_gpio(number)
  83. ledc_var = cg.new_Pvariable(id_, gpio_var)
  84. cg.add(ledc_var.set_frequency(frequency));
  85. cg.add(ledc_var.set_channel(channel));
  86. return await cg.register_component(ledc_var, {})
  87. async def make_light_hal(config):
  88. r_var = await make_ledc_output(config[CONF_RED_ID], config[CONF_RED], 3000, 0)
  89. g_var = await make_ledc_output(config[CONF_GREEN_ID], config[CONF_GREEN], 3000, 1)
  90. b_var = await make_ledc_output(config[CONF_BLUE_ID], config[CONF_BLUE], 3000, 2)
  91. w_var = await make_ledc_output(config[CONF_WHITE_ID], config[CONF_WHITE], 10000, 4)
  92. m1_var = await make_gpio_binary_output(config[CONF_MASTER1_ID], config[CONF_MASTER1])
  93. m2_var = await make_gpio_binary_output(config[CONF_MASTER2_ID], config[CONF_MASTER2])
  94. light_hal = cg.new_Pvariable(config[CONF_LIGHT_HAL_ID])
  95. await cg.register_component(light_hal, config)
  96. cg.add(light_hal.set_red_pin(r_var))
  97. cg.add(light_hal.set_green_pin(g_var))
  98. cg.add(light_hal.set_blue_pin(b_var))
  99. cg.add(light_hal.set_white_pin(w_var))
  100. cg.add(light_hal.set_master1_pin(m1_var))
  101. cg.add(light_hal.set_master2_pin(m2_var))
  102. async def make_front_panel_hal(config):
  103. trigger_pin = await make_gpio(config[CONF_TRIGGER_PIN], "INPUT")
  104. fp_hal = cg.new_Pvariable(config[CONF_FRONT_PANEL_HAL_ID])
  105. await cg.register_component(fp_hal, config)
  106. cg.add(fp_hal.set_trigger_pin(trigger_pin))
  107. # The i2c component automatically sets up one I2C bus.
  108. # Take that bus and update is to make it work for the
  109. # front panel I2C communication.
  110. fp_i2c_var = await cg.get_variable(config[CONF_FP_I2C_ID])
  111. cg.add(fp_i2c_var.set_sda_pin(config[CONF_SDA]))
  112. cg.add(fp_i2c_var.set_scl_pin(config[CONF_SCL]))
  113. cg.add(fp_i2c_var.set_scan(True))
  114. cg.add(fp_hal.set_i2c_parent(fp_i2c_var))
  115. cg.add(fp_hal.set_i2c_address(config[CONF_ADDRESS]))
  116. async def to_code(config):
  117. # Dirty little hack to make the ESPHome component loader include
  118. # the code for the "gpio" platform for the "output" domain.
  119. # Loading specific platform components is not possible using
  120. # the AUTO_LOAD feature unfortunately.
  121. CORE.config["output"].append({ CONF_PLATFORM: "gpio" })
  122. await make_light_hal(config)
  123. await make_front_panel_hal(config)