Code Monkey home page Code Monkey logo

Comments (8)

ebw44 avatar ebw44 commented on June 8, 2024

There is a problem with ESPHome ble on_connect event. The quick fix was to add a button to manually start the ble notification from home assistant. But adding the button press in the on_connect event actions seems to work for me. So I have committed that change. Let me know if it works or not for you.

Normally you should now get

[23:29:08][D][button:010]: 'Inkbird IHT-2PB notification' Pressed.
[23:29:08][D][ble_client.automation:026]: Write type: ESP_GATT_WRITE_TYPE_RSP
[23:29:08][E][ble_client.automation:031]: Characteristic 0000FFE4-0000-1000-8000-00805F9B34FB does not allow writing
[23:29:08][W][component:214]: Component esp32_ble took a long time for an operation (0.07 s).
[23:29:08][W][component:215]: Components should block for at most 20-30ms.
[23:29:08][D][esp32_ble_tracker:246]: Starting scan...
[23:29:09][D][sensor:094]: 'Inkbird IHT-2PB last probe data': Sending state -1.00000  with 0 decimals of accuracy
[23:29:09][D][sensor:094]: 'Inkbird IHT-2PB last probe data': Sending state -1.00000  with 0 decimals of accuracy
[23:29:09][D][sensor:094]: 'Inkbird IHT-2PB last probe data': Sending state -1.00000  with 0 decimals of accuracy
[23:29:09][D][sensor:094]: 'Inkbird IHT-2PB last probe data': Sending state -1.00000  with 0 decimals of accuracy
[23:29:09][D][sensor:094]: 'Inkbird IHT-2PB last probe data': Sending state -1.00000  with 0 decimals of accuracy
[23:29:10][D][sensor:094]: 'Inkbird IHT-2PB probe manual': Sending state 23.80000 �C with 1 decimals of accuracy
[23:29:10][D][sensor:094]: 'Inkbird IHT-2PB last probe data': Sending state 1.00000  with 0 decimals of accuracy
[23:29:13][D][sensor:094]: 'Inkbird IHT-2PB last probe data': Sending state -1.00000  with 0 decimals of accuracy

from esphome-inkbird-ith-2pb.

vezinpi avatar vezinpi commented on June 8, 2024

Hi, Thank you for your quick reply.

My bad. It is working when I push the notification button in Home Assistant. Sorry about the confusion. With your latest modification I was expecting the button push to be automatic but in my case I still need to manually press it. The command might be happening too soon in the process.

The only error still showing once in a while is the following:

[W][ble_sensor:080]: Error reading char at handle 21, status=2

Again, Many thanks

from esphome-inkbird-ith-2pb.

ebw44 avatar ebw44 commented on June 8, 2024

I should have added the information about the notification button. I thought I would find a solution before anyone else uses it.
If you have a bit of time to do some testing you could try to add some delay in the on_connect or activate_temperature_notifications script to see if it allows the ble connection to finish before starting the writing of characteristic that starts the notifications.

    on_connect:
      then:
        - lambda: |-
            ESP_LOGD("ble_client_lambda", "Connected to BLE device");
            id(inkbird_IHT_2PB_connected).publish_state(true);
        # on_connect is triggered before the device is fully connected see https://github.com/esphome/issues/issues/4153
        # But even with a 10ms delay it doesn't seem to work. So the solution is to add a button that is pressed and start the script to activate
        # the notifications. This also allows the user to force the notifications manually.
        - delay: 10ms
        - button.press: inkbird_IHT_2PB_notification
script:
  - id: activate_temperature_notifications
    then:
      - delay: 10ms
      - ble_client.ble_write:
          id: inkbird_IHT_2PB_ble
          service_uuid: 0000ffe0-0000-1000-8000-00805f9b34fb
          characteristic_uuid: 0000ffe9-0000-1000-8000-00805f9b34fb
          value: [0x55, 0xAA, 0x19, 0x01, 0x00, 0x19]
      - ble_client.ble_write:
          id: inkbird_IHT_2PB_ble
          service_uuid: 0000ffe0-0000-1000-8000-00805f9b34fb
          characteristic_uuid: 0000ffe4-0000-1000-8000-00805f9b34fb
          value: [0x55, 0xAA, 0x1A, 0x01, 0x00, 0x1A]

from esphome-inkbird-ith-2pb.

vezinpi avatar vezinpi commented on June 8, 2024

Hi,

I was about to write to you. I did add a delay yesterday and it works like a charm. Upon reboot the I do not need to do anything for the data to come in.

I went a bit agressive with the delay with "delay: 1000ms". I figured what is the rush... I can try other values if you want.

Any idea about the last remaining error that poped up once in a while:

[W][ble_sensor:080]: Error reading char at handle 21, status=2

It seems to be happening every time the manual proble value is updated.

Many thanks for your assistance

from esphome-inkbird-ith-2pb.

vezinpi avatar vezinpi commented on June 8, 2024

Hi again,

2 more things I did not mentionned.

First the delay I added in the on_connect before the button.press

ble_client:

  • mac_address: !secret ble_mac_address
    id: inkbird_IHT_2PB_ble
    on_connect:
    then:
    - lambda: |-
    ESP_LOGD("ble_client_lambda", "Connected to BLE device");
    id(inkbird_IHT_2PB_connected).publish_state(true);
    # We need to add a small delay because on_connect is triggered before the device is fully connected
    # see esphome/issues#4153
    # But even with a 10ms delay it doesn't seem to work. So the solution is to add a button for the user to activate the notifications.
    # - delay: 10ms
    # - script.execute: activate_temperature_notifications
    - delay: 1000ms
    - button.press: inkbird_IHT_2PB_notification
    on_disconnect:

Second, I changed the last line of you script from: return (float)probeNr; to: return: (float)probeNr -1; to get the number reported to match the probe #. 0 = manual 1 = probe 1 and 2 = probe 2. This seemed more logical to me.

from esphome-inkbird-ith-2pb.

vezinpi avatar vezinpi commented on June 8, 2024

Hi, sorry for the delay I was away for a few days.

Adding: delay: 10 ms in the: on_connect or activate_temperature_notifications, as you suggested, works just fine.

Also I do not understand why the "last probe data" is sometime reporting a value of -1 (I know, I change the probeNr to probeNr - 1 but I was expecting the values to be 0,1 or 2 in my case or 1,2 or 3 as per the original code).

[W][ble_sensor:080]: Error reading char at handle 21, status=2
[10:06:29][D][sensor:094]: 'Inkbird IHT-2PB probe manual': Sending state 21.90000 °C with 1 decimals of accuracy
[10:06:29][D][sensor:094]: 'Inkbird IHT-2PB last probe data': Sending state 0.00000 with 0 decimals of accuracy
[10:06:29][D][sensor:094]: 'Inkbird IHT-2PB last probe data': Sending state -1.00000 with 0 decimals of accuracy
[10:06:51][W][ble_sensor:080]: Error reading char at handle 21, status=2
[10:07:34][D][sensor:094]: 'Inkbird IHT-2PB probe manual': Sending state 21.90000 °C with 1 decimals of accuracy
[10:07:34][D][sensor:094]: 'Inkbird IHT-2PB last probe data': Sending state 0.00000 with 0 decimals of accuracy
[10:07:34][D][sensor:094]: 'Inkbird IHT-2PB probe 2': Sending state 21.70000 °C with 1 decimals of accuracy
[10:07:34][D][sensor:094]: 'Inkbird IHT-2PB last probe data': Sending state 2.00000 with 0 decimals of accuracy
[10:07:51][W][ble_sensor:080]: Error reading char at handle 21, status=2

from esphome-inkbird-ith-2pb.

vezinpi avatar vezinpi commented on June 8, 2024

Hi again,

Since you succesfully manage to connect and extract the information from the thermometer, do you have any information(format, protocol, etc...) that you could share with respect to the service uuid: ffe0 and its associated characteristics uuid: ffe4 and ffe9. They seemed proprietary but somehow you figured them out.

Just starting in BLE and the format used by each fields associated with the service and characteristics would go a long way helping me understand the fucntionnality.

Thanks in advance

from esphome-inkbird-ith-2pb.

ebw44 avatar ebw44 commented on June 8, 2024

Hi,

For the probeNr I just push a change to use more meaningful number for the "last probe data" entity (c943486).
For the BLE protocol, I didn't do the reverse engineering, it was done in https://gitlab.com/sensor-stuff/inkbird-iht-2pb-to-mqtt
I'd like to add more features, like settings the temperature alarm of the ITH-2PB. But I haven't found the time to look at the BLE protocol. I did some recording of the inkbird app communication with the sensor. But the android log file 'btsnoop_hci.log' is not straightforward to look at. If you want to have a go at it you call look at https://medium.com/@charlie.d.anderson/how-to-get-the-bluetooth-host-controller-interface-logs-from-a-modern-android-phone-d23bde00b9fa

from esphome-inkbird-ith-2pb.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.