adizanni / hydrao

Home Assistant Custom Integration for Hydrao shower head
MIT License
8 stars 0 forks source link

MQTT integration for HYDRAO Shower head #1

Open caubios opened 4 months ago

caubios commented 4 months ago

Hi Andy,

Did you consider to mainstream your knowledge of HYDRAO BT protocol to try an implementation in :

This way everything could be streamline with Jeedom/Home Automation and simple to deploy on any BT STM32 device which is much more easy to install in a bathroom that a raspberry :-)

I would be happy to discuss/help if you're into it!

adizanni commented 4 months ago

Hello @caubios , yes looking at the code it seems they implement a generic active conversation with the Bluetooth device. I think that it is feasible using the right configuration (no code). I should dedicate a little time to it. If you know better the framework, my knowledge is pretty much concentrated into these few lines of python code:

        data1 = await client.read_gatt_char("0000ca1c-0000-1000-8000-00805f9b34fb")
        device.sensors["current_volume"] = int.from_bytes(data1[2:4], byteorder="little")
        device.sensors["total_volume"] = int.from_bytes(data1[0:2], byteorder="little")
        data2 = await client.read_gatt_char("0000ca32-0000-1000-8000-00805f9b34fb")
        device.sensors["current_temperature"] = (int.from_bytes(data2[0:2], byteorder="little") / 2)
        device.sensors["average_temperature"] = (int.from_bytes(data2[2:4], byteorder="little") / 2)
        data3 = await client.read_gatt_char("0000ca26-0000-1000-8000-00805f9b34fb")
        device.sensors["current_duration"] = (int.from_bytes(data3[0:2], byteorder="little") / 50)

You have the BLE characteristic and the data decoding.

caubios commented 4 months ago

I don't know the framework nor BT protocol, I'm much more a linux low level driver developper...

First I'll setup everything in the next few days (the board, the framework & compilers, etc.), give a first try and let you know if i'm lost somewhere.

Let me know if you dedicate some time to it. Will move faster with 4 hands than 2.

adizanni commented 4 months ago

If you use ESPHome, the hydrao reading can be achieved via BLE_Client sensor. I need to see if I can make it work

adizanni commented 4 months ago

Not sure if this is what you wanted to achieve, but I was able to get the sensor values via ESPHome using the BLE Client module, example:

  - platform: ble_client
    type: characteristic
    ble_client_id: hydrao_small_bathroom
    name: "Current Volume"
    service_uuid: '180f'
    characteristic_uuid: 'ca1c'
    unit_of_measurement: 'L'
    update_interval: 2000ms
    lambda: |-
      if (x.size() >= 2) {
        uint16_t value = (x[1] << 8) | x[0];
        return static_cast<float>(value);
      }
      return NAN;

This does not mean that the integration will be automatically detected and managed. I'm not expert enough to make sure that Hydrao will work out of the box when bluetooth le tracker is activated. Not even sure that this is even possible using ble proxies (ESP or Shelly for instance) unless you create a module in ESPHome (maybe this is what you are up to).