Repository: Bluetooth-Devices/bthome-ble (language: python)

Issue:
Electrical Conductivity (σ)
I would like to see a unit for Electrical Conductivity (EC) because it's pretty important to know to let crops grow optimally (aside from temperature and moisture content).

The unit for EC is often expressed in milliSiemens/centimeter (mS/cm) or dS/m.
Example list for good soil EC for crops can be found here: https://www.seeedstudio.com/blog/2022/07/15/soil-electrical-conductivity/
(showing ranges between 0.3 mS/cm between 3.5 mS/cm)

As for the encoding in the packet, I think an unsigned 16 bit and a factor of 0.0001 S/m would be good for most cases, resulting in a unit of µS/cm.

Some example conversions:

So for a crop in a soil of 0.55 mS/cm could be encoded as:
(0.55 milliSiemens per centimeter)  /  (0.0001 Siemens per meter) = 550

Seawater/salt-aquarium at 4.8 S/m to 5.3 S/m as:
(4.8 Siemens per meter)  /  (0.0001 Siemens per meter) = 48000

Tap water at 200 to 800 µS/cm
(500 microSiemens per centimeter)  /  (0.0001 Siemens per meter) = 500

Demineralised water 0.1 to 1.0 μS/cm   (no real use-case I think)
(1.0 microSiemens per centimeter)  /  (0.0001 Siemens per meter) = 1

I guess the value of max uint16 will indicate out of range?
Temperature correction (if wanted) could be done in post processing (depends on soil type of course) but often not needed.


Discussion / hints:

Fix patch:
diff --git a/src/bthome_ble/const.py b/src/bthome_ble/const.py
index 05ea0f0..00cc503 100644
--- a/src/bthome_ble/const.py
+++ b/src/bthome_ble/const.py
@@ -409,4 +409,8 @@ class ExtendedSensorLibrary(SensorLibrary):
         data_length=4,
         factor=0.001,
     ),
+    0x56: MeasTypes(
+        meas_format=SensorLibrary.CONDUCTIVITY__CONDUCTIVITY,
+        data_length=2,
+    ),
 }


Test patch:
diff --git a/tests/test_parser_v2.py b/tests/test_parser_v2.py
index 7aac8b5..502b453 100644
--- a/tests/test_parser_v2.py
+++ b/tests/test_parser_v2.py
@@ -65,6 +65,7 @@
 KEY_VOLUME_FLOW_RATE = DeviceKey(key="volume_flow_rate", device_id=None)
 KEY_VOLUME_STORAGE = DeviceKey(key="volume_storage", device_id=None)
 KEY_WATER = DeviceKey(key="water", device_id=None)
+KEY_CONDUCTIVITY = DeviceKey(key="conductivity", device_id=None)
 
 
 @pytest.fixture(autouse=True)
@@ -1745,6 +1746,48 @@ def test_bthome_moisture(caplog):
     )
 
 
+def test_bthome_conductivity(caplog):
+    """Test BTHome parser for conductivity reading from SenseNL sensor."""
+    data_string = b"\x40\x56\xe8\x03"
+    advertisement = bytes_to_service_info(
+        data_string, local_name="TEST DEVICE", address="A4:C1:38:8D:18:B2"
+    )
+
+    device = BTHomeBluetoothDeviceData()
+    assert device.update(advertisement) == SensorUpdate(
+        title="TEST DEVICE 18B2",
+        devices={
+            None: SensorDeviceInfo(
+                name="TEST DEVICE 18B2",
+                manufacturer=None,
+                model="BTHome sensor",
+                sw_version="BTHome BLE v2",
+                hw_version=None,
+            )
+        },
+        entity_descriptions={
+            KEY_CONDUCTIVITY: SensorDescription(
+                device_key=KEY_CONDUCTIVITY,
+                device_class=SensorDeviceClass.CONDUCTIVITY,
+                native_unit_of_measurement=Units.CONDUCTIVITY,
+            ),
+            KEY_SIGNAL_STRENGTH: SensorDescription(
+                device_key=KEY_SIGNAL_STRENGTH,
+                device_class=SensorDeviceClass.SIGNAL_STRENGTH,
+                native_unit_of_measurement=Units.SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
+            ),
+        },
+        entity_values={
+            KEY_CONDUCTIVITY: SensorValue(
+                device_key=KEY_CONDUCTIVITY, name="Conductivity", native_value=1000
+            ),
+            KEY_SIGNAL_STRENGTH: SensorValue(
+                device_key=KEY_SIGNAL_STRENGTH, name="Signal Strength", native_value=-60
+            ),
+        },
+    )
+
+
 def test_bthome_event_button_long_press(caplog):
     """Test BTHome parser for an event of a long press on a button without encryption."""
     data_string = b"\x40\x3A\x04"