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.

340 lines
14 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
  4. look at the [example.yaml](example.yaml) file from the project documentation.
  5. This configuration was written with the functionality of the original firmware in mind
  6. and it makes use of all available options. This configuration guide can be used to
  7. fill in the blanks.
  8. The `xiaomi_bslamp2` platform provides various components that expose the core functionalities of the lamp.
  9. In the following table, you can find what components are used for exposing what parts 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
  22. hub-style hardware abstraction layer (HAL) components that are used by the other components:
  23. one for driving the GPIO's for the RGBWW leds and one for the I2C communication between
  24. the ESP32 and the front panel.
  25. I do mention it here for completeness sake, but generally you will not have to add the
  26. 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
  28. for the Bedside Lamp 2 wiring out of the box.
  29. Therefore, you will not find this piece of configuration in 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
  47. file, would be if you blew one or more or the ESP32 pins, and need to rewire functions
  48. to different pins.
  49. ## Component: light
  50. The light component creates an RGBWW light. This means that it can do colored light and
  51. cold/warm 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
  84. button is tapped)
  85. * **default_transition_length** (*Optional*, Time): The transition length to use when
  86. no transition length is set in a light call. Defaults to 1s.
  87. * **effects** (*Optional*, list): A list of [light effects](https://esphome.io/components/light/index.html#light-effects)
  88. to use for this light.
  89. * **presets** (*Optional*, dict): Used to define presets, that can be used from automations.
  90. See [below](#light-presets) for detailed information.
  91. * **on_brightness** (*Optional*, Action): An automation to perform when the brightness of the light is modified.
  92. * All other options from [the base Light implementation](https://esphome.io/components/light/index.html#config-light),
  93. except for options that handle color correction options like `gamma_correct` and `color_correct`.
  94. These options are superceded by the fact that the light component has a fully customized
  95. light model, that closely follows the light model of the original lamp's firmware.
  96. ### Light modes
  97. The lamp supports multiple light modes. These are:
  98. * **RGB light** (input: RGB + brightness)
  99. * **White light** (input: Color Temperature + brightness)
  100. * **Night light** (input: either RGB or Color Temperature + brightness at 1%)
  101. In the original firmware + Yeelight Home Assistant integration, the night light feature is
  102. implemented through a switch component. The switch can be turned on to activate the night
  103. light mode. In this ESPHome firmware, setting the brightness to its lowest value triggers
  104. the night light mode. This makes things a lot easier to control.
  105. It is possible to control the night light mode separately. An example of this can be
  106. found in the [example.yaml](example.yaml), in which holding the power button is bound
  107. to activating the night light.
  108. ### Light presets
  109. The presets functionality was written with the original lamp firemware functionality in mind:
  110. the user has two groups of presets available: one for RGB light presets and one for white light
  111. presets (based on color temperature). The color button (the top one on the front panel) can be
  112. tapped to switch to the next preset within the active preset group. The same button can be
  113. held for a little while, to switch to the other preset group.
  114. In your light configuration, you can mimic this behavior (in fact: it is done so in the
  115. [example.yaml](example.yaml)) by means of the presets system. This system consists of two
  116. parts:
  117. * Defining presets
  118. * Activating presets from automations
  119. **Defining presets**
  120. Presets can be configured in the `presets` option of the `light` configuration.
  121. Presets are arranged in groups. You can define as little or as many groups as you like.
  122. The example configuration uses two groups, but that is only to mimic the original behavior.
  123. If you only need one group, then create one group. If you need ten, go ahead and knock yourself out.
  124. The general structure of the presets configuration is:
  125. ```yaml
  126. light:
  127. presets:
  128. group_1:
  129. preset_1: ...
  130. preset_2: ...
  131. ..
  132. group_2:
  133. preset_1: ...
  134. preset_2: ...
  135. ..
  136. ..
  137. ```
  138. *Note: duplicate template names are ok, as long as they are within their own group.
  139. If you use duplicate preset names within a single group, then the last preset will override the
  140. earlier one(s).*
  141. A preset can define one of the following:
  142. * **RGB light**
  143. * **red** (**Optional**, percentage): the red component of the RGB value (default = 0%).
  144. * **green** (**Optional**, percentage): the green component of the RGB value (default = 0%).
  145. * **blue** (**Optional**, percentage): the blue component of the RGB value (default = 0%).
  146. * **brightness** (*Optional*, percentage): the brightness to use (default = current brightness).
  147. * **transition_length** (*Optional*, time): the transition length to use.
  148. * **White light**
  149. * **color_temperature** (**Required**, mireds): the color temperature in mireds (range: "153 mireds" - "588 mireds")
  150. * **brightness** (*Optional*, percentage): the brightness to use (default = current brightness).
  151. * **transition_length** (*Optional*, time): the transition length to use.
  152. * **Light effect**
  153. * **effect** (**Required**, string): the name of a light effect to activate.
  154. * **Brightness change only**
  155. * **brightness** (**Required**, percentage): the brightness to use.
  156. **Activating presets from automations**
  157. Once presets have been configured, they can be activated using the `preset.activate` action.
  158. The following options are available for this action:
  159. * Switch to next preset group (and after the last, switch to the first):
  160. ```yaml
  161. preset.activate:
  162. next: group
  163. ```
  164. * Switch to next preset within currentl preset group (and after the last, switch to the first):
  165. ```yaml
  166. preset.activate:
  167. next: preset
  168. ---
  169. * Activate a specific preset group by specifying the group's name:
  170. ```yaml
  171. preset.activate:
  172. group: rgb
  173. ```
  174. * Activate a specific preset by specifying both the preset's name and group name:
  175. ```yaml
  176. preset.activate:
  177. group: white
  178. preset: warm
  179. ```
  180. Shorthand definitions are available for all these actions:
  181. ```yaml
  182. preset.activate: next_group
  183. preset.activate: next_preset
  184. preset.activate: rgb
  185. preset.activate: white.warm
  186. ```
  187. **Handling of invalid input**
  188. When a group or template is specified that does not exist, or if next group/preset
  189. is used while no presets have been defined at all, then the action will be ignored
  190. and an error will be logged.
  191. This is of course validation at run time. It would be better to validate the
  192. names at compile time more strictly, so the firmware won't compile when invalid
  193. names are in use. [Issue #15 was created for implementing this](https://github.com/mmakaay/esphome-xiaomi_bslamp2/issues/15).
  194. ## Component: binary_sensor
  195. Binary sensors can be added to the configuration for handling touch/release events
  196. for the front panel. On touch, a binary_sensor will publish `True`, on release it
  197. will publish `False`. The configuration of a binary_sensor determines what part
  198. or parts of the front panel are involved in the touch events.
  199. ```yaml
  200. binary_sensor:
  201. - platform: xiaomi_bslamp2
  202. id: my_bedside_lamp_power_button
  203. part: POWER_BUTTON
  204. on_press:
  205. then:
  206. - light.toggle: my_bedside_lamp
  207. ```
  208. For specifying specific parts of the front panel in the upcoming configuration variables,
  209. the following identifiers are available:
  210. * POWER_BUTTON (or its alias: POWER)
  211. * COLOR_BUTTON (or its alias: COLOR)
  212. * SLIDER
  213. ### Configuration variables:
  214. * **name** (*Optional*, string): The name of the binary sensor. Setting a name will expose the
  215. binary sensor as an entity in Home Assistant. If you do not need this, you can omit the name.
  216. * **id** (*Optional*, ID): Manually specify the ID used for code generation. By providing an id,
  217. you can reference the binary_sensor from automation rules (to retrieve the current state
  218. of the binary_sensor).
  219. * **part** (*Optional*, part identifier): This specifies what part of the front panel the binary sensor must
  220. look at. Valid options are: "any" (the default) or one of the abovementioned part identifiers.
  221. * All other options from [Binary Sensor](https://esphome.io/components/binary_sensor/index.html#config-binary-sensor).
  222. ## Component: sensor
  223. The sensor component publishes touch events for the front panel slider. The published value
  224. represents the level at which the slider was touched.
  225. *Note: This sensor only reports the touched slider level. It cannot be used for detecting release
  226. events. If you want to handle touch/release events for the slider, then you can make use of
  227. the [binary_sensor](#component-binary_sensor) instead.*
  228. ```yaml
  229. sensor:
  230. - platform: xiaomi_bslamp2
  231. - id: my_bedside_lamp_slider_level
  232. range_from: 0.2
  233. range_to: 0.9
  234. on_value:
  235. then:
  236. - light.turn_on:
  237. id: my_bedside_lamp
  238. brightness: !lambda return x;
  239. ```
  240. ### Configuration variables:
  241. * **name** (*Optional*, string): The name of the sensor. Setting a name will expose the
  242. sensor as an entity in Home Assistant. If you do not need this, you can omit the name.
  243. * **id** (*Optional*, ID): Manually specify the ID used for code generation. By providing an id,
  244. you can reference the sensor from automation rules (e.g. to retrieve the current state
  245. of the binary_sensor).
  246. * **range_from** (*Optional*, float): By default, published values vary from the range 0.01 to 1.00,
  247. in 20 steps. This option modifies the lower bound of the range.
  248. * **range_to** (*Optional*, float): This option modifies the upper bound of the range.
  249. * All other options from [Sensor](https://esphome.io/components/sensor/index.html#config-sensor).
  250. ## Component: output
  251. The (float) output component is linked to the front panel illumination + level indicator.
  252. Setting this output to value 0.0 will turn off the frontpanel illumination. Other values,
  253. up to 1.0, will turn on the illumination and will set the level indicator to the requested
  254. level (in 10 steps).
  255. ```yaml
  256. output:
  257. - platform: xiaomi_bslamp2
  258. id: my_bedside_lamp_front_panel_illumination
  259. ```
  260. ### Configuration variables:
  261. * **id** (**Required**, ID): The id to use for this output component.
  262. * All other options from [Output](https://esphome.io/components/output/index.html)
  263. ## Component: text_sensor
  264. The text sensor component publishes changes in the active [light mode](#light-modes).
  265. Possible output values for this sensor are: "off", "rgb", "white" and "night".
  266. ### Configuration variables:
  267. * **name** (*Optional*, string): The name of the text sensor. Setting a name will expose the
  268. text sensor as an entity in Home Assistant. If you do not need this, you can omit the name.
  269. * **id** (*Optional*, ID): Manually specify the ID used for code generation. By providing an id,
  270. you can reference the text sensor from automation rules (to retrieve the current state
  271. of the text_sensor).
  272. * All other options from [Text Sensor](https://esphome.io/components/text_sensor/index.html)
  273. < [Installation guide](installation.md) | [Index](../README.md) | [Flashing guide](flashing.md) >