pschroeder89 / homebridge-levoit-humidifiers

Levoit Humidifiers Plugin for Apple HomeKit via Homebridge
Apache License 2.0
70 stars 9 forks source link

Night light support for Dual 200S #43

Closed danfratamico closed 1 year ago

danfratamico commented 1 year ago

Is your feature request related to a problem? Please describe: There are two different models of the Dual 200S. The Amazon version does not have a night light but the Target version does (the one I have). The VeSync app supports the night light function and I can control it just fine. The error I am getting in the latest version of your plugin is: This plugin generated a warning from the characteristic 'Brightness': characteristic value expected valid finite number and received "undefined" (undefined).

Describe the solution you'd like: Looking for the developers to add support for the night light function for the Dual 200S as the VeSync app supports it.

Describe alternatives you've considered: N/A

Additional context: N/A

pschroeder89 commented 1 year ago

Hey @danfratamico, can you provide me with the exact model? You can probably find it on the device, or enable debug mode in your plugin config and it will output the device model.

I recently added night light support to the LUH-D301S-WUSR model. If that's the model you have and you are seeing that error, it could be a cache issue.

rockerest commented 1 year ago

First of all, @pschroeder89, thank you very much for working on this and for being so active / responsive. You're doing great work!

(My girlfriend wanted to use her LUH-D301S-WUSR and we've just skipped the Hubitat and gone straight through the Homebridge, thanks to your plugin!)

On that note, we are also having trouble with the night light, with the exact same error reported by @danfratamico.

I've enabled debug mode and - as I noted above - it's the LUH-D301S-WUSR model.
Could you help me understand what you mean by a caching issue? Yours was the first plugin we installed for this device, so there shouldn't (🤞) be any locally cached incorrect version.

(As a complication, however, we did install the other humidifer Homebridge plugin when we noticed that the light wasn't working - but that plugin doesn't work at all)

Here's the initial debug output when the Homebridge starts up and loads the plugin:

[30/12/2022, 06:04:14] [Levoit Humidifiers] [DEBUG]: [GET DEVICES] Device List -> JSON: [{"deviceRegion":"US","isOwner":true,"authKey":null,"deviceName":"Humidifier","deviceImg":"https://image.vesync.com/defaultImages/deviceDefaultImages/wfon_ahm_luh-d301s-wusr_us_240.png","cid":[This might be customer ID?? Seems sus. Redacted for safety],"deviceStatus":"on","connectionStatus":"online","connectionType":"WiFi+BTOnboarding+BTNotify","deviceType":"LUH-D301S-WUSR","type":"wifi-air","uuid":"0a0426e1-f845-49c6-a9ea-75fb95c99482","configModule":"WFON_AHM_LUH-D301S-WUSR_US","macID":"MA:CM:AC:MA:CM:AC","mode":null,"speed":null,"currentFirmVersion":null,"subDeviceNo":null,"subDeviceType":null,"deviceFirstSetupTime":"Dec 30, 2022 5:18:47 AM","subDeviceList":null,"extension":null,"deviceProp":null}]

(prettified)

[
  {
    "deviceRegion": "US",
    "isOwner": true,
    "authKey": null,
    "deviceName": "Humidifier",
    "deviceImg": "https://image.vesync.com/defaultImages/deviceDefaultImages/wfon_ahm_luh-d301s-wusr_us_240.png",
    "cid": [This might be customer ID?? Seems sus. Redacted for safety],
    "deviceStatus": "on",
    "connectionStatus": "online",
    "connectionType": "WiFi+BTOnboarding+BTNotify",
    "deviceType": "LUH-D301S-WUSR",
    "type": "wifi-air",
    "uuid": "0a0426e1-f845-49c6-a9ea-75fb95c99482 [I generated this randomly to replace the real one]",
    "configModule": "WFON_AHM_LUH-D301S-WUSR_US",
    "macID": "MA:CM:AC:MA:CM:AC [this is a faked MAC]",
    "mode": null,
    "speed": null,
    "currentFirmVersion": null,
    "subDeviceNo": null,
    "subDeviceType": null,
    "deviceFirstSetupTime": "Dec 30, 2022 5:18:47 AM",
    "subDeviceList": null,
    "extension": null,
    "deviceProp": null
  }
]
danfratamico commented 1 year ago

@pschroeder89 I enabled Homebridge debug mode and also deleted the accessory from the cache, but I did not see any lines in the log that listed my humidifier model. I also don't see a way to add debug mode just to your plugin. Am I missing something?

Edit: Just checked the model on the unit itself and mine is LUH-D301S-WUSR, so it looks like I may be having the same issue as @rockerest. As stated above, I removed my humidifier from the cache so that most likely is not the issue.

pschroeder89 commented 1 year ago

Thanks @danfratamico and @rockerest. I'll probably have to publish a debug version of the plugin for you guys to get some info for me.

Before I do that, I have some questions:

  1. Is the Night Light exposed in HomeKit as an accessory? a. If it is exposed, do you get the This plugin generated a warning from the characteristic 'Brightness' error when you attempt to change the brightness? b. If it's not exposed, is "night_light" set to true in your config?
  2. Do you see any other errors when debug mode is turned on for the plugin? You can find instructions on enabling debug mode here: https://github.com/pschroeder89/homebridge-levoit-humidifiers#enabling-debug-mode
  3. Does this model have a brightness level associated with the light (press the light button multiple times on the unit)? Or does it simply go On / Off? The other models have different brightness levels, but if this one does not, I'll need to add some logic to exclude that characteristic from the LUH-D301S-WUSR model.
danfratamico commented 1 year ago

Here are the answers to your questions:

  1. The Night Light slider is exposed in HomeKit, but as expected, turning it on does not turn on the light. The error message does not appear when I use the slider in the Home app, it seems to display in the logs every minute or so. The "night_light" setting is set to "true" in config.

  2. There are no errors, below is the full log of the plugin during a full restart of Homebridge. The error seems to trigger every time the plugin is getting device info:

[12/30/2022, 5:05:45 PM] [Levoit Humidifiers] [DEBUG]: [LOGIN] The authentication success [12/30/2022, 5:05:45 PM] [Levoit Humidifiers] Discovering devices... [12/30/2022, 5:05:45 PM] [Levoit Humidifiers] [DEBUG]: [GET DEVICES] Device List -> JSON: [{"deviceRegion":"US","isOwner":true,"authKey":null,"deviceName":"Bedroom Humidifier","deviceImg":"https://image.vesync.com/defaultImages/deviceDefaultImages/wfon_ahm_luh-d301s-wusr_us_240.png","cid":"*REMOVED*","deviceStatus":"off","connectionStatus":"online","connectionType":"WiFi+BTOnboarding+BTNotify","deviceType":"LUH-D301S-WUSR","type":"wifi-air","uuid":"*REMOVED*","configModule":"WFON_AHM_LUH-D301S-WUSR_US","macID":"*REMOVED*","mode":null,"speed":null,"currentFirmVersion":null,"subDeviceNo":null,"subDeviceType":null,"deviceFirstSetupTime":"Dec 28, 2022 4:15:06 AM","subDeviceList":null,"extension":null,"deviceProp":null}] [12/30/2022, 5:05:45 PM] [Levoit Humidifiers] [DEBUG]: [GET DEVICE INFO] Getting device info... [12/30/2022, 5:05:45 PM] [Levoit Humidifiers] Restoring existing accessory from cache: Bedroom Humidifier [12/30/2022, 5:05:46 PM] [homebridge-levoit-humidifiers] This plugin generated a warning from the characteristic 'Brightness': characteristic value expected valid finite number and received "undefined" (undefined). See https://homebridge.io/w/JtMGR for more info. [12/30/2022, 5:06:01 PM] [Levoit Humidifiers] [DEBUG]: [GET DEVICE INFO] Getting device info... [12/30/2022, 5:06:01 PM] [homebridge-levoit-humidifiers] This plugin generated a warning from the characteristic 'Brightness': characteristic value expected valid finite number and received "undefined" (undefined). See https://homebridge.io/w/JtMGR for more info.

  1. The humidifier night light button operates as follows when you tap on the button. The VeSync app lets you pick any color you want and allows you to adjust the dimmer:

Tap 1 - Auto color change mode Tap 2 - Purple light Tap 3 - Blue light Tap 4 - Light blue light Tap 5 - Cyan light Tap 6 - Yellow/orange light

pschroeder89 commented 1 year ago

Interesting, thanks for the info @danfratamico!

I actually just discovered that Levoit has locked down their app's SSL certificate, so I can no longer sniff the traffic from their app to their servers. This will make debugging and implementing this (and all future changes to this plugin) more difficult.

I have published version 1.8.4-debug, that will output a new [UPDATED INFO RESPONSE] log (you will not need to have debug mode enabled to see this log). It should look something like:

[UPDATED INFO RESPONSE]
{
  "traceId": "1672465495037",
  "code": 0,
  "msg": "request success",
  "module": null,
  "stacktrace": null,
  "result": {
    "traceId": "1672465495037",
    "code": 0,
    "result": {
      "enabled": false,
      "mist_virtual_level": 9,
      "mist_level": 3,
      "mode": "auto",
      "water_lacks": true,
      "water_tank_lifted": false,
      "humidity": 31,
      "humidity_high": false,
      "display": false,
      "automatic_stop_reach_target": false,
      "night_light_brightness": 0,
      "configuration": {
        "auto_target_humidity": 40,
        "display": true,
        "automatic_stop": true
      }
    }
  }
}

I'm expecting / hoping that your log will contain 2 new values in that response, maybe something like light_color and night_light (instead of night_light_brightness like on other models). I can then hopefully construct the correct API calls to control the light's color and power.

Thanks a lot for helping out on this!

danfratamico commented 1 year ago

Thanks for your work on this! I installed the latest version of the plugin and here is my response:

 {
   "traceId":"1672494584478",
   "code":0,
   "msg":"request success",
   "module":null,
   "stacktrace":null,
   "result":{
      "traceId":"1672494584478",
      "code":0,
      "result":{
         "enabled":true,
         "mist_virtual_level":1,
         "mist_level":1,
         "mode":"auto",
         "water_lacks":false,
         "water_tank_lifted":false,
         "humidity":35,
         "humidity_high":false,
         "display":true,
         "automatic_stop_reach_target":true,
         "configuration":{
            "auto_target_humidity":40,
            "display":true,
            "automatic_stop":true
         },
         "extension":{
            "schedule_count":0,
            "timer_remain":0
         },
         "rgbNightLight":{
            "action":"off",
            "colorMode":"marquee",
            "speed":0,
            "brightness":91,
            "red":255,
            "green":255,
            "blue":255,
            "colorSliderLocation":61
         }
      }
   }
}
rockerest commented 1 year ago
"rgbNightLight":{
   "action":"off",
   "colorMode":"marquee",
   "speed":0,
   "brightness":91,
   "red":255,
   "green":255,
   "blue":255,
   "colorSliderLocation":61
}

we got 'em, folks

pschroeder89 commented 1 year ago

1.8.4-debug2 has been pushed. I'd appreciate it if you both could test it out and let me know how things look.

There's a possibility that it won't work at all as this took a bit of guesswork and outdated info from other VeSync repos (and since I don't have this feature on my current models), but I am getting successful responses from VeSync when sending the current set of commands.

The current behaviors that should be supported:

  1. Turning the light on and off (not using the slider, but the lightbulb icon). Turning it on should go to 50% (check the slider to confirm, please).
  2. Turning the light on and off from the slider. Turning on from the slider will always go to 50%. Once it is on, you can adjust the brightness to any other %. That's the current behavior for the non-RGB night lights, too...it's more of a UI limitation in HomeKit than anything else.
  3. When turning on the lights, whatever color, colorMode, speed, and colorSliderLocation you had set in VeSync should be kept and respected by HomeKit. I attempted to just read and store these values from the initial get requests, and we just supply them when we turn the light on / off or change the brightness.

I did have some other questions too, to make sure my logic is ok:

  1. What different "actions" are there? Just on/off? There are some other vesync devices that appear to handle dim as an option as well, not sure if that applies here.
  2. What are the different color modes? If there are only a couple and people want it, we can probably make a few new switches for them.
  3. What does speed control, exactly? We could potentially add a slider in the future to change the speed.
  4. What does colorSliderLocation do?

Also, please test with debug mode turned on in the config. There should be logs for the Night Light Status request and response.

danfratamico commented 1 year ago

@pschroeder89 Sure, here is how it's working for me:

  1. The device in the Home app defaults to 50% brightness and the slider is half way. I don't see a on/off switch for the light, there is only a slider. To turn off the night light, I need to drag the slider to the bottom and that shuts it off.

  2. Adjusting the brightness does not work from the slider.

  3. From what I can test, it does respect the color chosen in VeSync. The other values, I am not sure about.

To try and answer your other questions, I'm hoping the attached image can help. This shows the settings we can configure for the night light in the VeSync app. I'm guessing the "colorSliderLocation" lets you pick any RGB color.

Here's a log entry that may help. Changing the brightness in the Home app does show as being changed in the logs and it does change in VeSync but the humidifier brightness does not change. It only respects the dimmer slider in the VeSync app:

[1/3/2023, 11:21:41 AM] [Levoit Humidifiers] Setting Night Light Status to {"action":"off","speed":0,"green":113,"blue":127,"red":1,"brightness":50,"colorMode":"color","colorSliderLocation":54}

IMG_1516

pschroeder89 commented 1 year ago

Thanks @danfratamico. To try to understand the brightness behavior a little more, I've published 1.8.4-debug3. This will output another log when getting the light info from VeSync. It should start with [GET LIGHT JSON].

Could you capture a GET log, then change (only) the Dimmer setting to another value in the VeSync app, then go back to Home and capture another GET log?

Also, for the on/off switch without the slider, you need to go to the Humidifier accessory in HomeKit (so all 5 or 6 accessories are showing), then scroll down to the Accessories item. You should then see the accessories in a smaller view, and you can tap the light to turn it on / off.

If all of this debugging is a lot for you and you'd be comfortable, you could add me as a Device User in the Share Device settings of the VeSync app (Paul.j.schroeder.29@gmail.com). Let me know if that's an option, that way I could debug on your device. If not, let's see what the logs look like and see if we can figure this out.

We also have a Discord channel for faster comms, if needed: https://discord.com/channels/432663330281226270/1055705874460594247

Thanks again for the help!

danfratamico commented 1 year ago

Thanks, I was able to find the accessories list. The night light button read 50% brightness and the light was off on the humidifier. I turned it on in Home and it did not turn on the humidifier light. It only turned on when I moved the slider. Here are the logs:

[1/3/2023, 7:59:32 PM] [Levoit Humidifiers] [GET LIGHT JSON] {"action":"on","speed":0,"green":154,"blue":173,"red":0,"brightness":50,"colorMode":"color","colorSliderLocation":54}
[1/3/2023, 7:59:38 PM] [Levoit Humidifiers] Setting Night Light Status to {"action":"on","speed":0,"green":154,"blue":173,"red":0,"brightness":75,"colorMode":"color","colorSliderLocation":54}

I also sent you an invitation for access to my device in VeSync. I would love to chat on Dkicord, but using your link displays a message "You don't have access to any text channels, or there are none on this server.".

pschroeder89 commented 1 year ago

Ah, try this discord link first: https://discord.com/invite/Z8jmyvb

danfratamico commented 1 year ago

Here are debug logs when I changed the brightness in the Home app:

[1/4/2023, 8:59:56 AM] [Levoit Humidifiers] [DEBUG]: [GET DEVICE INFO] Getting device info...

[1/4/2023, 8:59:56 AM] [Levoit Humidifiers] [DEBUG]: [DEVICE INFO] {"traceId":"*removed*","code":0,"msg":"request success","module":null,"stacktrace":null,"result":{"traceId":"*removed*","code":0,"result":{"enabled":true,"mist_virtual_level":1,"mist_level":1,"mode":"auto","water_lacks":false,"water_tank_lifted":false,"humidity":41,"humidity_high":false,"display":true,"automatic_stop_reach_target":true,"configuration":{"auto_target_humidity":40,"display":true,"automatic_stop":true},"extension":{"schedule_count":0,"timer_remain":0},"rgbNightLight":{"action":"off","colorMode":"color","speed":0,"brightness":50,"red":9,"green":255,"blue":115,"colorSliderLocation":42}}}}

[1/4/2023, 8:59:56 AM] [Levoit Humidifiers] [GET LIGHT JSON] {"action":"off","speed":0,"green":255,"blue":115,"red":9,"brightness":50,"colorMode":"color","colorSliderLocation":42}

[1/4/2023, 9:00:02 AM] [Levoit Humidifiers] Setting Night Light Status to {"action":"on","speed":0,"green":255,"blue":115,"red":9,"brightness":57,"colorMode":"color","colorSliderLocation":42}

[1/4/2023, 9:00:02 AM] [Levoit Humidifiers] [DEBUG]: [SEND COMMAND] Sending command setLightStatus to Bedroom Humidifier with ({"action":"on","speed":0,"green":255,"blue":115,"red":9,"brightness":57,"colorMode":"color","colorSliderLocation":42})...

[1/4/2023, 9:00:02 AM] [Levoit Humidifiers] Setting Night Light Status to {"action":"on","speed":0,"green":255,"blue":115,"red":9,"brightness":50,"colorMode":"color","colorSliderLocation":42}

[1/4/2023, 9:00:02 AM] [Levoit Humidifiers] [DEBUG]: [SEND COMMAND] Successfully sent command setLightStatus to Bedroom Humidifier with ({"action":"on","speed":0,"green":255,"blue":115,"red":9,"brightness":57,"colorMode":"color","colorSliderLocation":42})! Response: {"traceId":"*removed*","code":0,"msg":"request success","module":null,"stacktrace":null,"result":{"traceId":"*removed*","code":0}}

[1/4/2023, 9:00:02 AM] [Levoit Humidifiers] [DEBUG]: [SEND COMMAND] Sending command setLightStatus to Bedroom Humidifier with ({"action":"on","speed":0,"green":255,"blue":115,"red":9,"brightness":50,"colorMode":"color","colorSliderLocation":42})...

[1/4/2023, 9:00:03 AM] [Levoit Humidifiers] [DEBUG]: [SEND COMMAND] Successfully sent command setLightStatus to Bedroom Humidifier with ({"action":"on","speed":0,"green":255,"blue":115,"red":9,"brightness":50,"colorMode":"color","colorSliderLocation":42})! Response: {"traceId":"*removed*","code":0,"msg":"request success","module":null,"stacktrace":null,"result":{"traceId":"*removed*","code":0}}

[1/4/2023, 9:00:08 AM] [Levoit Humidifiers] Setting Night Light Status to {"action":"on","speed":0,"green":255,"blue":115,"red":9,"brightness":73,"colorMode":"color","colorSliderLocation":42}

[1/4/2023, 9:00:08 AM] [Levoit Humidifiers] [DEBUG]: [SEND COMMAND] Sending command setLightStatus to Bedroom Humidifier with ({"action":"on","speed":0,"green":255,"blue":115,"red":9,"brightness":73,"colorMode":"color","colorSliderLocation":42})...

[1/4/2023, 9:00:08 AM] [Levoit Humidifiers] [DEBUG]: [SEND COMMAND] Successfully sent command setLightStatus to Bedroom Humidifier with ({"action":"on","speed":0,"green":255,"blue":115,"red":9,"brightness":73,"colorMode":"color","colorSliderLocation":42})! Response: {"traceId":"*removed*","code":0,"msg":"request success","module":null,"stacktrace":null,"result":{"traceId":"*removed*","code":0}}
pschroeder89 commented 1 year ago

Update: Thanks to @danfratamico for letting me test and debug on his LUH-D301S-WUSR! 1.8.5 has been pushed and fixes brightness and on / off for the light on this model.

We do not support changing the color from the plugin (yet).

pschroeder89 commented 1 year ago

If new bugs are found against this feature, please raise them in a new ticket. Thanks!