0x5e / homebridge-tuya-platform

Make homebridge-tuya-platform great again.
MIT License
216 stars 65 forks source link

Diffuser is more a Humidifier with a Lightbulb #181

Open soko-xyz opened 1 year ago

soko-xyz commented 1 year ago

First off all thank you very much for adding all my devices that were unsupported.

I got 2 Diffuser they more like Humidifier. They evaporate Water with ultrasonic vibration. Any they got a LED light inside.

So my Feature Request is could you make its Homebridge Service from "Air Purifier, Lightbulb" to "Humidifier, Lightbulb".

In addition mine got no "switch", its always on. Is it possible to overwrite this with the Advanced Options?

0x5e commented 1 year ago

I have the same thought but, homekit humidifier requires Current Relative Humidity, most diffuser don't have this. change to Humidifier would always display a text like "decreasing humidity to 0%". What do you think about it?

you can try to overwrite dp code 'switch' into anything unused. by the way, is the switch working for you? or just didn't show up in your device's tuya control panel?

soko-xyz commented 1 year ago

I did overwrite my Diffuser to Product Code jsq for Humidifier and mapped DP Code 'switch' to 'switch_spray'. I didn't noticed the humidity sensor. But you're absolutely right that's not the way it should appear on the home app.

I got a warning in console which direkt me to the README on GitHub. I had to use advanced options but I run into problems with my "always on" device. On the one hand with DP Code 'switch' to 'switch_spray' it will spray even if I just want to turn on the LED. On the other hand with DP Code 'switch' to 'switch_led' the led will light up even if I just turned on the spray. Unfortunately there is nothing unused. In addition, without the Productcode mapping the LED won't show as RGB in Home App is there a way to fix that?

0x5e commented 1 year ago

You mean your diffuser only have switch_spray and switch_led, don't have switch? If so, I can remove the requirement of switch in the future version.

the reason why spray and led are both opened is because the current code will turn on the main switch if spray or led is opened.

RGB is not supported yet, since many products have mixed feature like lights, I haven't configured out how to better support this, since RGB light's code is complicated, copy it between every products seems not good to maintain...

soko-xyz commented 1 year ago

Mine don't have switch. Here is my Standard Instruction Set:

Code Type Values
switch_spray Boolean "{true,false}"
mode Enum { "range": [ "large", "small" ] }
countdown Enum { "range": [ "cancel", "1", "3", "6" ] }
switch_led Boolean "{true,false}"
work_mode Enum { "range": [ "colour", "colourful1" ] }
bright_value Integer { "unit": "", "min": 0, "max": 255, "scale": 0, "step": 1 }
colour_data String { "maxlen": 255 }
0x5e commented 1 year ago

Got it. switch will be change to optional later. for the lights I will support it in the future.

0x5e commented 1 year ago

rgb supported in beta.18, please have a try.

soko-xyz commented 1 year ago

Sorry to tell you but now its crashing:

[12/29/2022, 3:53:58 PM] TypeError: Cannot read properties of undefined (reading 'property') at /homebridge/node_modules/@0x5e/homebridge-tuya-platform/src/accessory/characteristic/Light.ts:116:39 at DiffuserAccessory.updateAllValues (/homebridge/node_modules/@0x5e/homebridge-tuya-platform/src/accessory/BaseAccessory.ts:112:46)

0x5e commented 1 year ago

Sorry I forget to add colour_data for color schema, could you try remap colour_data to colour_data_hsv ? I will add this code in the next version.

antonioreyna commented 1 year ago

how can i control the rgb of my diffuser? it only shows the on off lightbulb on home app?

0x5e commented 1 year ago

@antonioreyna probably your rgb schema is not show up, please see readme, change the control mode.

soko-xyz commented 1 year ago

Sorry to reply late, wasn't in town. Unfortunately there is still a crash with the diffuser:

[1/4/2023, 9:37:28 AM] TypeError: Cannot destructure property 'max' of 'colorSchema.property.v' as it is undefined. at /homebridge/node_modules/@0x5e/homebridge-tuya-platform/src/accessory/characteristic/Light.ts:116:17 at DiffuserAccessory.updateAllValues (/homebridge/node_modules/@0x5e/homebridge-tuya-platform/src/accessory/BaseAccessory.ts:112:46)

0x5e commented 1 year ago

@JoshuaSokolowski Can you post your device's status? these can be found in device list json, see faq.

soko-xyz commented 1 year ago
{
    "active_time": 1643212647,
    "biz_type": 0,
    "category": "xxj",
    "create_time": 1634119157,
    "icon": "smart/icon/ay15591173285745WPhW/cc3c02174f6b1468ed8c56cc6d233962.jpg",
    "id": "xxxxxxxxxxxxxxx",
    "ip": "x.x.x.x",
    "lat": "xxxxxxx",
    "local_key": "xxxxxxx",
    "lon": "xxxxxxx",
    "model": "本厂通用模块",
    "name": "Zimmer Aroma Diffuser",
    "online": false,
    "owner_id": "xxxxxxx",
    "product_id": "0kezozmqlu2iv0ki",
    "product_name": "Aroma Diffuser",
    "status": [
      {
        "code": "bright_value",
        "value": 0
      },
      {
        "code": "colour_data",
        "value": "00000000000000"
      },
      {
        "code": "countdown",
        "value": "cancel"
      },
      {
        "code": "countdown_left",
        "value": 0
      },
      {
        "code": "mode",
        "value": "large"
      },
      {
        "code": "switch_led",
        "value": false
      },
      {
        "code": "switch_spray",
        "value": false
      },
      {
        "code": "work_mode",
        "value": "colour"
      }
    ],
    "sub": false,
    "time_zone": "+01:00",
    "uid": "xxxxxxx",
    "update_time": 1655529675,
    "uuid": "xxxxxxx",
    "schema": [
      {
        "code": "bright_value",
        "mode": "rw",
        "type": "Integer",
        "property": {
          "unit": "",
          "min": 0,
          "max": 255,
          "scale": 0,
          "step": 1
        }
      },
      {
        "code": "colour_data",
        "mode": "rw",
        "type": "String",
        "property": {
          "maxlen": 255
        }
      },
      {
        "code": "countdown",
        "mode": "rw",
        "type": "Enum",
        "property": {
          "range": [
            "cancel",
            "1",
            "3",
            "6"
          ]
        }
      },
      {
        "code": "countdown_left",
        "mode": "ro",
        "type": "Integer",
        "property": {
          "unit": "min",
          "min": 0,
          "max": 360,
          "scale": 0,
          "step": 1
        }
      },
      {
        "code": "mode",
        "mode": "rw",
        "type": "Enum",
        "property": {
          "range": [
            "large",
            "small"
          ]
        }
      },
      {
        "code": "switch_led",
        "mode": "rw",
        "type": "Boolean",
        "property": {}
      },
      {
        "code": "switch_spray",
        "mode": "rw",
        "type": "Boolean",
        "property": {}
      },
      {
        "code": "work_mode",
        "mode": "rw",
        "type": "Enum",
        "property": {
          "range": [
            "colour",
            "colourful1"
          ]
        }
      }
    ]
  },
  {
    "active_time": 1643211835,
    "biz_type": 0,
    "category": "xxj",
    "create_time": 1634119388,
    "icon": "smart/icon/ay15591173285745WPhW/cc3c02174f6b1468ed8c56cc6d233962.jpg",
    "id": "xxxxxxx",
    "ip": "x.x.x.x",
    "lat": "xxxxxxx",
    "local_key": "xxxxxxx",
    "lon": "xxxxxxx",
    "model": "本厂通用模块",
    "name": "Studierzimmer Aroma Diffuser",
    "online": true,
    "owner_id": "xxxxxxx",
    "product_id": "0kezozmqlu2iv0ki",
    "product_name": "Aroma Diffuser",
    "status": [
      {
        "code": "bright_value",
        "value": 0
      },
      {
        "code": "colour_data",
        "value": "00000000000000"
      },
      {
        "code": "countdown",
        "value": "cancel"
      },
      {
        "code": "countdown_left",
        "value": 0
      },
      {
        "code": "mode",
        "value": "large"
      },
      {
        "code": "switch_led",
        "value": false
      },
      {
        "code": "switch_spray",
        "value": false
      },
      {
        "code": "work_mode",
        "value": "colour"
      }
    ],
    "sub": false,
    "time_zone": "+01:00",
    "uid": "xxxxxxx",
    "update_time": 1655529675,
    "uuid": "xxxxxxx",
    "schema": [
      {
        "code": "bright_value",
        "mode": "rw",
        "type": "Integer",
        "property": {
          "unit": "",
          "min": 0,
          "max": 255,
          "scale": 0,
          "step": 1
        }
      },
      {
        "code": "colour_data",
        "mode": "rw",
        "type": "String",
        "property": {
          "maxlen": 255
        }
      },
      {
        "code": "countdown",
        "mode": "rw",
        "type": "Enum",
        "property": {
          "range": [
            "cancel",
            "1",
            "3",
            "6"
          ]
        }
      },
      {
        "code": "countdown_left",
        "mode": "ro",
        "type": "Integer",
        "property": {
          "unit": "min",
          "min": 0,
          "max": 360,
          "scale": 0,
          "step": 1
        }
      },
      {
        "code": "mode",
        "mode": "rw",
        "type": "Enum",
        "property": {
          "range": [
            "large",
            "small"
          ]
        }
      },
      {
        "code": "switch_led",
        "mode": "rw",
        "type": "Boolean",
        "property": {}
      },
      {
        "code": "switch_spray",
        "mode": "rw",
        "type": "Boolean",
        "property": {}
      },
      {
        "code": "work_mode",
        "mode": "rw",
        "type": "Enum",
        "property": {
          "range": [
            "colour",
            "colourful1"
          ]
        }
      }
    ]
  }
0x5e commented 1 year ago

I've just noticed your colour_data is String type, the normal one should be Json. It's not supported... I will update the code to prevent it from crash.

      {
        "code": "colour_data",
        "mode": "rw",
        "type": "String",
        "property": {
          "maxlen": 255
        }
      }
antonioreyna commented 1 year ago

where do i see that status log?

antonioreyna commented 1 year ago

i have this on mine CleanShot 2023-01-22 at 9 55 28

soko-xyz commented 1 year ago

Hi again thank you very much for preventing my homebridge from crashing. Would it be possible to add support for color_data as string?

The schema is two bytes each of R, G, B, followed by followed by four bytes of hue (in the range 0 to 360) followed by two bytes of value, followed by two bytes which represent the brightness.

All values except for hue are 0-255, and all values must be set.

To recap: RR GG BB HHHH VV BrBr

0x5e commented 1 year ago

@antonioreyna https://github.com/0x5e/homebridge-tuya-platform#troubleshooting

@JoshuaSokolowski I don't understand why the color_data string have both rgb and hsv? the "value" and "brightness" are they the same thing (hsv/hsb)?

0x5e commented 1 year ago

Found this: https://github.com/esphome/esphome/pull/4383 Sorry, life is always busy... Will update when I'm free.