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.

472 lines
18 KiB

  1. < [Installation guide](installation.md) | [Index](../README.md) | [Flashing guide](flashing.md) >
  2. # Configuration guide
  3. I think, the best starting point for creating your own yaml configuration, is to look at the
  4. [`example.yaml`](../example.yaml) file from the project documentation. This configuration was written
  5. with the functionality of the original firmware in mind and it makes use of all available options.
  6. This configuration guide can be used to fill in the blanks.
  7. The `xiaomi_bslamp2` platform provides various components that expose the core functionalities of
  8. the lamp. In the following table, you can find what components are used for exposing what physical
  9. components of the lamp.
  10. | Part | Component(s) |
  11. | -------------------------- |------------------------------------------------------------------|
  12. | ESP32 pinouts | [platform xiaomi_bslamp2](#platform-xiaomi_bslamp2) |
  13. | RGBWW LEDs | [light](#light) |
  14. | Front Panel Power button | [binary_sensor](#component-binary_sensor) |
  15. | Front Panel Color button | [binary_sensor](#component-binary_sensor) |
  16. | Front Panel Slider | [binary_sensor](#component-binary_sensor) (touch/release) |
  17. | | [sensor](#component-sensor) (touched slider level) |
  18. | Front Panel Illumination | [output](#component-output) (on/off + indicator level) |
  19. | Light mode propagation | [text_sensor](#component-text_sensor) |
  20. ## Platform: xiaomi_bslamp2
  21. At the core of the hardware support is the `xiaomi_bslamp2` platform, which provides two hub-style
  22. hardware abstraction layer (HAL) components that are used by the other components: one for driving
  23. the GPIO's for the RGBWW leds and one for the I2C communication between the ESP32 and the front
  24. panel.
  25. I do mention the platform configuration here for completeness sake, but **generally you will not have
  26. to add the following configuration option to your yaml file**. It is loaded automatically by the
  27. components that need it, and the GPIO + I2C configurations are fully prepared to work for the
  28. Bedside Lamp 2 wiring out of the box. Therefore, you will not find this piece of configuration in
  29. the [`example.yaml`](../example.yaml).
  30. Having said that, here are the configuration options:
  31. ```yaml
  32. xiaomi_bslamp2:
  33. # Options for the RGBWW LEDs HAL.
  34. red: "GPIO13"
  35. green: "GPIO14"
  36. blue: "GPIO5"
  37. white: "GPIO12"
  38. master_1: "GPIO33"
  39. master_2: "GPIO4"
  40. # Options for the Front Panel HAL.
  41. sda: "GPIO21"
  42. scl: "GPIO19"
  43. address: 0x2C
  44. trigger_pin: "GPIO16"
  45. ```
  46. The only reason that I can think of for adding this platform configuration to your yaml file, would
  47. be if you blew one or more or the ESP32 pins, and need to rewire functionality. In other casis,
  48. simply omit the section.
  49. ## Component: light
  50. The light component creates an RGBWW light. This means that it can do colored light and cold/warm
  51. white light based on a color temperature.
  52. ```yaml
  53. light:
  54. - platform: xiaomi_bslamp2
  55. name: My Bedside Lamp
  56. id: my_bedside_lamp
  57. default_transition_length: 0.5s
  58. effects:
  59. - random:
  60. name: Randomize
  61. transition_length: 3s
  62. update_interval: 3s
  63. on_brightness:
  64. - then:
  65. - logger.log: The brightness changed!
  66. presets:
  67. my_color_presets:
  68. red: { red: 100%, green: 0%, blue: 0% }
  69. green: { red: 0%, green: 100%, blue: 0% }
  70. blue: { red: 0%, green: 0%, blue: 100% }
  71. yellow: { red: 100%, green: 100%, blue: 0% }
  72. purple: { red: 100%, green: 0%, blue: 100% }
  73. randomize: { effect: Randomize }
  74. my_white_presets:
  75. cold: { color_temperature: 153 mireds }
  76. chilly: { color_temperature: 275 mireds }
  77. luke: { color_temperature: 400 mireds }
  78. warm: { color_temperature: 588 mireds
  79. ```
  80. ### Configuration variables:
  81. * **name** (**Required**, string): The name of the light.
  82. * **id** (*Optional*, ID): Manually specify the ID used for code generation. By providing an id,
  83. you can reference the light from automation rules (e.g. to turn on the light when the power button
  84. is tapped)
  85. * **default_transition_length** (*Optional*, Time): The transition length to use when no transition
  86. length is set in a light call. Defaults to 1s.
  87. * **effects** (*Optional*, list): A list of
  88. [light effects](https://esphome.io/components/light/index.html#light-effects) to use for this light.
  89. * **presets** (*Optional*, dict): Used to define presets, that can be used from automations. See
  90. [below](#light-presets) for detailed information.
  91. * **on_brightness** (*Optional*, Action): An automation to perform when the brightness of the light
  92. is modified.
  93. * All other options from
  94. [the base Light implementation](https://esphome.io/components/light/index.html#config-light),
  95. except for options that handle color correction options like `gamma_correct` and `color_correct`.
  96. These options are superceded by the fact that the light component has a fully customized light
  97. model, that closely follows the light model of the original lamp's firmware.
  98. ### Light modes
  99. The lamp supports multiple light modes. These are:
  100. * **RGB light** (input: RGB + brightness > 1%)
  101. * **White light** (input: Color Temperature + brightness > 1%)
  102. * **Night light** (input: RGB or White light + brightness at 1%)
  103. In the original firmware + Yeelight Home Assistant integration, the night light feature is
  104. implemented through a switch component. The switch can be turned on to activate the night light
  105. mode. In this ESPHome firmware, setting the brightness to its lowest value triggers the night light
  106. mode. This makes things a lot easier to control.
  107. It is possible to control the night light mode separately. An example of this can be found in the
  108. [example.yaml](../example.yaml), in which holding the power button is bound to activating the night
  109. light.
  110. ### `light.disco_on` Action
  111. This action sets the state of the light immediately (i.e. without waiting for the next main loop
  112. iteration), without saving the state to memory and without publishing the state change.
  113. ```yaml
  114. on_...:
  115. then:
  116. - light.disco_on:
  117. id: my_bedside_lamp
  118. brightness: 80%
  119. red: 70%
  120. green: 0%
  121. blue: 100%
  122. ```
  123. The possible configuration options for this Action are the same as those for the standard
  124. `light.turn_on` Action.
  125. ### `light.disco_off` Action
  126. This action turns off the disco mode by restoring the state of the lamp to the last known state from
  127. before using the disco mode.
  128. ```yaml
  129. on_...:
  130. then:
  131. - light.disco_off:
  132. id: my_bedside_lamp
  133. ```
  134. ### Light presets
  135. The presets functionality was written with the original lamp firemware functionality in mind: the
  136. user has two groups of presets available: one for RGB light presets and one for white light presets
  137. (based on color temperature). The color button (the top one on the front panel) can be tapped to
  138. switch to the next preset within the active preset group. The same button can be held for a little
  139. while, to switch to the other preset group.
  140. In your light configuration, you can mimic this behavior (in fact: it is done so in the
  141. [example.yaml](../example.yaml)) by means of the presets system. This system consists of two parts:
  142. * Defining presets
  143. * Activating presets from automations
  144. **Defining presets**
  145. Presets can be configured in the `presets` option of the `light` configuration.
  146. Presets are arranged in groups. You can define as little or as many groups as you like. The example
  147. configuration uses two groups, but that is only to mimic the original behavior. If you only need one
  148. group, then create one group. If you need ten, go ahead and knock yourself out.
  149. The general structure of the presets configuration is:
  150. ```yaml
  151. light:
  152. presets:
  153. group_1:
  154. preset_1: ...
  155. preset_2: ...
  156. ..
  157. group_2:
  158. preset_1: ...
  159. preset_2: ...
  160. ..
  161. ..
  162. ```
  163. *Note: Duplicate template names are ok, as long as they are within their own group. If you use
  164. duplicate preset names within a single group, then the last preset will override the earlier
  165. one(s).*
  166. A preset can define one of the following:
  167. * **RGB light**
  168. * **red** (**Optional**, percentage): the red component of the RGB value (default = 0%).
  169. * **green** (**Optional**, percentage): the green component of the RGB value (default = 0%).
  170. * **blue** (**Optional**, percentage): the blue component of the RGB value (default = 0%).
  171. * **brightness** (*Optional*, percentage): the brightness to use (default = current brightness).
  172. * **transition_length** (*Optional*, time): the transition length to use.
  173. * **White light**
  174. * **color_temperature** (**Required**, mireds): the color temperature in mireds (range: "153 mireds" - "588 mireds")
  175. * **brightness** (*Optional*, percentage): the brightness to use (default = current brightness).
  176. * **transition_length** (*Optional*, time): the transition length to use.
  177. * **Light effect**
  178. * **effect** (**Required**, string): the name of a light effect to activate.
  179. * **Brightness change only**
  180. * **brightness** (**Required**, percentage): the brightness to use.
  181. **Activating presets from automations**
  182. Once presets have been configured, they can be activated using the `preset.activate` action. The
  183. following options are available for this action:
  184. * Switch to next preset group (and after the last, switch to the first):
  185. ```yaml
  186. preset.activate:
  187. next: group
  188. ```
  189. * Switch to next preset within currentl preset group (and after the last,
  190. switch to the first):
  191. ```yaml
  192. preset.activate:
  193. next: preset
  194. ---
  195. * Activate a specific preset group by specifying the group's name:
  196. ```yaml
  197. preset.activate:
  198. group: rgb
  199. ```
  200. * Activate a specific preset by specifying both the preset's name and group name:
  201. ```yaml
  202. preset.activate:
  203. group: white
  204. preset: warm
  205. ```
  206. Shorthand definitions are available for all these actions:
  207. ```yaml
  208. preset.activate: next_group
  209. preset.activate: next_preset
  210. preset.activate: rgb
  211. preset.activate: white.warm
  212. ```
  213. **Handling of invalid input**
  214. When a group or template is specified that does not exist, or if next group/preset is used while no
  215. presets have been defined at all, then the action will be ignored and an error will be logged.
  216. *Note: This is validation at run time. It would be a lot better to validate the names at compile
  217. time more strictly, so the firmware will not even compile when invalid names are in use.
  218. [Issue #15](https://github.com/mmakaay/esphome-xiaomi_bslamp2/issues/15) was created for
  219. implementing this. However, a new feature in ESPHome is required to be able to do this
  220. implementation. Good news is that this is already well on its way.*
  221. ## Component: binary_sensor
  222. Binary sensors can be added to the configuration for handling touch/release events for the front
  223. panel. On touch, a binary_sensor will publish `True`, on release it will publish `False`. The
  224. configuration of a binary_sensor determines what part of the front panel is involved in the touch
  225. events.
  226. ```yaml
  227. binary_sensor:
  228. - platform: xiaomi_bslamp2
  229. id: my_bedside_lamp_power_button
  230. for: POWER_BUTTON
  231. on_press:
  232. then:
  233. - light.toggle: my_bedside_lamp
  234. ```
  235. For referencing the parts of the front panel, the following part identifiers are available:
  236. * POWER_BUTTON (or its alias: POWER)
  237. * COLOR_BUTTON (or its alias: COLOR)
  238. * SLIDER
  239. If personal taste dictates so, you can use lower case characters and spaces instead of underscores.
  240. This means that for example "Power Button" and "power" would be valid identifiers for the power
  241. button.
  242. ### Configuration variables:
  243. * **name** (*Optional*, string): The name of the binary sensor. Setting a name will expose the
  244. binary sensor as an entity in Home Assistant. If you do not need this, you can omit the name.
  245. * **id** (*Optional*, ID): Manually specify the ID used for code generation. By providing an id,
  246. you can reference the binary_sensor from automation rules (to retrieve the current state of the
  247. binary_sensor).
  248. * **for** (*Mandatory*, part identifier): This specifies to for part of the front panel the binary
  249. sensor must report touch events.
  250. * All other options from
  251. [Binary Sensor](https://esphome.io/components/binary_sensor/index.html#config-binary-sensor).
  252. ## Component: sensor
  253. The sensor component publishes touch events for the front panel slider. The published value
  254. represents the level at which the slider was touched.
  255. *Note: This sensor only reports the touched slider level. It cannot be used for detecting release
  256. events. If you want to handle touch/release events for the slider, then you can make use of the
  257. [binary_sensor](#component-binary_sensor) instead.*
  258. ```yaml
  259. sensor:
  260. - platform: xiaomi_bslamp2
  261. - id: my_bedside_lamp_slider_level
  262. range_from: 0.2
  263. range_to: 0.9
  264. on_value:
  265. then:
  266. - light.turn_on:
  267. id: my_bedside_lamp
  268. brightness: !lambda return x;
  269. ```
  270. ### Configuration variables:
  271. * **name** (*Optional*, string): The name of the sensor. Setting a name will expose the sensor as an
  272. entity in Home Assistant. If you do not need this, you can omit the name.
  273. * **id** (*Optional*, ID): Manually specify the ID used for code generation. By providing an id,
  274. you can reference the sensor from automation rules (e.g. to retrieve the current state of the
  275. binary_sensor).
  276. * **range_from** (*Optional*, float): By default, published values vary from the range 0.01 to 1.00,
  277. in 20 steps. This option modifies the lower bound of the range.
  278. * **range_to** (*Optional*, float): This option modifies the upper bound of the range.
  279. * All other options from
  280. [Sensor](https://esphome.io/components/sensor/index.html#config-sensor).
  281. ## Component: output
  282. The (float) output component is linked to the front panel illumination + level indicator. Setting
  283. this output (using the standard `output.set_level` action) to value 0.0 will turn off the frontpanel
  284. illumination. Other values, up to 1.0, will turn on the illumination and will set the level indicator
  285. to the requested level (in 10 steps).
  286. ```yaml
  287. output:
  288. - platform: xiaomi_bslamp2
  289. id: my_bedside_lamp_front_panel_illumination
  290. ```
  291. ### Configuration variables:
  292. * **id** (**Required**, ID): The id to use for this output component.
  293. * All other options from [Output](https://esphome.io/components/output/index.html)
  294. ### Addressing the LEDs of the illumination individually
  295. While the standard `output.set_level` action emulates the front panel illumination behavior
  296. of the original device firmware, it is also possible to control all of the LEDs for this
  297. illumination individually, in case you need some different behavior, e.g. leaving the
  298. power button on at night, so the user can easily find it in the dark.
  299. To address the LEDs, the following identifiers can be used in your YAML configuration:
  300. * `POWER` : The power button illumination.
  301. * `COLOR` : The color button illumination.
  302. * `1`, `2`, .., `10` : The 10 LEDs on the slider, where LED `1` is closest to the
  303. power button and LED `10` is closest to the color button.
  304. * `ALL` : represents all of the available LEDs
  305. * `NONE` : represents none of the available LEDs
  306. #### `front_panel.set_leds` Action
  307. This action turns on the provided LEDs, all other LEDs are turned off.
  308. ```yaml
  309. on_...:
  310. then:
  311. - front_panel.set_leds:
  312. leds:
  313. - POWER
  314. - COLOR
  315. - 1
  316. - 2
  317. - 3
  318. ```
  319. The `leds:` key can also be omitted here, making the following action calls
  320. equivalent to the one above.
  321. ```yaml
  322. on_...:
  323. then:
  324. - front_panel.set_leds:
  325. - POWER
  326. - COLOR
  327. - 1
  328. - 2
  329. - 3
  330. ```
  331. This can also be written as:
  332. ```yaml
  333. on_...:
  334. then:
  335. - front_panel.set_leds: [ POWER, COLOR, 1, 2, 3 ]
  336. ```
  337. If only one LED is specified, you are allowed to omit the list;
  338. ```yaml
  339. on_...:
  340. then:
  341. - front_panel.set_leds: POWER
  342. ```
  343. #### `front_panel.turn_on_leds` Action
  344. This action turns on the provided LEDs, and leaves the rest of the LEDs as-is.
  345. The LEDs to affect are specified in the same wat as above for `front_panel.set_leds`.
  346. #### `front_panel.turn_off_leds` Action
  347. This action turns off the provided LEDs, and leaves the rest of the LEDs as-is.
  348. The LEDs to affect are specified in the same wat as above for `front_panel.set_leds`.
  349. #### `front_panel.update_leds` Action
  350. The previous actions only modify the required state for the front panel LEDs.
  351. Updating the actual state of the LEDs is done when the main loop for the
  352. output component is run by ESPHome.
  353. If you need the required state to be pushed to the LEDs immediately, regardless
  354. the main loop, then this action can ben used to take care of this.
  355. *Note: In most situations, you will not need to use this action explicitly
  356. to make the LEDs update. Only use it when you are sure that this is required.*
  357. ```yaml
  358. on_...:
  359. then:
  360. - front_panel.set_leds: POWER
  361. - front_panel.update_leds:
  362. ```
  363. ## Component: text_sensor
  364. The text sensor component publishes changes in the active [light mode](#light-modes). Possible
  365. output values for this sensor are: "off", "rgb", "white" and "night".
  366. ### Configuration variables:
  367. * **name** (*Optional*, string): The name of the text sensor. Setting a name will expose the text
  368. sensor as an entity in Home Assistant. If you do not need this, you can omit the name.
  369. * **id** (*Optional*, ID): Manually specify the ID used for code generation. By providing an id,
  370. you can reference the text sensor from automation rules (to retrieve the current state of the
  371. text_sensor).
  372. * All other options from
  373. [Text Sensor](https://esphome.io/components/text_sensor/index.html)
  374. < [Installation guide](installation.md) | [Index](../README.md) | [Flashing guide](flashing.md) >