Tuya wifi temperature and humidity detect

Hi, sheminasalam
If I flash tuya device to Tasmota, do you think it could work so that HA could recognize the temperature and humidity? Thanks a lot.

I answer myself:

As you have already found out, tasmota is not supported with this device. This is because tasmota works with Esp8266 or Esp32 chips which are not present in these. HA tuya integraion is constantly improving and so I think the support for temperature sensors and others will be coming shortly.

I have the same problem.
I tried to link this Tuya WiFi temperature sensor but it has been wrongly recognized as a switch.


image

Same problem for me. It appears as a switch instead of temperature/humidity sensor with logging.

I followed this guide from tuyaHA documentation.
PaulAnnekov/tuyaha: Implements the special Tuya Home Assistant API. (github.com)
It looks that the device is not supported so we need to ask tuya add it to /homeassistant API
Please, do the same to push them.

Getting devices
Got devices
{   'header': {'code': 'SUCCESS', 'payloadVersion': 1},
    'payload': {   'devices': [   {   'data': {'online': True, 'state': False},
                                      'dev_type': 'switch',
                                      'ha_type': 'switch',
                                      'icon': 'https://images.tuyaeu.com/smart/program_category_icon/wsdcg.png',
                                      'id': 'bf890f3b16dc3be1c6aijl',
                                      'name': 'Temperature Humidity Sensor'}],
                   'scenes': []}}

Tuya humidity/temperature sensor is recognized as switch · Issue #62 · PaulAnnekov/tuyaha (github.com)

As I understand from his github page, Paul Annenkov cloned and took over the deployment of the abandoned Tuya Python library “tuyapi v0.1.3”. Thus, I understand that he is developing/checking/correcting his tuyaha Python library for HA, right?

I might be wrong, but I’m wondering why he’s asking the users of his library to send an email to the unresponsive [email protected]? It’s almost 2 years since Tuya abandoned their HA Python library, will they care much if few of us would send them an email?

Hello, I fully agree with Adi_tca. Who and how unlock this problem ? Should we give up buying this device? As you have understand I have invested in these devices… and I hope use them with HA.

Is there already een solution for connection/integration tuya humidity and temperature-device; so we can read the sensor in home assistant?

I have the same problem; no solution…

Device added wrongly
Do not select “Switch” ,Select “SENSOR” whenn add it.
Then will appear temp/humidity/battery statuses

image

But then next problem
device is conecting only onece at 24h to wifi for less then 5 seconds,
take ip from router conect to tuya cloud and return to low power mode.
No chance to get data exactly in this moment.

I mailed them. But no chance yes

I have played a bit with LocalTuya and TinyTuya.

LocalTuya works well, but it seems it pull devices not so often then it could catch the data for motion and temperature/humidity sensors.

But with TinyTuya I have luck, I could run a script in the loop and wait until these sensors will wake up and push the data.

This works for me for the TuYa motion sensor and for the same Temperature and Humidity sensor.

Here small script:

import tinytuya

tinytuya.set_debug(True)

temperature = None
humidity = None
battery = None

while(True):
    d = tinytuya.OutletDevice('xxxxxxxx', '192.168.30.116', 'yyyyyyyyy')
    d.set_version(3.3)
    data = d.status() 
    print(data)
    data = d.status() 
    if isinstance(data, dict):
      if 'dps' in data:
        if '1' in data['dps']:
          temperature = data['dps']['1']
          print(temperature)
        if '2' in data['dps']:
          humidity = data['dps']['2']                 
          print(humidity)
        if '3' in data['dps']:
          battery = data['dps']['3']                 
          print(battery)
        file='/home/pi/hass/tinytuya/th001.log' 
        with open(file, 'w') as filetowrite:
          filetowrite.write('{"name":"TH001","temperature":"' + str(temperature)+ '","humidity":"' + str(humidity) + '","battery":"' + battery + '"}')

I hope this would be helpful.

Thank you. but is this working under Home assistant??
And how do i implant this.

Greetz

Hi, Rob.

Yep, in Home assistant.

Before, you need to follow the tiny tuna guide: GitHub - jasonacox/tinytuya: Python module to interface with Tuya WiFi smart devices.

Then you need to fill your device ID, IP, key in the script.
This script could be running in the background.

As you can see it write data to the log file, so you only need to read it in home assistant.

- platform: command_line
    name: TH001
    command: "/config/tinytuya/th001.sh"
    scan_interval: 60
    command_timeout: 60
    json_attributes:
      - battery
      - temperature
      - humidity
    value_template: "{{ value_json.name }}"

  - platform: template
    sensors:
      th001_temperature:
        device_class: temperature
        friendly_name: TH001 Temperature
        value_template: "{{ state_attr('sensor.th001', 'temperature') | float / 10 | round(2) }}"

  - platform: template
    sensors:
      th001_humidity:
        device_class: humidity
        friendly_name: TH001 Humidity
        value_template: "{{ state_attr('sensor.th001', 'humidity') | float | round(2) }}"

  - platform: template
    sensors:
      th001_battery:
        device_class: battery
        friendly_name: TH001 Battery
        value_template: "{{ state_attr('sensor.th001', 'battery') }}"

the content of th001.sh is:

tail -1 /config/tinytuya/th001.log

For testing, I am removing battery for 10-15 sec from this sensor, then when I put it back it connecting and send the data to the cloud, at that moment script could fetch data from it, via local API.

Thank you for your Answer. Now i have to implement it (i hope) !!!

Hi, can you help me install tinytuya and add temperature?
Thank you so much!

Thanks for posting this. I tried running your python code. Every time the temp/humidity device sends data it crashes with

DEBUG:payload generated=b'\x00\x00U\xaa\x00\x00\x00\x01\x00\x00\x00\r\x00\x00\x00\x873.3\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbdz\x81>\xa1=\xfb\xcf\xe0\xf59\xf2\xa8\xec\xc6\x19k\xfd:"\x8a7\x1c\x9f\x01\x13\xb2\xfeD\x80X\x8e\x04\xf6X\xf5?\x8e\x9cM\xb0\xd1^\xad,.A>\x86\xcd;[\xe8\xa0n\xb3\xd6\xef\xb8\xb5HbxWKk\xda\xb5\x9e\xd5\xc0\x1b\xcam\xc9.\xe9\xceO\x80*\xed\x97[\xcf\x9bIx\x01\x14\x7f\xc1E\xbf@|\x93V1\xedr&\xc5\xd8\xa3;@\xadb\x1f\xab\x8a\x1c\x94\x1b\xda\x00\x00\xaaU'
data= {'dps': {}, 't': 1}
dps= {}
DEBUG:received data=b'\x00\x00U\xaa\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00;\x00\x00\x00\x003.3\x00\x00\x00\x00\x00\x00\xa8\x14\x00\x00\x00\x016\xd9\x90?\x01\x12r+\xb7O\x0e\x8d6\xad\xa5\xd3\xb0/\xc0:\xeds^l\x03v7\xa0Zv\xd0\xd0\xa8\x9a\xb0\xdc\x00\x00\xaaU'
DEBUG:raw unpacked message = TuyaMessage(seqno=0, cmd=8, retcode=0, payload=b'3.3\x00\x00\x00\x00\x00\x00\xa8\x14\x00\x00\x00\x016\xd9\x90?\x01\x12r+\xb7O\x0e\x8d6\xad\xa5\xd3\xb0/\xc0:\xeds^l\x03v7\xa0Zv\xd0\xd0', crc=2828710108)
DEBUG:decode payload=b'3.3\x00\x00\x00\x00\x00\x00\xa8\x14\x00\x00\x00\x016\xd9\x90?\x01\x12r+\xb7O\x0e\x8d6\xad\xa5\xd3\xb0/\xc0:\xeds^l\x03v7\xa0Zv\xd0\xd0'
DEBUG:removing 3.3=b'6\xd9\x90?\x01\x12r+\xb7O\x0e\x8d6\xad\xa5\xd3\xb0/\xc0:\xeds^l\x03v7\xa0Zv\xd0\xd0'
DEBUG:decrypting=b'6\xd9\x90?\x01\x12r+\xb7O\x0e\x8d6\xad\xa5\xd3\xb0/\xc0:\xeds^l\x03v7\xa0Zv\xd0\xd0'
DEBUG:decrypted 3.3 payload='{"dps":{},"t":1}'
DEBUG:decoded results='{"dps":{},"t":1}'
Traceback (most recent call last):
  File "C:\Users\xxxxxxxxxxx\scratch.py", line 28, in <module>
    filetowrite.write('{"name":"TH001","temperature":"' + str(temperature)+ '","humidity":"' + str(humidity) + '","battery":"' + battery + '"}')
TypeError: can only concatenate str (not "NoneType") to str

Did you manage to get a solution for the too large update interval of the thermostat?? I have realised that only updates if 0,5 degree change (if it is 21,1 it will only update cloud if goes `0,5 or -0,5…) so all the accuracy (0,1) is lost…

No, there is no way in realtime to monitor when it connect to wifi, to start scan imidetly.

There is no alternative firmware with can send data, no matter when, or on any temp/humidity change.

p.s. Termostat is other thing aka controler not sensor.