milo526 / homebridge-tuya-web

Hoobs and Homebridge plugin for Tuya devices using Home Assistant Tuya Web Api
MIT License
219 stars 95 forks source link

Outlet strip devices show up as fan/switch/light in HomeKit #431

Closed vfontes closed 2 years ago

vfontes commented 2 years ago

Describe the bug I have a few Tuya outlet strips, each one with 4 regular outlets and 4 USB type-A ports for charging. Each outlet can be individually controlled, and the 4 USB ports show up as a single outlet.

The plugin correctly exposes all devices to HomeKit and I can control them individually as expected, however, I can not set the device type to outlet in HomeKit, as it only have the option of showing the devices as fans, switches, or lights.

Here's a couple screenshots from the Tuya app and from HomeKit to better illustrate it: IMG_CCF5F2F7EC4C-1 IMG_4E756E16F89C-1

Steps To Reproduce

  1. Add an outlet strip device to the Tuya app.
  2. Add the device to the Homebridge plugin, and set its type to Outlet.
  3. Note how the devices show up as fans/lights/switches in HomeKit, with no option of showing them as outlets.

Plugin Version 1.1.1

Homebridge Config

{
    "name": "TuyaWebPlatform",
    "options": {
        "username": "REDACTED",
        "password": "REDACTED",
        "countryCode": "55",
        "platform": "tuya",
        "pollingInterval": 600
    },
    "defaults": [
        {
            "id": "eb0b7e08b8a6821c16y32z",
            "device_type": "outlet"
        }
    ],
    "scenes": false,
    "platform": "TuyaWebPlatform"
}

Device Config

vfontes@Viniciuss-MacBook-Air Desktop % python3 script.py
Getting credentials
Got credentials
{   'access_token': 'REDACTED',
    'expires_in': 864000,
    'refresh_token': 'REDACTED',
    'token_type': 'bearer'}
Getting devices
Got devices
{   'header': {'code': 'SUCCESS', 'payloadVersion': 1},
    'payload': {   'devices': [   {   'data': {'online': True, 'state': True},
                                      'dev_type': 'switch',
                                      'ha_type': 'switch',
                                      'icon': 'https://images.tuyaus.com/smart/icon/ay1540090774726g5666/1627487277044a91331d7.png',
                                      'id': 'eb735b47d5c5f0b3ddkmqj',
                                      'name': 'Escritório Tomada'},
                                  {   'data': {'online': True, 'state': True},
                                      'dev_type': 'switch',
                                      'ha_type': 'switch',
                                      'icon': 'https://images.tuyaus.com/smart/icon/ay1540090774726g5666/1627487277044a91331d7.png',
                                      'id': 'ebf8f345b80ee31fa2hvf2',
                                      'name': 'Sala Tomada'},
                                  {   'data': {'online': True, 'state': True},
                                      'dev_type': 'switch',
                                      'ha_type': 'switch',
                                      'icon': 'https://images.tuyaus.com/smart/icon/ay149682747096840kwW/1624687328daa1a323f75.jpg',
                                      'id': 'eb0b7e08b8a6821c16y32z_1',
                                      'name': '1 Tomada'},
                                  {   'data': {'online': True, 'state': True},
                                      'dev_type': 'switch',
                                      'ha_type': 'switch',
                                      'icon': 'https://images.tuyaus.com/smart/icon/ay149682747096840kwW/1624687328daa1a323f75.jpg',
                                      'id': 'eb0b7e08b8a6821c16y32z_2',
                                      'name': '2 Tomada'},
                                  {   'data': {'online': True, 'state': True},
                                      'dev_type': 'switch',
                                      'ha_type': 'switch',
                                      'icon': 'https://images.tuyaus.com/smart/icon/ay149682747096840kwW/1624687328daa1a323f75.jpg',
                                      'id': 'eb0b7e08b8a6821c16y32z_3',
                                      'name': '3 Tomada'},
                                  {   'data': {'online': True, 'state': False},
                                      'dev_type': 'switch',
                                      'ha_type': 'switch',
                                      'icon': 'https://images.tuyaus.com/smart/icon/ay149682747096840kwW/1624687328daa1a323f75.jpg',
                                      'id': 'eb0b7e08b8a6821c16y32z_4',
                                      'name': '4 Chaleira'},
                                  {   'data': {'online': True, 'state': True},
                                      'dev_type': 'switch',
                                      'ha_type': 'switch',
                                      'icon': 'https://images.tuyaus.com/smart/icon/ay149682747096840kwW/1624687328daa1a323f75.jpg',
                                      'id': 'eb0b7e08b8a6821c16y32z_5',
                                      'name': '5 USB'},
                                  {   'data': {'online': True, 'state': True},
                                      'dev_type': 'switch',
                                      'ha_type': 'switch',
                                      'icon': 'https://images.tuyaus.com/smart/icon/ay149682747096840kwW/1624687328daa1a323f75.jpg',
                                      'id': 'ebbc3c1438610265d3eq6c_1',
                                      'name': '1 Roteador'},
                                  {   'data': {'online': True, 'state': True},
                                      'dev_type': 'switch',
                                      'ha_type': 'switch',
                                      'icon': 'https://images.tuyaus.com/smart/icon/ay149682747096840kwW/1624687328daa1a323f75.jpg',
                                      'id': 'ebbc3c1438610265d3eq6c_2',
                                      'name': '2 Modem'},
                                  {   'data': {'online': True, 'state': True},
                                      'dev_type': 'switch',
                                      'ha_type': 'switch',
                                      'icon': 'https://images.tuyaus.com/smart/icon/ay149682747096840kwW/1624687328daa1a323f75.jpg',
                                      'id': 'ebbc3c1438610265d3eq6c_3',
                                      'name': '3 HT'},
                                  {   'data': {'online': True, 'state': True},
                                      'dev_type': 'switch',
                                      'ha_type': 'switch',
                                      'icon': 'https://images.tuyaus.com/smart/icon/ay149682747096840kwW/1624687328daa1a323f75.jpg',
                                      'id': 'ebbc3c1438610265d3eq6c_4',
                                      'name': '4 TV'},
                                  {   'data': {'online': True, 'state': True},
                                      'dev_type': 'switch',
                                      'ha_type': 'switch',
                                      'icon': 'https://images.tuyaus.com/smart/icon/ay149682747096840kwW/1624687328daa1a323f75.jpg',
                                      'id': 'ebbc3c1438610265d3eq6c_5',
                                      'name': '5 RPi'},
                                  {   'data': {'online': True, 'state': True},
                                      'dev_type': 'switch',
                                      'ha_type': 'switch',
                                      'icon': 'https://images.tuyaus.com/smart/icon/ay149682747096840kwW/1624687328daa1a323f75.jpg',
                                      'id': 'eb41b1efd9107d6aa4pwgm_1',
                                      'name': '11 Braava'},
                                  {   'data': {'online': True, 'state': True},
                                      'dev_type': 'switch',
                                      'ha_type': 'switch',
                                      'icon': 'https://images.tuyaus.com/smart/icon/ay149682747096840kwW/1624687328daa1a323f75.jpg',
                                      'id': 'eb41b1efd9107d6aa4pwgm_2',
                                      'name': '12 Roomba'},
                                  {   'data': {'online': True, 'state': False},
                                      'dev_type': 'switch',
                                      'ha_type': 'switch',
                                      'icon': 'https://images.tuyaus.com/smart/icon/ay149682747096840kwW/1624687328daa1a323f75.jpg',
                                      'id': 'eb41b1efd9107d6aa4pwgm_3',
                                      'name': '13'},
                                  {   'data': {'online': True, 'state': False},
                                      'dev_type': 'switch',
                                      'ha_type': 'switch',
                                      'icon': 'https://images.tuyaus.com/smart/icon/ay149682747096840kwW/1624687328daa1a323f75.jpg',
                                      'id': 'eb41b1efd9107d6aa4pwgm_4',
                                      'name': '14'},
                                  {   'data': {'online': True, 'state': False},
                                      'dev_type': 'switch',
                                      'ha_type': 'switch',
                                      'icon': 'https://images.tuyaus.com/smart/icon/ay149682747096840kwW/1624687328daa1a323f75.jpg',
                                      'id': 'eb41b1efd9107d6aa4pwgm_5',
                                      'name': '15'},
                                  {   'data': {'online': True, 'state': True},
                                      'dev_type': 'switch',
                                      'ha_type': 'switch',
                                      'icon': 'https://images.tuyaus.com/smart/icon/ay149682747096840kwW/1624687328daa1a323f75.jpg',
                                      'id': 'eb7f9a2db3b71c7dd7ogpk_1',
                                      'name': '6 Nintendo'},
                                  {   'data': {'online': True, 'state': True},
                                      'dev_type': 'switch',
                                      'ha_type': 'switch',
                                      'icon': 'https://images.tuyaus.com/smart/icon/ay149682747096840kwW/1624687328daa1a323f75.jpg',
                                      'id': 'eb7f9a2db3b71c7dd7ogpk_2',
                                      'name': '7 Sw Eth'},
                                  {   'data': {'online': True, 'state': True},
                                      'dev_type': 'switch',
                                      'ha_type': 'switch',
                                      'icon': 'https://images.tuyaus.com/smart/icon/ay149682747096840kwW/1624687328daa1a323f75.jpg',
                                      'id': 'eb7f9a2db3b71c7dd7ogpk_3',
                                      'name': '8 Apple TV'},
                                  {   'data': {'online': True, 'state': True},
                                      'dev_type': 'switch',
                                      'ha_type': 'switch',
                                      'icon': 'https://images.tuyaus.com/smart/icon/ay149682747096840kwW/1624687328daa1a323f75.jpg',
                                      'id': 'eb7f9a2db3b71c7dd7ogpk_4',
                                      'name': '9 PS5'},
                                  {   'data': {'online': True, 'state': True},
                                      'dev_type': 'switch',
                                      'ha_type': 'switch',
                                      'icon': 'https://images.tuyaus.com/smart/icon/ay149682747096840kwW/1624687328daa1a323f75.jpg',
                                      'id': 'eb7f9a2db3b71c7dd7ogpk_5',
                                      'name': '10 Zigbee'},
                                  {   'data': {},
                                      'dev_type': 'scene',
                                      'ha_type': 'scene',
                                      'id': 'lyYEXsAbuAmBjHZv',
                                      'name': 'If Outlet Voltage : <199.5V'},
                                  {   'data': {},
                                      'dev_type': 'scene',
                                      'ha_type': 'scene',
                                      'id': 'ML5GGtM18blyn8J5',
                                      'name': 'If Outlet Voltage : >201.3V'}],
                   'scenes': []}}
!!! NOW REMOVE THIS FILE, SO YOUR CREDENTIALS (username, password) WON'T LEAK !!!
vfontes@Viniciuss-MacBook-Air Desktop %

Additional Context

milo526 commented 2 years ago

Thanks for completing the template, that is really helpful!

I expect that adding the number after the identifier should solve your problem.

{
   "name": "TuyaWebPlatform",
   "options": {
       "username": "REDACTED",
       "password": "REDACTED",
       "countryCode": "55",
       "platform": "tuya",
       "pollingInterval": 600
   },
   "defaults": [
       {
           "id": "eb0b7e08b8a6821c16y32z_1",
           "device_type": "outlet"
       },
       {
           "id": "eb0b7e08b8a6821c16y32z_2",
           "device_type": "outlet"
       }
   ],
   "scenes": false,
   "platform": "TuyaWebPlatform"
}

You could also try replacing the id with the name i.e.

{
  "id": "1 Tomada",
  "device_type": "outlet"
}
vfontes commented 2 years ago

That did the trick, thank you so much!

milo526 commented 2 years ago

Good to hear! Which of the two worked for you?

vfontes commented 2 years ago

I only tried adding _1, _2, etc at the end of the IDs, and it worked first try. This is how my settings look like now:

 "defaults": [
        {
            "id": "eb0b7e08b8a6821c16y32z_1",
            "device_type": "outlet"
        },
        {
            "id": "eb0b7e08b8a6821c16y32z_2",
            "device_type": "outlet"
(...)