TheAgentK / tuya-mqtt

Nodejs-Script to combine tuyaapi and openhab via mqtt
MIT License
173 stars 81 forks source link

Devices behind zigbee gateway available with tuya-cli but not tuya-mqtt #85

Closed timo12357 closed 3 months ago

timo12357 commented 1 year ago

Background I have a bunch of Tuya zigbee temperature and humidity sensors connected via a wireless Tuya zigbee gateway. I have configured them as described in: https://community.openhab.org/t/tuya-devices-to-openhab-via-mqtt-a-working-solution-without-flashing/106756. Tuya-cli wizard produces a devices.conf that is missing ip and version. By adding those I can access the gateway. This is what my devices.conf looks like:

[
  {
    name: 'Gateway',
    ip: '192.168.1.110',
    version: '3.3',
    id: 'bf828770253d**********',
    key: '322f1a**********',
    subDevices: [
      {
        name: 'Outdoor',
        ip: '192.168.1.110',
        version: '3.3',
        id: 'bfd9e1682954**********',
        cid: 'a4c138**********'
      },
      {
        name: 'Indoor',
        ip: '192.168.1.110',
        version: '3.3',        
        id: 'bfdc73e03341**********',
        cid: 'a4c138**********'
      }
    ]
  }
]

I can read the "Indoor" sensor with tuya-cli like so tuya-cli get --ip 192.168.0.110 --id bf828770253d********** --key 322f1a********** --cid a4c138********** --protocol-version 3.3 Same works for "Oudoor", too.

Expected behavior Tuya-mqtt to read the individual sensor values in a similar fashion as tuya-cli does. In MQTT publishing states under tuya/Indoor/dps/2 and tuya/Outdoor/dps/2 DPS 1 is temperature, 2 is humidity and 4 is battery state.

**Actual behavior*** Tuya-mqtt publishes both "Indoor" and "Outdoor" values under tuya/Gateway/dps/1, 2 or 4 as if the Gateway would be the sensor.

I have tried quite a few variations of devices.conf but the best I can get is an online/offline state from the sensors. The actual measured values are always published directly under the Gateway tree. If anyone has a working devices.conf for sensors behind a tuya zigbee gateway a copy to use as model would be greatly appreciated.

lehanspb commented 1 year ago

Each subdevice has own id called "cid". But the original code of tuya-mqtt project has no ability to process values from subdevices.

I've forked this project and made some changes to fix it.

Please try: https://github.com/lehanspb/tuya-mqtt

I'm not a developer and fixed the code as best I could. It works for my Zigbee TRV behind Tuya Wireless Gateway. Also see readme file. I hope I have explained in an accessible way how to work with subdevices.

Anyway feel free to contact me.