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.

467 lines
18 KiB

3 years ago
  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. *Note: This is validation at run time. It would be a lot better to validate the names at compile
  203. time more strictly, so the firmware will not even compile when invalid names are in use.
  204. [Issue #15](https://github.com/mmakaay/esphome-xiaomi_bslamp2/issues/15) was created for
  205. implementing this. However, a new feature in ESPHome is required to be able to do this
  206. implementation. Good news is that this is already well on its way.*
  207. ## Component: binary_sensor
  208. Binary sensors can be added to the configuration for handling touch/release events for the front
  209. panel. On touch, a binary_sensor will publish `True`, on release it will publish `False`. The
  210. configuration of a binary_sensor determines what part of the front panel is involved in the touch
  211. events.
  212. ```yaml
  213. binary_sensor:
  214. - platform: xiaomi_bslamp2
  215. id: my_bedside_lamp_power_button
  216. for: POWER_BUTTON
  217. on_press:
  218. then:
  219. - light.toggle: my_bedside_lamp
  220. ```
  221. For referencing the parts of the front panel, the following part identifiers are available:
  222. * POWER_BUTTON (or its alias: POWER)
  223. * COLOR_BUTTON (or its alias: COLOR)
  224. * SLIDER
  225. If personal taste dictates so, you can use lower case characters and spaces instead of underscores.
  226. This means that for example "Power Button" and "power" would be valid identifiers for the power
  227. button.
  228. ### Configuration variables:
  229. * **name** (*Optional*, string): The name of the binary sensor. Setting a name will expose the
  230. binary sensor as an entity in Home Assistant. If you do not need this, you can omit the name.
  231. * **id** (*Optional*, ID): Manually specify the ID used for code generation. By providing an id,
  232. you can reference the binary_sensor from automation rules (to retrieve the current state of the
  233. binary_sensor).
  234. * **for** (*Mandatory*, part identifier): This specifies to for part of the front panel the binary
  235. sensor must report touch events.
  236. * All other options from
  237. [Binary Sensor](https://esphome.io/components/binary_sensor/index.html#config-binary-sensor).
  238. ## Component: sensor
  239. The sensor component publishes touch events for the front panel slider. The published value
  240. represents the level at which the slider was touched.
  241. *Note: This sensor only reports the touched slider level. It cannot be used for detecting release
  242. events. If you want to handle touch/release events for the slider, then you can make use of the
  243. [binary_sensor](#component-binary_sensor) instead.*
  244. ```yaml
  245. sensor:
  246. - platform: xiaomi_bslamp2
  247. - id: my_bedside_lamp_slider_level
  248. range_from: 0.2
  249. range_to: 0.9
  250. on_value:
  251. then:
  252. - light.turn_on:
  253. id: my_bedside_lamp
  254. brightness: !lambda return x;
  255. ```
  256. ### Configuration variables:
  257. * **name** (*Optional*, string): The name of the sensor. Setting a name will expose the sensor as an
  258. entity in Home Assistant. If you do not need this, you can omit the name.
  259. * **id** (*Optional*, ID): Manually specify the ID used for code generation. By providing an id,
  260. you can reference the sensor from automation rules (e.g. to retrieve the current state of the
  261. binary_sensor).
  262. * **range_from** (*Optional*, float): By default, published values vary from the range 0.01 to 1.00,
  263. in 20 steps. This option modifies the lower bound of the range.
  264. * **range_to** (*Optional*, float): This option modifies the upper bound of the range.
  265. * All other options from
  266. [Sensor](https://esphome.io/components/sensor/index.html#config-sensor).
  267. ## Component: output
  268. The (float) output component is linked to the front panel illumination + level indicator. Setting
  269. this output (using the standard `output.set_level` action) to value 0.0 will turn off the frontpanel
  270. illumination. Other values, up to 1.0, will turn on the illumination and will set the level indicator
  271. to the requested level (in 10 steps).
  272. ```yaml
  273. output:
  274. - platform: xiaomi_bslamp2
  275. id: my_bedside_lamp_front_panel_illumination
  276. ```
  277. ### Configuration variables:
  278. * **id** (**Required**, ID): The id to use for this output component.
  279. * All other options from [Output](https://esphome.io/components/output/index.html)
  280. ### Addressing the LEDs of the illumination individually
  281. While the standard `output.set_level` action emulates the front panel illumination behavior
  282. of the original device firmware, it is also possible to control all of the LEDs for this
  283. illumination individually, in case you need some different behavior, e.g. leaving the
  284. power button on at night, so the user can easily find it in the dark.
  285. To address the LEDs, the following identifiers can be used in your YAML configuration:
  286. * `POWER` : The power button illumination.
  287. * `COLOR` : The color button illumination.
  288. * `1`, `2`, .., `10` : The 10 LEDs on the slider, where LED `1` is closest to the
  289. power button and LED `10` is closest to the color button.
  290. * `ALL` : represents all of the available LEDs
  291. * `NONE` : represents none of the available LEDs
  292. #### `front_panel.set_leds` Action
  293. This action turns on the provided LEDs, all other LEDs are turned off.
  294. ```yaml
  295. on_...:
  296. then:
  297. - front_panel.set_leds:
  298. leds:
  299. - POWER
  300. - COLOR
  301. - 1
  302. - 2
  303. - 3
  304. ```
  305. The `leds:` key can also be omitted here, making the following action calls
  306. equivalent to the one above.
  307. ```yaml
  308. on_...:
  309. then:
  310. - front_panel.set_leds:
  311. - POWER
  312. - COLOR
  313. - 1
  314. - 2
  315. - 3
  316. ```
  317. This can also be written as:
  318. ```yaml
  319. on_...:
  320. then:
  321. - front_panel.set_leds: [ POWER, COLOR, 1, 2, 3 ]
  322. ```
  323. If only one LED is specified, you are allowed to omit the list definition:
  324. ```yaml
  325. on_...:
  326. then:
  327. - front_panel.set_leds: POWER
  328. ```
  329. #### `front_panel.turn_on_leds` Action
  330. This action turns on the provided LEDs, and leaves the rest of the LEDs as-is.
  331. The LEDs to affect are specified in the same wat as above for `front_panel.set_leds`.
  332. #### `front_panel.turn_off_leds` Action
  333. This action turns off the provided LEDs, and leaves the rest of the LEDs as-is.
  334. The LEDs to affect are specified in the same wat as above for `front_panel.set_leds`.
  335. #### `front_panel.set_level` Action
  336. This action works like the `output.set_level` action, but it only updates the
  337. LEDs of the slider. The LEDs for the power and color button are left as-is.
  338. ```yaml
  339. on_...:
  340. then:
  341. - front_panel.set_level: 0.5
  342. ```
  343. #### `front_panel.update_leds` Action
  344. The previous actions only modify the required state for the front panel LEDs.
  345. Updating the actual state of the LEDs is done when the main loop for the
  346. output component is run by ESPHome.
  347. If you need the required state to be pushed to the LEDs immediately, regardless
  348. the main loop, then this action can ben used to take care of this.
  349. *Note: In most situations, you will not need to use this action explicitly
  350. to make the LEDs update. Only use it when you are sure that this is required.*
  351. ```yaml
  352. on_...:
  353. then:
  354. - front_panel.set_leds: POWER
  355. - front_panel.update_leds:
  356. ```
  357. ## Component: text_sensor
  358. The text sensor component publishes changes in the active [light mode](#light-modes). Possible
  359. output values for this sensor are: "off", "rgb", "white" and "night".
  360. ### Configuration variables:
  361. * **name** (*Optional*, string): The name of the text sensor. Setting a name will expose the text
  362. sensor as an entity in Home Assistant. If you do not need this, you can omit the name.
  363. * **id** (*Optional*, ID): Manually specify the ID used for code generation. By providing an id,
  364. you can reference the text sensor from automation rules (to retrieve the current state of the
  365. text_sensor).
  366. * All other options from
  367. [Text Sensor](https://esphome.io/components/text_sensor/index.html)
  368. < [Installation guide](installation.md) | [Index](../README.md) | [Flashing guide](flashing.md) >