Skip to content

Commit

Permalink
Merge pull request #133 from custom-components/battery_LYWSD02
Browse files Browse the repository at this point in the history
Adds battery level support for LYWSD02 sensors
  • Loading branch information
Ernst79 authored Oct 27, 2020
2 parents 1516c63 + e981903 commit 0c31c92
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ This custom component is an alternative for the standard build in [mitemp_bt](ht

- LYWSD02

(rectangular body, E-Ink, broadcasts temperature and humidity, about 20 readings per minute, no battery info)
(rectangular body, E-Ink, broadcasts temperature, humidity and battery level (battery level is available for firmware version 1.1.2_00085 and later), about 20 readings per minute)

![LYWSD02](/pictures/LYWSD02.jpeg)

Expand Down
2 changes: 1 addition & 1 deletion custom_components/mitemp_bt/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
'GCLS002' : [0, 9, 1, 2, 3, 9, 9, 9, 9],
'HHCCPOT002': [9, 9, 0, 1, 9, 9, 9, 9, 9],
'LYWSDCGQ' : [0, 1, 9, 9, 9, 9, 9, 9, 2],
'LYWSD02' : [0, 1, 9, 9, 9, 9, 9, 9, 9],
'LYWSD02' : [0, 1, 9, 9, 9, 9, 9, 9, 2],
'CGG1' : [0, 1, 9, 9, 9, 9, 9, 9, 2],
'LYWSD03MMC': [0, 1, 9, 9, 9, 9, 9, 9, 2],
'CGD1' : [0, 1, 9, 9, 9, 9, 9, 9, 2],
Expand Down
15 changes: 10 additions & 5 deletions faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- [Conflicts with other components using the same BT interface](#conflicts-with-other-components-using-the-same-bt-interface)
- [My sensor stops receiving updates some time after the system restart](#my-sensor-stops-receiving-updates-some-time-after-the-system-restart)
- [My sensor from the Xiaomi ecosystem is not in the list of supported ones. How to request implementation?](#my-sensor-from-the-xiaomi-ecosystem-is-not-in-the-list-of-supported-ones-how-to-request-implementation)
- [My sensor isn't showing the battery level](#my-sensor-isnt-showing-the-battery-level)
- [TIPS AND TRICKS](#tips-and-tricks)
- [How to know exactly if the reception of data from my sensors has stopped?](#how-to-know-exactly-if-the-reception-of-data-from-my-sensors-has-stopped)
- [DEBUG](#debug)
Expand Down Expand Up @@ -86,21 +87,21 @@ Devices:

### How can I create a battery sensor?

You can create a battery sensor by using a template sensor. Add the following to your `configuration.yaml`. Make sure you adjust the name of the sensor with your own sensor.
You can set option `batt_entities` to `True` - the battery sensor entity will be created automatically for each device reporting battery status.

Or you can create a battery sensor by using a template sensor. Add the following to your `configuration.yaml`. Make sure you adjust the name of the sensor with your own sensor.

```yaml
sensor:
- platform: template
sensors:
mi_b_582d34339449:
mi_battery_582d34339449:
friendly_name: "Battery"
unit_of_measurement: "%"
value_template: "{{ state_attr('sensor.mi_t_582d34339449', 'battery_level') }}"
value_template: "{{ state_attr('sensor.mi_temperature_582d34339449', 'battery_level') }}"
device_class: "battery"
```
Or (since v0.5.4) you can set option `batt_entities` to `True` - the battery sensor entity will be created automatically for each device reporting battery status.

## RECEPTION ISSUES
### My sensor doesn't receive any readings from my sensors anymore or only occasionally
Expand Down Expand Up @@ -189,6 +190,10 @@ logger:
- Do not forget to disable the `report_unknown` option (delete it or set it to `False` and restart HA)! Since the potentially large output of this option will spam the log and can mask really important messages.
- Wait for a response from the developers.

### My sensor isn't showing the battery level

Battery level is not broadcasted by all sensors. Check the list of [supported sensors](https://github.com/custom-components/sensor.mitemp_bt/blob/master/README.md#supported-sensors) to see if your sensor supports battery level. LYWSD02 sensors need to be updated to firmware 1.1.2_00085 or above to the show battery level.

## TIPS AND TRICKS

### How to know exactly if the reception of data from my sensors has stopped?
Expand Down
16 changes: 3 additions & 13 deletions info.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,9 @@ Changes were based on a small part of the changes as proposed in beta 0.7.1 by @
{% endif %}
{% if installed or pending_update %}

# Changes in 0.7.5
# Changes in 0.7.6

Fix typo in formaldehyde sensor (by @MarpleA)

# Changes in 0.7.4

This time, only some code optimization, reducing the number of lines of python code with about 20%.

- Adding a MeasuringSensor class which is used for all measuring sensors, to shorten the python code (won't affect users)
- Adding device_class Illuminance to illuminance sensors (will change the icon to default Home Asssistant icon)
- Using default unit of measurements from Home Assistant constants (won't affect users)

Changes were based on a small part of the changes as proposed in beta 0.7.1 by @Magalex2x14, further developed by me (@Ernst79).
Added battery level support for LYWSD02 sensor. Note that battery level is only supported for LYWSD02 sensors with firmware 1.1.2_00085 or later.

{% endif %}

Expand Down Expand Up @@ -69,7 +59,7 @@ This custom component is an alternative for the standard build in [mitemp_bt](ht

- LYWSD02

(rectangular body, E-Ink, broadcasts temperature and humidity, about 20 readings per minute, no battery info)
(rectangular body, E-Ink, broadcasts temperature, humidity and battery level, about 20 readings per minute. Battery level is available for firmware version 1.1.2_00085 and later.)

<img src="https://github.com/custom-components/sensor.mitemp_bt/blob/master/pictures/LYWSD02.jpeg">

Expand Down

0 comments on commit 0c31c92

Please sign in to comment.