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.

435 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,
  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 or parts of the front panel are involved in the touch
  215. events.
  216. For referencing the parts of the front panel, the following identifiers are
  217. available:
  218. * POWER_BUTTON (or POWER)
  219. * COLOR_BUTTON (or its alias: COLOR)
  220. * SLIDER
  221. If personal taste dictates so, you can use lower case characters and spaces
  222. instead of underscores. This means that for example "Power Button" would also
  223. be a valid identifier.
  224. ```yaml
  225. binary_sensor:
  226. - platform: xiaomi_bslamp2
  227. id: my_bedside_lamp_power_button
  228. for: POWER_BUTTON
  229. on_release:
  230. then:
  231. - light.toggle: my_bedside_lamp
  232. - platform: xiaomi_bslamp2
  233. id: my_bedside_lamp_power_plus_color_button
  234. for:
  235. - POWER_BUTTON
  236. - COLOR_BUTTON
  237. on_press:
  238. then:
  239. - light.turn_on:
  240. id: my_bedside_lamp
  241. effect: BlinkyBlink
  242. ```
  243. ### Configuration variables:
  244. * **name** (*Optional*, string): The name of the binary sensor. Setting a
  245. name will expose the binary sensor as an entity in Home Assistant. If you
  246. do not need this, you can omit the name.
  247. * **id** (*Optional*, ID): Manually specify the ID used for code generation.
  248. By providing an id, you can reference the binary_sensor from automation
  249. rules (to retrieve the current state of the binary_sensor).
  250. * **for** (*Mandatory*, single identifier or a list): This specifies what part
  251. or parts of the front panel the binary sensor must look at. When multiple
  252. parts are specified here, the binary_sensor will handle multi-touch events
  253. using those parts.
  254. * All other options from
  255. [Binary Sensor](https://esphome.io/components/binary_sensor/index.html#config-binary-sensor).
  256. ### Multi-touch support
  257. When using a multi-touch binary-sensor, beware to use non-conflicting
  258. triggers for any related binary sensors. For example, when you implement a
  259. multi-touch binary sensor for the power + color button, then you probably
  260. should not also be using `on_press` triggers for the two individual buttons.
  261. First a few definitions:
  262. * **multi-touch binary sensor**: when two or more parts of the front panel
  263. can be touched concurrently to trigger an automation. A binary sensor can
  264. be defined as multi-touch by configuring two or more parts in the `for:`
  265. parameter.
  266. * **lower order binary sensors**: binary sensors that use a subset of the
  267. parts of a multi-touch binary sensor. For example a binary sensor for the
  268. power button is a lower order binary sensor for a multi-touch binary
  269. sensor for the power + color button.
  270. Why not use `on_press` for every binary sensor:
  271. The user of your lamp will very likely not touch the power and color buttons
  272. at the *exact same time*. Therefore, you would first get an `on_press`
  273. trigger for one of these buttons, followed by the `on_press` trigger for the
  274. multi-touch binary sensor. Thus, if you have defined `on_press` for every
  275. binary sensor, then two automations would be triggered. Most likely, this
  276. would be unwanted behavior.
  277. Interlocking to the rescue:
  278. Multi-touch binary sensors provide a form of interlocking behavior, to
  279. facilitate their use.
  280. * When multi-touch binary sensors trigger `on_press`, they will block all
  281. further triggers for their lower order binary sensors.
  282. * These blocks will be released after all involved parts have been released.
  283. Because of interlocking, in the above example you might first have gotten
  284. an `on_press` trigger for the power button, followed by an `on_press`
  285. trigger for the multi-touch power + color buttons. When after this the
  286. buttons are released, then only the multi-touch binary sensor will trigger
  287. `on_release`.
  288. TL;DR:
  289. * If a sensor is a lower order sensor for a multi-touch sensor, then it is
  290. best to only use an `on_release` trigger.
  291. * A multi-touch sensor can also act on other triggers.
  292. ## Component: sensor
  293. The sensor component publishes touch events for the front panel slider. The
  294. published value represents the level at which the slider was touched.
  295. *Note: This sensor only reports the touched slider level. It cannot be used
  296. for detecting release events. If you want to handle touch/release events for
  297. the slider, then you can make use of the
  298. [binary_sensor](#component-binary_sensor) instead.*
  299. ```yaml
  300. sensor:
  301. - platform: xiaomi_bslamp2
  302. - id: my_bedside_lamp_slider_level
  303. range_from: 0.2
  304. range_to: 0.9
  305. on_value:
  306. then:
  307. - light.turn_on:
  308. id: my_bedside_lamp
  309. brightness: !lambda return x;
  310. ```
  311. ### Configuration variables:
  312. * **name** (*Optional*, string): The name of the sensor. Setting a name will
  313. expose the sensor as an entity in Home Assistant. If you do not need this,
  314. you can omit the name.
  315. * **id** (*Optional*, ID): Manually specify the ID used for code generation.
  316. By providing an id, you can reference the sensor from automation rules
  317. (e.g. to retrieve the current state of the binary_sensor).
  318. * **range_from** (*Optional*, float): By default, published values vary from
  319. the range 0.01 to 1.00, in 20 steps. This option modifies the lower bound
  320. of the range.
  321. * **range_to** (*Optional*, float): This option modifies the upper bound of
  322. the range.
  323. * All other options from
  324. [Sensor](https://esphome.io/components/sensor/index.html#config-sensor).
  325. ## Component: output
  326. The (float) output component is linked to the front panel illumination +
  327. level indicator. Setting this output to value 0.0 will turn off the
  328. frontpanel illumination. Other values, up to 1.0, will turn on the
  329. illumination and will set the level indicator to the requested level (in 10
  330. steps).
  331. ```yaml
  332. output:
  333. - platform: xiaomi_bslamp2
  334. id: my_bedside_lamp_front_panel_illumination
  335. ```
  336. ### Configuration variables:
  337. * **id** (**Required**, ID): The id to use for this output component.
  338. * All other options from [Output](https://esphome.io/components/output/index.html)
  339. ## Component: text_sensor
  340. The text sensor component publishes changes in the active
  341. [light mode](#light-modes). Possible output values for this sensor are: "off",
  342. "rgb", "white" and "night".
  343. ### Configuration variables:
  344. * **name** (*Optional*, string): The name of the text sensor. Setting a name
  345. will expose the text sensor as an entity in Home Assistant. If you do not
  346. need this, you can omit the name.
  347. * **id** (*Optional*, ID): Manually specify the ID used for code generation.
  348. By providing an id, you can reference the text sensor from automation
  349. rules (to retrieve the current state of the text_sensor).
  350. * All other options from
  351. [Text Sensor](https://esphome.io/components/text_sensor/index.html)
  352. < [Installation guide](installation.md) | [Index](../README.md) | [Flashing guide](flashing.md) >