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.

405 lines
15 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.disco_on Action
  116. This action sets the state of the light immediately
  117. (i.e. without waiting for the next main loop iteration),
  118. without saving the state to memory and without publishing
  119. the state change.
  120. ```yaml
  121. on_...:
  122. then:
  123. - light.disco_on:
  124. id: my_bedside_lamp
  125. brightness: 80%
  126. red: 70%
  127. green: 0%
  128. blue: 100%
  129. ```
  130. The possible configuration options for this Action are the same
  131. as those for the standard `light.turn_on` Action.
  132. ### light.disco_off Action
  133. This action turns off the disco mode by restoring the state
  134. of the lamp to the last known state that was saved to memory.
  135. ```yaml
  136. on_...:
  137. then:
  138. - light.disco_off:
  139. id: my_bedside_lamp
  140. ```
  141. ### Light presets
  142. The presets functionality was written with the original lamp firemware
  143. functionality in mind: the user has two groups of presets available: one for
  144. RGB light presets and one for white light presets (based on color
  145. temperature). The color button (the top one on the front panel) can be
  146. tapped to switch to the next preset within the active preset group. The same
  147. button can be held for a little while, to switch to the other preset group.
  148. In your light configuration, you can mimic this behavior (in fact: it is
  149. done so in the [example.yaml](example.yaml)) by means of the presets system.
  150. This system consists of two parts:
  151. * Defining presets
  152. * Activating presets from automations
  153. **Defining presets**
  154. Presets can be configured in the `presets` option of the `light`
  155. configuration.
  156. Presets are arranged in groups. You can define as little or as many groups
  157. as you like. The example configuration uses two groups, but that is only to
  158. mimic the original behavior. If you only need one group, then create one
  159. group. If you need ten, go ahead and knock yourself out.
  160. The general structure of the presets configuration is:
  161. ```yaml
  162. light:
  163. presets:
  164. group_1:
  165. preset_1: ...
  166. preset_2: ...
  167. ..
  168. group_2:
  169. preset_1: ...
  170. preset_2: ...
  171. ..
  172. ..
  173. ```
  174. *Note: duplicate template names are ok, as long as they are within their own
  175. group. If you use duplicate preset names within a single group, then the
  176. last preset will override the earlier one(s).*
  177. A preset can define one of the following:
  178. * **RGB light**
  179. * **red** (**Optional**, percentage): the red component of the RGB value (default = 0%).
  180. * **green** (**Optional**, percentage): the green component of the RGB value (default = 0%).
  181. * **blue** (**Optional**, percentage): the blue component of the RGB value (default = 0%).
  182. * **brightness** (*Optional*, percentage): the brightness to use (default = current brightness).
  183. * **transition_length** (*Optional*, time): the transition length to use.
  184. * **White light**
  185. * **color_temperature** (**Required**, mireds): the color temperature in mireds (range: "153 mireds" - "588 mireds")
  186. * **brightness** (*Optional*, percentage): the brightness to use (default = current brightness).
  187. * **transition_length** (*Optional*, time): the transition length to use.
  188. * **Light effect**
  189. * **effect** (**Required**, string): the name of a light effect to activate.
  190. * **Brightness change only**
  191. * **brightness** (**Required**, percentage): the brightness to use.
  192. **Activating presets from automations**
  193. Once presets have been configured, they can be activated using the
  194. `preset.activate` action. The following options are available for this
  195. action:
  196. * Switch to next preset group (and after the last, switch to the first):
  197. ```yaml
  198. preset.activate:
  199. next: group
  200. ```
  201. * Switch to next preset within currentl preset group (and after the last,
  202. switch to the first):
  203. ```yaml
  204. preset.activate:
  205. next: preset
  206. ---
  207. * Activate a specific preset group by specifying the group's name:
  208. ```yaml
  209. preset.activate:
  210. group: rgb
  211. ```
  212. * Activate a specific preset by specifying both the preset's name and group name:
  213. ```yaml
  214. preset.activate:
  215. group: white
  216. preset: warm
  217. ```
  218. Shorthand definitions are available for all these actions:
  219. ```yaml
  220. preset.activate: next_group
  221. preset.activate: next_preset
  222. preset.activate: rgb
  223. preset.activate: white.warm
  224. ```
  225. **Handling of invalid input**
  226. When a group or template is specified that does not exist, or if next
  227. group/preset is used while no presets have been defined at all, then the
  228. action will be ignored and an error will be logged.
  229. *Note: This is validation at run time. It would be a lot better to
  230. validate the names at compile time more strictly, so the firmware will not
  231. even compile when invalid names are in use.
  232. [Issue #15](https://github.com/mmakaay/esphome-xiaomi_bslamp2/issues/15)
  233. was created for implementing this. However, a new feature in ESPHome is
  234. required to be able to do this implementation. Good news is that this
  235. is already well on its way.*
  236. ## Component: binary_sensor
  237. Binary sensors can be added to the configuration for handling touch/release
  238. events for the front panel. On touch, a binary_sensor will publish `True`,
  239. on release it will publish `False`. The configuration of a binary_sensor
  240. determines what part of the front panel is involved in the touch events.
  241. ```yaml
  242. binary_sensor:
  243. - platform: xiaomi_bslamp2
  244. id: my_bedside_lamp_power_button
  245. for: POWER_BUTTON
  246. on_press:
  247. then:
  248. - light.toggle: my_bedside_lamp
  249. ```
  250. For referencing the parts of the front panel, the following part identifiers
  251. are available:
  252. * POWER_BUTTON (or its alias: POWER)
  253. * COLOR_BUTTON (or its alias: COLOR)
  254. * SLIDER
  255. If personal taste dictates so, you can use lower case characters and spaces
  256. instead of underscores. This means that for example "Power Button" and
  257. "power" would be valid identifiers for the power button.
  258. ### Configuration variables:
  259. * **name** (*Optional*, string): The name of the binary sensor. Setting a
  260. name will expose the binary sensor as an entity in Home Assistant. If you
  261. do not need this, you can omit the name.
  262. * **id** (*Optional*, ID): Manually specify the ID used for code generation.
  263. By providing an id, you can reference the binary_sensor from automation
  264. rules (to retrieve the current state of the binary_sensor).
  265. * **for** (*Mandatory*, part identifier): This specifies to for part of the
  266. front panel the binary sensor must report touch events.
  267. * All other options from
  268. [Binary Sensor](https://esphome.io/components/binary_sensor/index.html#config-binary-sensor).
  269. ## Component: sensor
  270. The sensor component publishes touch events for the front panel slider. The
  271. published value represents the level at which the slider was touched.
  272. *Note: This sensor only reports the touched slider level. It cannot be used
  273. for detecting release events. If you want to handle touch/release events for
  274. the slider, then you can make use of the
  275. [binary_sensor](#component-binary_sensor) instead.*
  276. ```yaml
  277. sensor:
  278. - platform: xiaomi_bslamp2
  279. - id: my_bedside_lamp_slider_level
  280. range_from: 0.2
  281. range_to: 0.9
  282. on_value:
  283. then:
  284. - light.turn_on:
  285. id: my_bedside_lamp
  286. brightness: !lambda return x;
  287. ```
  288. ### Configuration variables:
  289. * **name** (*Optional*, string): The name of the sensor. Setting a name will
  290. expose the sensor as an entity in Home Assistant. If you do not need this,
  291. you can omit the name.
  292. * **id** (*Optional*, ID): Manually specify the ID used for code generation.
  293. By providing an id, you can reference the sensor from automation rules
  294. (e.g. to retrieve the current state of the binary_sensor).
  295. * **range_from** (*Optional*, float): By default, published values vary from
  296. the range 0.01 to 1.00, in 20 steps. This option modifies the lower bound
  297. of the range.
  298. * **range_to** (*Optional*, float): This option modifies the upper bound of
  299. the range.
  300. * All other options from
  301. [Sensor](https://esphome.io/components/sensor/index.html#config-sensor).
  302. ## Component: output
  303. The (float) output component is linked to the front panel illumination +
  304. level indicator. Setting this output to value 0.0 will turn off the
  305. frontpanel illumination. Other values, up to 1.0, will turn on the
  306. illumination and will set the level indicator to the requested level (in 10
  307. steps).
  308. ```yaml
  309. output:
  310. - platform: xiaomi_bslamp2
  311. id: my_bedside_lamp_front_panel_illumination
  312. ```
  313. ### Configuration variables:
  314. * **id** (**Required**, ID): The id to use for this output component.
  315. * All other options from [Output](https://esphome.io/components/output/index.html)
  316. ## Component: text_sensor
  317. The text sensor component publishes changes in the active
  318. [light mode](#light-modes). Possible output values for this sensor are: "off",
  319. "rgb", "white" and "night".
  320. ### Configuration variables:
  321. * **name** (*Optional*, string): The name of the text sensor. Setting a name
  322. will expose the text sensor as an entity in Home Assistant. If you do not
  323. need this, you can omit the name.
  324. * **id** (*Optional*, ID): Manually specify the ID used for code generation.
  325. By providing an id, you can reference the text sensor from automation
  326. rules (to retrieve the current state of the text_sensor).
  327. * All other options from
  328. [Text Sensor](https://esphome.io/components/text_sensor/index.html)
  329. < [Installation guide](installation.md) | [Index](../README.md) | [Flashing guide](flashing.md) >