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.

372 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,
  4. is to look at the [example.yaml](example.yaml) file from the project
  5. documentation. This configuration was written with the functionality of the
  6. original firmware in mind and it makes use of all available options. This
  7. configuration guide can be used to fill in the blanks.
  8. The `xiaomi_bslamp2` platform provides various components that expose the
  9. core functionalities of the lamp. In the following table, you can find what
  10. components are used for exposing what physical 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
  23. provides two hub-style hardware abstraction layer (HAL) components that are
  24. used by the other components: one for driving the GPIO's for the RGBWW leds
  25. and one for the I2C communication between the ESP32 and the front panel.
  26. I do mention the platform configuration here for completeness sake, but
  27. generally you will not have to add the following configuration option to
  28. your yaml file. It is loaded automatically by the components that need it,
  29. and the GPIO + I2C configurations are fully prepared to work for the Bedside
  30. Lamp 2 wiring out of the box. Therefore, you will not find this piece of
  31. configuration in the [example.yaml](example.yaml).
  32. Having said that, here are the configuration options:
  33. ```yaml
  34. xiaomi_bslamp2:
  35. # Options for the RGBWW LEDs HAL.
  36. red: "GPIO13"
  37. green: "GPIO14"
  38. blue: "GPIO5"
  39. white: "GPIO12"
  40. master_1: "GPIO33"
  41. master_2: "GPIO4"
  42. # Options for the Front Panel HAL.
  43. sda: "GPIO21"
  44. scl: "GPIO19"
  45. address: 0x2C
  46. trigger_pin: "GPIO16"
  47. ```
  48. The only reason that I can think of for adding this platform configuration
  49. to your yaml file, would be if you blew one or more or the ESP32 pins, and
  50. need to rewire functionality. In other casis, simply omit the section.
  51. ## Component: light
  52. The light component creates an RGBWW light. This means that it can do
  53. colored light and cold/warm white light based on a color temperature.
  54. ```yaml
  55. light:
  56. - platform: xiaomi_bslamp2
  57. name: My Bedside Lamp
  58. id: my_bedside_lamp
  59. default_transition_length: 0.5s
  60. effects:
  61. - random:
  62. name: Randomize
  63. transition_length: 3s
  64. update_interval: 3s
  65. on_brightness:
  66. - then:
  67. - logger.log: The brightness changed!
  68. presets:
  69. my_color_presets:
  70. red: { red: 100%, green: 0%, blue: 0% }
  71. green: { red: 0%, green: 100%, blue: 0% }
  72. blue: { red: 0%, green: 0%, blue: 100% }
  73. yellow: { red: 100%, green: 100%, blue: 0% }
  74. purple: { red: 100%, green: 0%, blue: 100% }
  75. randomize: { effect: Randomize }
  76. my_white_presets:
  77. cold: { color_temperature: 153 mireds }
  78. chilly: { color_temperature: 275 mireds }
  79. luke: { color_temperature: 400 mireds }
  80. warm: { color_temperature: 588 mireds
  81. ```
  82. ### Configuration variables:
  83. * **name** (**Required**, string): The name of the light.
  84. * **id** (*Optional*, ID): Manually specify the ID used for code generation.
  85. By providing an id, you can reference the light from automation rules
  86. (e.g. to turn on the light when the power button is tapped)
  87. * **default_transition_length** (*Optional*, Time): The transition length to
  88. use when no transition length is set in a light call. Defaults to 1s.
  89. * **effects** (*Optional*, list): A list of
  90. [light effects](https://esphome.io/components/light/index.html#light-effects)
  91. to use for this light.
  92. * **presets** (*Optional*, dict): Used to define presets, that can be used
  93. from automations. See [below](#light-presets) for detailed information.
  94. * **on_brightness** (*Optional*, Action): An automation to perform when the
  95. brightness of the light is modified.
  96. * All other options from [the base Light
  97. implementation](https://esphome.io/components/light/index.html#config-light),
  98. except for options that handle color correction options like
  99. `gamma_correct` and `color_correct`. These options are superceded by the
  100. fact that the light component has a fully customized light model, that
  101. closely follows the light model of the original lamp's firmware.
  102. ### Light modes
  103. The lamp supports multiple light modes. These are:
  104. * **RGB light** (input: RGB + brightness > 1%)
  105. * **White light** (input: Color Temperature + brightness > 1%)
  106. * **Night light** (input: RGB or White light + brightness at 1%)
  107. In the original firmware + Yeelight Home Assistant integration, the night
  108. light feature is implemented through a switch component. The switch can be
  109. turned on to activate the night light mode. In this ESPHome firmware,
  110. setting the brightness to its lowest value triggers the night light mode.
  111. This makes things a lot easier to control.
  112. It is possible to control the night light mode separately. An example of
  113. this can be found in the [example.yaml](example.yaml), in which holding the
  114. power button is bound to activating the night light.
  115. ### Light presets
  116. The presets functionality was written with the original lamp firemware
  117. functionality in mind: the user has two groups of presets available: one for
  118. RGB light presets and one for white light presets (based on color
  119. temperature). The color button (the top one on the front panel) can be
  120. tapped to switch to the next preset within the active preset group. The same
  121. button can be held for a little while, to switch to the other preset group.
  122. In your light configuration, you can mimic this behavior (in fact: it is
  123. done so in the [example.yaml](example.yaml)) by means of the presets system.
  124. This system consists of two parts:
  125. * Defining presets
  126. * Activating presets from automations
  127. **Defining presets**
  128. Presets can be configured in the `presets` option of the `light`
  129. configuration.
  130. Presets are arranged in groups. You can define as little or as many groups
  131. as you like. The example configuration uses two groups, but that is only to
  132. mimic the original behavior. If you only need one group, then create one
  133. group. If you need ten, go ahead and knock yourself out.
  134. The general structure of the presets configuration is:
  135. ```yaml
  136. light:
  137. presets:
  138. group_1:
  139. preset_1: ...
  140. preset_2: ...
  141. ..
  142. group_2:
  143. preset_1: ...
  144. preset_2: ...
  145. ..
  146. ..
  147. ```
  148. *Note: duplicate template names are ok, as long as they are within their own
  149. group. If you use duplicate preset names within a single group, then the
  150. last preset will override the earlier one(s).*
  151. A preset can define one of the following:
  152. * **RGB light**
  153. * **red** (**Optional**, percentage): the red component of the RGB value (default = 0%).
  154. * **green** (**Optional**, percentage): the green component of the RGB value (default = 0%).
  155. * **blue** (**Optional**, percentage): the blue component of the RGB value (default = 0%).
  156. * **brightness** (*Optional*, percentage): the brightness to use (default = current brightness).
  157. * **transition_length** (*Optional*, time): the transition length to use.
  158. * **White light**
  159. * **color_temperature** (**Required**, mireds): the color temperature in mireds (range: "153 mireds" - "588 mireds")
  160. * **brightness** (*Optional*, percentage): the brightness to use (default = current brightness).
  161. * **transition_length** (*Optional*, time): the transition length to use.
  162. * **Light effect**
  163. * **effect** (**Required**, string): the name of a light effect to activate.
  164. * **Brightness change only**
  165. * **brightness** (**Required**, percentage): the brightness to use.
  166. **Activating presets from automations**
  167. Once presets have been configured, they can be activated using the
  168. `preset.activate` action. The following options are available for this
  169. 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
  201. group/preset is used while no presets have been defined at all, then the
  202. action will be ignored and an error will be logged.
  203. *Note: This is validation at run time. It would be a lot better to
  204. validate the names at compile time more strictly, so the firmware will not
  205. even compile when invalid names are in use.
  206. [Issue #15](https://github.com/mmakaay/esphome-xiaomi_bslamp2/issues/15)
  207. was created for implementing this. However, a new feature in ESPHome is
  208. required to be able to do this implementation. Good news is that this
  209. is already well on its way.*
  210. ## Component: binary_sensor
  211. Binary sensors can be added to the configuration for handling touch/release
  212. events for the front panel. On touch, a binary_sensor will publish `True`,
  213. on release it will publish `False`. The configuration of a binary_sensor
  214. determines what part of the front panel is involved in the touch events.
  215. ```yaml
  216. binary_sensor:
  217. - platform: xiaomi_bslamp2
  218. id: my_bedside_lamp_power_button
  219. for: POWER_BUTTON
  220. on_press:
  221. then:
  222. - light.toggle: my_bedside_lamp
  223. ```
  224. For referencing the parts of the front panel, the following part identifiers
  225. are available:
  226. * POWER_BUTTON (or its alias: POWER)
  227. * COLOR_BUTTON (or its alias: COLOR)
  228. * SLIDER
  229. If personal taste dictates so, you can use lower case characters and spaces
  230. instead of underscores. This means that for example "Power Button" and
  231. "power" would be valid identifiers for the power button.
  232. ### Configuration variables:
  233. * **name** (*Optional*, string): The name of the binary sensor. Setting a
  234. name will expose the binary sensor as an entity in Home Assistant. If you
  235. do not need this, you can omit the name.
  236. * **id** (*Optional*, ID): Manually specify the ID used for code generation.
  237. By providing an id, you can reference the binary_sensor from automation
  238. rules (to retrieve the current state of the binary_sensor).
  239. * **for** (*Mandatory*, part identifier): This specifies to for part of the
  240. front panel the binary sensor must report touch events.
  241. * All other options from
  242. [Binary Sensor](https://esphome.io/components/binary_sensor/index.html#config-binary-sensor).
  243. ## Component: sensor
  244. The sensor component publishes touch events for the front panel slider. The
  245. published value represents the level at which the slider was touched.
  246. *Note: This sensor only reports the touched slider level. It cannot be used
  247. for detecting release events. If you want to handle touch/release events for
  248. the slider, then you can make use of the
  249. [binary_sensor](#component-binary_sensor) instead.*
  250. ```yaml
  251. sensor:
  252. - platform: xiaomi_bslamp2
  253. - id: my_bedside_lamp_slider_level
  254. range_from: 0.2
  255. range_to: 0.9
  256. on_value:
  257. then:
  258. - light.turn_on:
  259. id: my_bedside_lamp
  260. brightness: !lambda return x;
  261. ```
  262. ### Configuration variables:
  263. * **name** (*Optional*, string): The name of the sensor. Setting a name will
  264. expose the sensor as an entity in Home Assistant. If you do not need this,
  265. you can omit the name.
  266. * **id** (*Optional*, ID): Manually specify the ID used for code generation.
  267. By providing an id, you can reference the sensor from automation rules
  268. (e.g. to retrieve the current state of the binary_sensor).
  269. * **range_from** (*Optional*, float): By default, published values vary from
  270. the range 0.01 to 1.00, in 20 steps. This option modifies the lower bound
  271. of the range.
  272. * **range_to** (*Optional*, float): This option modifies the upper bound of
  273. the range.
  274. * All other options from
  275. [Sensor](https://esphome.io/components/sensor/index.html#config-sensor).
  276. ## Component: output
  277. The (float) output component is linked to the front panel illumination +
  278. level indicator. Setting this output to value 0.0 will turn off the
  279. frontpanel illumination. Other values, up to 1.0, will turn on the
  280. illumination and will set the level indicator to the requested level (in 10
  281. steps).
  282. ```yaml
  283. output:
  284. - platform: xiaomi_bslamp2
  285. id: my_bedside_lamp_front_panel_illumination
  286. ```
  287. ### Configuration variables:
  288. * **id** (**Required**, ID): The id to use for this output component.
  289. * All other options from [Output](https://esphome.io/components/output/index.html)
  290. ## Component: text_sensor
  291. The text sensor component publishes changes in the active
  292. [light mode](#light-modes). Possible output values for this sensor are: "off",
  293. "rgb", "white" and "night".
  294. ### Configuration variables:
  295. * **name** (*Optional*, string): The name of the text sensor. Setting a name
  296. will expose the text sensor as an entity in Home Assistant. If you do not
  297. need this, you can omit the name.
  298. * **id** (*Optional*, ID): Manually specify the ID used for code generation.
  299. By providing an id, you can reference the text sensor from automation
  300. rules (to retrieve the current state of the text_sensor).
  301. * All other options from
  302. [Text Sensor](https://esphome.io/components/text_sensor/index.html)
  303. < [Installation guide](installation.md) | [Index](../README.md) | [Flashing guide](flashing.md) >