Skip to content

Commit 5471f69

Browse files
authored
Merge pull request #493 from custom-components/rssi_sensor
Add RSSI sensor
2 parents 107c50c + 0e673bc commit 5471f69

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+339
-113
lines changed

custom_components/ble_monitor/const.py

+82-70
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,21 @@
2323
DEVICE_CLASS_HUMIDITY,
2424
DEVICE_CLASS_ILLUMINANCE,
2525
DEVICE_CLASS_PRESSURE,
26+
DEVICE_CLASS_SIGNAL_STRENGTH,
2627
DEVICE_CLASS_TEMPERATURE,
2728
DEVICE_CLASS_VOLTAGE,
28-
PERCENTAGE,
2929
CONDUCTIVITY,
3030
CONCENTRATION_MILLIGRAMS_PER_CUBIC_METER,
3131
ELECTRIC_POTENTIAL_VOLT,
3232
ENERGY_KILO_WATT_HOUR,
33-
POWER_KILO_WATT,
34-
PRESSURE_HPA,
3533
LIGHT_LUX,
3634
MASS_KILOGRAMS,
37-
VOLUME_LITERS,
35+
PERCENTAGE,
36+
POWER_KILO_WATT,
37+
PRESSURE_HPA,
38+
SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
3839
TEMP_CELSIUS,
40+
VOLUME_LITERS,
3941
)
4042

4143
DOMAIN = "ble_monitor"
@@ -297,13 +299,14 @@ class BLEMonitorBinarySensorEntityDescription(
297299
state_class=STATE_CLASS_MEASUREMENT,
298300
),
299301
BLEMonitorSensorEntityDescription(
300-
key="voltage",
302+
key="rssi",
301303
sensor_class="MeasuringSensor",
302-
name="ble voltage",
303-
unique_id="v_",
304-
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
305-
device_class=DEVICE_CLASS_VOLTAGE,
304+
name="ble rssi",
305+
unique_id="rssi_",
306+
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
307+
device_class=DEVICE_CLASS_SIGNAL_STRENGTH,
306308
state_class=STATE_CLASS_MEASUREMENT,
309+
entity_registry_enabled_default=False,
307310
),
308311
BLEMonitorSensorEntityDescription(
309312
key="battery",
@@ -314,6 +317,15 @@ class BLEMonitorBinarySensorEntityDescription(
314317
device_class=DEVICE_CLASS_BATTERY,
315318
state_class=STATE_CLASS_MEASUREMENT,
316319
),
320+
BLEMonitorSensorEntityDescription(
321+
key="voltage",
322+
sensor_class="MeasuringSensor",
323+
name="ble voltage",
324+
unique_id="v_",
325+
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
326+
device_class=DEVICE_CLASS_VOLTAGE,
327+
state_class=STATE_CLASS_MEASUREMENT,
328+
),
317329
BLEMonitorSensorEntityDescription(
318330
key="consumable",
319331
sensor_class="InstantUpdateSensor",
@@ -531,67 +543,67 @@ class BLEMonitorBinarySensorEntityDescription(
531543
# - [instantly updating sensor list]: sensors that update the state instantly after new data
532544
# - [binary sensor list]: binary sensors
533545
MEASUREMENT_DICT = {
534-
'LYWSDCGQ' : [["temperature", "humidity", "battery"], [], []],
535-
'LYWSD02' : [["temperature", "humidity", "battery"], [], []],
536-
'LYWSD03MMC' : [["temperature", "humidity", "battery", "voltage"], [], []],
537-
'HHCCJCY01' : [["temperature", "moisture", "conductivity", "illuminance"], [], []],
538-
'GCLS002' : [["temperature", "moisture", "conductivity", "illuminance"], [], []],
539-
'HHCCPOT002' : [["moisture", "conductivity"], [], []],
540-
'WX08ZM' : [["consumable", "battery"], [], ["switch"]],
541-
'MCCGQ02HL' : [["battery"], [], ["opening", "light"]],
542-
'YM-K1501' : [[], ["temperature"], ["switch"]],
543-
'YM-K1501EU' : [[], ["temperature"], ["switch"]],
544-
'V-SK152' : [[], ["temperature"], ["switch"]],
545-
'SJWS01LM' : [["battery"], [], ["moisture"]],
546-
'MJYD02YL' : [["battery"], [], ["light", "motion"]],
547-
'MUE4094RT' : [[], [], ["motion"]],
548-
'RTCGQ02LM' : [["battery"], ["button"], ["light", "motion"]],
549-
'MMC-T201-1' : [["temperature", "battery"], [], []],
550-
'M1S-T500' : [["battery"], [], ["toothbrush"]],
551-
'ZNMS16LM' : [["battery"], [], ["lock", "fingerprint"]],
552-
'ZNMS17LM' : [["battery"], [], ["lock", "fingerprint"]],
553-
'CGC1' : [["temperature", "humidity", "battery"], [], []],
554-
'CGD1' : [["temperature", "humidity", "battery"], [], []],
555-
'CGDK2' : [["temperature", "humidity", "battery"], [], []],
556-
'CGG1' : [["temperature", "humidity", "battery"], [], []],
557-
'CGG1-ENCRYPTED' : [["temperature", "humidity", "battery"], [], []],
558-
'CGH1' : [["battery"], [], ["opening"]],
559-
'CGP1W' : [["temperature", "humidity", "battery", "pressure"], [], []],
560-
'CGPR1' : [["illuminance", "battery"], [], ["motion"]],
561-
'MHO-C401' : [["temperature", "humidity", "battery"], [], []],
562-
'MHO-C303' : [["temperature", "humidity", "battery"], [], []],
563-
'JQJCY01YM' : [["temperature", "humidity", "battery", "formaldehyde"], [], []],
564-
'JTYJGD03MI' : [[], ["button", "battery"], ["smoke detector"]],
565-
'K9B-1BTN' : [[], ["one btn switch"], []],
566-
'K9B-2BTN' : [[], ["two btn switch left", "two btn switch right"], []],
567-
'K9B-3BTN' : [[], ["three btn switch left", "three btn switch middle", "three btn switch right"], []],
568-
'YLAI003' : [[], ["button", "battery"], []],
569-
'YLYK01YL' : [[], ["remote"], ["remote single press", "remote long press"]],
570-
'YLYK01YL-FANCL' : [[], ["fan remote"], []],
571-
'YLYK01YL-VENFAN' : [[], ["ventilator fan remote"], []],
572-
'YLYB01YL-BHFRC' : [[], ["bathroom heater remote"], []],
573-
'YLKG07YL/YLKG08YL' : [[], ["dimmer"], []],
574-
'ATC' : [["temperature", "humidity", "battery", "voltage"], [], []],
575-
'Mi Scale V1' : [[], ["weight", "non-stabilized weight"], ["weight removed"]],
576-
'Mi Scale V2' : [[], ["weight", "non-stabilized weight", "impedance"], ["weight removed"]],
577-
'Kegtron KT-100' : [[], ["volume dispensed port 1"], []],
578-
'Kegtron KT-200' : [[], ["volume dispensed port 1", "volume dispensed port 2"], []],
579-
'Smart hygrometer' : [["temperature", "humidity", "battery", "voltage"], [], []],
580-
'Lanyard/mini hygrometer' : [["temperature", "humidity", "battery", "voltage"], [], []],
581-
'T201' : [["temperature", "humidity", "battery", "voltage"], [], []],
582-
'H5072/H5075' : [["temperature", "humidity", "battery"], [], []],
583-
'H5101/H5102/H5177' : [["temperature", "humidity", "battery"], [], []],
584-
'H5051' : [["temperature", "humidity", "battery"], [], []],
585-
'H5074' : [["temperature", "humidity", "battery"], [], []],
586-
'H5178' : [["temperature", "temperature outdoor", "humidity", "humidity outdoor", "battery"], [], []],
587-
'H5179' : [["temperature", "humidity", "battery"], [], []],
588-
'Ruuvitag' : [["temperature", "humidity", "pressure", "battery", "voltage"], ["acceleration"], ["motion"]],
589-
'iNode Energy Meter' : [["battery", "voltage"], ["energy", "power"], []],
590-
'Blue Puck T' : [["temperature"], [], []],
591-
'Blue Coin T' : [["temperature"], [], []],
592-
'Blue Puck RHT' : [["temperature", "humidity"], [], []],
593-
'HTP.xw' : [["temperature", "humidity", "pressure"], [], []],
594-
'HT.w' : [["temperature", "humidity", "pressure"], [], []]
546+
'LYWSDCGQ' : [["temperature", "humidity", "battery", "rssi"], [], []],
547+
'LYWSD02' : [["temperature", "humidity", "battery", "rssi"], [], []],
548+
'LYWSD03MMC' : [["temperature", "humidity", "battery", "voltage", "rssi"], [], []],
549+
'HHCCJCY01' : [["temperature", "moisture", "conductivity", "illuminance", "rssi"], [], []],
550+
'GCLS002' : [["temperature", "moisture", "conductivity", "illuminance", "rssi"], [], []],
551+
'HHCCPOT002' : [["moisture", "conductivity", "rssi"], [], []],
552+
'WX08ZM' : [["consumable", "battery", "rssi"], [], ["switch"]],
553+
'MCCGQ02HL' : [["battery", "rssi"], [], ["opening", "light"]],
554+
'YM-K1501' : [["rssi"], ["temperature"], ["switch"]],
555+
'YM-K1501EU' : [["rssi"], ["temperature"], ["switch"]],
556+
'V-SK152' : [["rssi"], ["temperature"], ["switch"]],
557+
'SJWS01LM' : [["battery", "rssi"], [], ["moisture"]],
558+
'MJYD02YL' : [["battery", "rssi"], [], ["light", "motion"]],
559+
'MUE4094RT' : [["rssi"], [], ["motion"]],
560+
'RTCGQ02LM' : [["battery", "rssi"], ["button"], ["light", "motion"]],
561+
'MMC-T201-1' : [["temperature", "battery", "rssi"], [], []],
562+
'M1S-T500' : [["battery", "rssi"], [], ["toothbrush"]],
563+
'ZNMS16LM' : [["battery", "rssi"], [], ["lock", "fingerprint"]],
564+
'ZNMS17LM' : [["battery", "rssi"], [], ["lock", "fingerprint"]],
565+
'CGC1' : [["temperature", "humidity", "battery", "rssi"], [], []],
566+
'CGD1' : [["temperature", "humidity", "battery", "rssi"], [], []],
567+
'CGDK2' : [["temperature", "humidity", "battery", "rssi"], [], []],
568+
'CGG1' : [["temperature", "humidity", "battery", "rssi"], [], []],
569+
'CGG1-ENCRYPTED' : [["temperature", "humidity", "battery", "rssi"], [], []],
570+
'CGH1' : [["battery", "rssi"], [], ["opening"]],
571+
'CGP1W' : [["temperature", "humidity", "battery", "pressure", "rssi"], [], []],
572+
'CGPR1' : [["illuminance", "battery", "rssi"], [], ["motion"]],
573+
'MHO-C401' : [["temperature", "humidity", "battery", "rssi"], [], []],
574+
'MHO-C303' : [["temperature", "humidity", "battery", "rssi"], [], []],
575+
'JQJCY01YM' : [["temperature", "humidity", "battery", "formaldehyde", "rssi"], [], []],
576+
'JTYJGD03MI' : [["rssi"], ["button", "battery"], ["smoke detector"]],
577+
'K9B-1BTN' : [["rssi"], ["one btn switch"], []],
578+
'K9B-2BTN' : [["rssi"], ["two btn switch left", "two btn switch right"], []],
579+
'K9B-3BTN' : [["rssi"], ["three btn switch left", "three btn switch middle", "three btn switch right"], []],
580+
'YLAI003' : [["rssi"], ["button", "battery"], []],
581+
'YLYK01YL' : [["rssi"], ["remote"], ["remote single press", "remote long press"]],
582+
'YLYK01YL-FANCL' : [["rssi"], ["fan remote"], []],
583+
'YLYK01YL-VENFAN' : [["rssi"], ["ventilator fan remote"], []],
584+
'YLYB01YL-BHFRC' : [["rssi"], ["bathroom heater remote"], []],
585+
'YLKG07YL/YLKG08YL' : [["rssi"], ["dimmer"], []],
586+
'ATC' : [["temperature", "humidity", "battery", "voltage", "rssi"], [], []],
587+
'Mi Scale V1' : [["rssi"], ["weight", "non-stabilized weight"], ["weight removed"]],
588+
'Mi Scale V2' : [["rssi"], ["weight", "non-stabilized weight", "impedance"], ["weight removed"]],
589+
'Kegtron KT-100' : [["rssi"], ["volume dispensed port 1"], []],
590+
'Kegtron KT-200' : [["rssi"], ["volume dispensed port 1", "volume dispensed port 2"], []],
591+
'Smart hygrometer' : [["temperature", "humidity", "battery", "voltage", "rssi"], [], []],
592+
'Lanyard/mini hygrometer' : [["temperature", "humidity", "battery", "voltage", "rssi"], [], []],
593+
'T201' : [["temperature", "humidity", "battery", "voltage", "rssi"], [], []],
594+
'H5072/H5075' : [["temperature", "humidity", "battery", "rssi"], [], []],
595+
'H5101/H5102/H5177' : [["temperature", "humidity", "battery", "rssi"], [], []],
596+
'H5051' : [["temperature", "humidity", "battery", "rssi"], [], []],
597+
'H5074' : [["temperature", "humidity", "battery", "rssi"], [], []],
598+
'H5178' : [["temperature", "temperature outdoor", "humidity", "humidity outdoor", "battery", "rssi"], [], []],
599+
'H5179' : [["temperature", "humidity", "battery", "rssi"], [], []],
600+
'Ruuvitag' : [["temperature", "humidity", "pressure", "battery", "voltage", "rssi"], ["acceleration"], ["motion"]],
601+
'iNode Energy Meter' : [["battery", "voltage", "rssi"], ["energy", "power"], []],
602+
'Blue Puck T' : [["temperature", "rssi"], [], []],
603+
'Blue Coin T' : [["temperature", "rssi"], [], []],
604+
'Blue Puck RHT' : [["temperature", "humidity", "rssi"], [], []],
605+
'HTP.xw' : [["temperature", "humidity", "pressure", "rssi"], [], []],
606+
'HT.w' : [["temperature", "humidity", "pressure", "rssi"], [], []]
595607
}
596608

597609
KETTLES = ('YM-K1501', 'YM-K1501EU', 'V-SK152')

custom_components/ble_monitor/manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
],
1212
"dependencies": [],
1313
"codeowners": ["@Ernst79", "@Magalex2x14", "@Thrilleratplay"],
14-
"version": "5.1.3",
14+
"version": "5.2.0",
1515
"iot_class": "local_polling"
1616
}

custom_components/ble_monitor/sensor.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ async def async_add_sensor(mac, sensortype, firmware):
108108
sensors_by_mac = {}
109109
sensors = []
110110
batt = {} # batteries
111-
rssi = {}
111+
rssi = {} # rssi
112112
ble_adv_cnt = 0
113113
ts_last = dt_util.now()
114114
ts_now = ts_last
@@ -241,9 +241,10 @@ class BaseSensor(RestoreEntity, SensorEntity):
241241
# | |**conductivity
242242
# | |**illuminance
243243
# | |**formaldehyde
244-
# | |**voltage
244+
# | |**rssi
245245
# | |--BatterySensor (Class)
246246
# | | |**battery
247+
# | |**voltage
247248
# |--InstantUpdateSensor (Class)
248249
# | |**consumable
249250
# | |--AccelerationSensor (Class)
@@ -508,7 +509,8 @@ async def async_update(self):
508509
self._measurements.clear()
509510
self._extra_state_attributes["median"] = state_median
510511
self._extra_state_attributes["mean"] = state_mean
511-
self._extra_state_attributes["rssi"] = round(sts.mean(self.rssi_values))
512+
if self.entity_description.key != "rssi":
513+
self._extra_state_attributes["rssi"] = round(sts.mean(self.rssi_values))
512514
self.rssi_values.clear()
513515
except (AttributeError, AssertionError):
514516
_LOGGER.debug(

docs/_devices/CGC1.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ broadcasted_properties:
88
- temperature
99
- humidity
1010
- battery
11+
- rssi
1112
broadcasted_property_notes:
1213
- property: battery
13-
note: For battery level, we do not have accurate periodicity information yet
14+
note: For battery level, we do not have accurate periodicity information yet.
15+
- property: rssi
16+
note: >
17+
The RSSI sensor is disabled by default. You can enable the RSSI sensor by going to `configuration`, `integrations`, select `devices` on the BLE monitor integration tile and select your device. Click on the `+1 disabled entity` to show the disabled sensor and select the disabled entity. Finally, click on `Enable entity` to enable it.
1418
broadcast_rate:
1519
active_scan:
1620
encryption_key: Yes (Xiaomi MiBeacon advertisement)

docs/_devices/CGD1.md

+4
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ broadcasted_properties:
88
- temperature
99
- humidity
1010
- battery
11+
- rssi
1112
broadcasted_property_notes:
1213
- property: battery
1314
note: For battery level, we do not have accurate periodicity information yet.
15+
- property: rssi
16+
note: >
17+
The RSSI sensor is disabled by default. You can enable the RSSI sensor by going to `configuration`, `integrations`, select `devices` on the BLE monitor integration tile and select your device. Click on the `+1 disabled entity` to show the disabled sensor and select the disabled entity. Finally, click on `Enable entity` to enable it.
1418
broadcast_rate: ~1/10min.
1519
active_scan:
1620
encryption_key: Yes (Xiaomi MiBeacon advertisement)

docs/_devices/CGDK2.md

+4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ broadcasted_properties:
88
- temperature
99
- humidity
1010
- battery
11+
- rssi
1112
broadcasted_property_notes:
13+
- property: rssi
14+
note: >
15+
The RSSI sensor is disabled by default. You can enable the RSSI sensor by going to `configuration`, `integrations`, select `devices` on the BLE monitor integration tile and select your device. Click on the `+1 disabled entity` to show the disabled sensor and select the disabled entity. Finally, click on `Enable entity` to enable it.
1216
broadcast_rate: ~1/10min.
1317
active_scan:
1418
encryption_key: true

docs/_devices/CGG1-M.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ broadcasted_properties:
99
- humidity
1010
- battery
1111
- voltage
12+
- rssi
1213
broadcasted_property_notes:
1314
- property: voltage
14-
note: battery voltage is only available with custom firmware
15+
note: Battery voltage is only available with custom firmware.
16+
- property: rssi
17+
note: >
18+
The RSSI sensor is disabled by default. You can enable the RSSI sensor by going to `configuration`, `integrations`, select `devices` on the BLE monitor integration tile and select your device. Click on the `+1 disabled entity` to show the disabled sensor and select the disabled entity. Finally, click on `Enable entity` to enable it.
1519
broadcast_rate: ~20/min.
1620
active_scan:
1721
encryption_key: True

docs/_devices/CGG1.md

+4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ broadcasted_properties:
88
- temperature
99
- humidity
1010
- battery
11+
- rssi
1112
broadcasted_property_notes:
13+
- property: rssi
14+
note: >
15+
The RSSI sensor is disabled by default. You can enable the RSSI sensor by going to `configuration`, `integrations`, select `devices` on the BLE monitor integration tile and select your device. Click on the `+1 disabled entity` to show the disabled sensor and select the disabled entity. Finally, click on `Enable entity` to enable it.
1216
broadcast_rate: ~20/min.
1317
active_scan: false
1418
encryption_key: false

docs/_devices/CGH1.md

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ broadcasted_properties:
88
- opening
99
- battery
1010
- status
11+
- rssi
1112
broadcasted_property_notes:
1213
- property: battery
1314
note: For battery level, we do not have accurate periodicity information yet.
@@ -18,6 +19,9 @@ broadcasted_property_notes:
1819
* closed
1920
* closing timeout
2021
* device reset
22+
- property: rssi
23+
note: >
24+
The RSSI sensor is disabled by default. You can enable the RSSI sensor by going to `configuration`, `integrations`, select `devices` on the BLE monitor integration tile and select your device. Click on the `+1 disabled entity` to show the disabled sensor and select the disabled entity. Finally, click on `Enable entity` to enable it.
2125
broadcast_rate:
2226
active_scan:
2327
encryption_key: true

docs/_devices/CGP1W.md

+4
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ broadcasted_properties:
99
- humidity
1010
- pressure
1111
- battery
12+
- rssi
1213
broadcasted_property_notes:
1314
- property: battery
1415
note: For battery level, we do not have accurate periodicity information yet.
16+
- property: rssi
17+
note: >
18+
The RSSI sensor is disabled by default. You can enable the RSSI sensor by going to `configuration`, `integrations`, select `devices` on the BLE monitor integration tile and select your device. Click on the `+1 disabled entity` to show the disabled sensor and select the disabled entity. Finally, click on `Enable entity` to enable it.
1519
broadcast_rate:
1620
active_scan:
1721
encryption_key:

docs/_devices/CGPR1.md

+4
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@ broadcasted_properties:
88
- illuminance
99
- motion
1010
- battery
11+
- rssi
1112
broadcasted_property_notes:
1213
- property: illuminance
1314
note: is measured in lux.
1415
- property: motion
1516
note: Motion state is ‘motion detected’ or ‘clear’.
1617
- property: battery
1718
note: For battery level, we do not have accurate periodicity information yet.
19+
- property: rssi
20+
note: >
21+
The RSSI sensor is disabled by default. You can enable the RSSI sensor by going to `configuration`, `integrations`, select `devices` on the BLE monitor integration tile and select your device. Click on the `+1 disabled entity` to show the disabled sensor and select the disabled entity. Finally, click on `Enable entity` to enable it.
1822
broadcast_rate: See Notes
1923
active_scan:
2024
encryption_key: true

docs/_devices/GCLS002.md

+4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ broadcasted_properties:
1010
- illuminance
1111
- conductivity
1212
- battery
13+
- rssi
1314
broadcasted_property_notes:
15+
- property: rssi
16+
note: >
17+
The RSSI sensor is disabled by default. You can enable the RSSI sensor by going to `configuration`, `integrations`, select `devices` on the BLE monitor integration tile and select your device. Click on the `+1 disabled entity` to show the disabled sensor and select the disabled entity. Finally, click on `Enable entity` to enable it.
1418
broadcast_rate:
1519
active_scan:
1620
encryption_key:

0 commit comments

Comments
 (0)