ble_monitor icon indicating copy to clipboard operation
ble_monitor copied to clipboard

[New Sensor]: SwitchBot W3400010 Indoor/Outdoor Thermo-Hygrometer

Open zedrdave opened this issue 2 years ago • 7 comments

Sensor Description

SwitchBot IP65 Indoor/Outdoor Thermo-Hygrometer

Additional information

Seems to be a simpler version of the already-supported Switchbot Meter (with LCD): https://eu.switch-bot.com/pages/switchbot-indoor-outdoor-thermo-hygrometer

I have already managed to extract temp/hygro and battery from the two BLE advertisements (see below):

    if sdid == 22:
        # "service data"
        battery = int(value[8:10], 16)
    elif sdid == 255:
        # "manufacturer specific data"
        byte10 = int(value[20:22],16)
        byte11 = int(value[22:24],16)
        byte12 = int(value[24:26],16)
        tempc = ((byte10 & 0x0F) * 0.1 + (byte11 & 0x7F)) * (1 if ((byte11 & 0x80) > 0) else -1)
        humidity = byte12 & 0x7F

Happy to help with the integration (new to BLE and BLE monitor, but know my way around Python).

BLE advertisements

2023-07-06 08:02:37.644 INFO (Thread-13) [custom_components.ble_monitor.ble_parser] BLE advertisement received from MAC/UUID d65d706dc117: service data: [b'\x06\x16=\xfdw\x00\xe4']manufacturer specific data: []local name: UUID16: None,UUID128: None
2023-07-06 08:02:39.649 INFO (Thread-13) [custom_components.ble_monitor.ble_parser] BLE advertisement received from MAC/UUID d65d706dc117: service data: []manufacturer specific data: [b'\x0f\xffi\t\xd6]pm\xc1\x17\xc7\x03\x00\x97;\x00']local name: UUID16: None,UUID128: None

zedrdave avatar Jul 06 '23 06:07 zedrdave

BTW, I am currently detecting the models by identifying the 6909 at the beginning of the manufacturer string. But that seems to be tied to all Switchbot devices. Not sure where to find a more specific ID.

zedrdave avatar Jul 06 '23 06:07 zedrdave

Update:

Digging around in the code a bit, I was able to add support for parsing the service data. Adding this condition to parse_switchbot():

    elif msg_length == 7 and device_id == 0x77:
        device_type = "METER THO"
        firmware = "Switchbot"
        result = {
           "battery": data[-1]
        }
    else:
        device_type = "unknown"

The battery info seems to be parsed and returned, but for some reason does not appear in the entity attribute in HAAS interface 😞

For temp/humidity, we need to parse the manufacturer data packet, which might be a bit more hackish to spot: we can check that is starts with 6909 + device MAC address + 6 bytes (containing temp-humidity)…

zedrdave avatar Jul 06 '23 12:07 zedrdave

I have released 12.4.0-beta for testing (enable beta versions in HACS).

There is an issue with the battery parsing, as I get 228 as result. And temperature is also a bit low (-0.7°C). However, with this version, the sensors should be created and you can try to modify the code to make it work. Let me know what I have to change, when you have figured it out.

Ernst79 avatar Jul 26 '23 18:07 Ernst79

@Ernst79 Thanks… Since I posted this, the latest version of HA seems to have added out-of-the-box detection and support for it… So I am no longer using this component for it.

It might be worth looking at their code to see how they parse battery and temp info?

zedrdave avatar Jul 28 '23 16:07 zedrdave

Ah, ok. Its better to use the core HA integration anyways. But I'll check the code.

Ernst79 avatar Jul 28 '23 17:07 Ernst79

Hi, I tried updating to beta 12.4.0 but the device doesn't show up. I tried adding manually but didn't work too. I can see the packets picked up in the ESPHome. I have turned on Active scan as well. Thank you.

dsaul560 avatar Aug 24 '23 18:08 dsaul560

@dsaul560 I need some debug logging to figure out what is wrong. Please follow these instructions to provide me with the necessary info.

https://custom-components.github.io/ble_monitor/sensor_request#getting-ble-advertisements-with-the-home-assistant-logger

Ernst79 avatar Sep 22 '23 14:09 Ernst79