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.

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