AMoo-Miki / homebridge-tuya-lan

Homebridge plugin for IoT devices that use Tuya Smart's platform
MIT License
204 stars 52 forks source link

Device Add Request #34

Closed tjenvy closed 5 years ago

tjenvy commented 5 years ago

Request to add ability to adjust light kelvin rating. This light is a tunable white bulb. I tried the RGB code in there and home bridge crashed with a ton of errors. It works with simple bulb, but having the tuning of white would be awesome!!!

IOTTON Wi-Fi Smart Bulb LED

Ready to handle bedroom light with signature {"1":false,"2":255,"3":255}

https://smile.amazon.com/gp/product/B07JZ4BVHL/ref=ppx_yo_dt_b_asin_title_o00_s00?ie=UTF8&psc=1

tjenvy commented 5 years ago

When using the RGB code for this device, the output is:

[3/28/2019, 6:08:51 PM] [TuyaLan] Ready to handle bedroom light with signature {"1":false,"2":255,"3":255} HAP Warning: Characteristic 00000008-0000-1000-8000-0026BB765291 not in required or optional characteristics for service 00000043-0000-1000-8000-0026BB765291. Adding anyway. /Users/tjenvy/.npm-global/lib/node_modules/homebridge-tuya-lan/lib/BaseAccessory.js:122 const [, h, s, b] = value.match(/^.{6}([0-9a-f]{4})([0-9a-f]{2})([0-9a-f]{2})$/i) || [0, 255, 255]; ^

TypeError: Cannot read property 'match' of undefined at RGBTWLightAccessory.convertColorFromTuyaToHomeKit (/Users/tjenvy/.npm-global/lib/node_modules/homebridge-tuya-lan/lib/BaseAccessory.js:122:35) at RGBTWLightAccessory._registerCharacteristics (/Users/tjenvy/.npm-global/lib/node_modules/homebridge-tuya-lan/lib/RGBTWLightAccessory.js:31:106) at TuyaAccessory.BaseAccessory.device.once (/Users/tjenvy/.npm-global/lib/node_modules/homebridge-tuya-lan/lib/BaseAccessory.js:22:18) at Object.onceWrapper (events.js:285:20) at TuyaAccessory.emit (events.js:197:13) at TuyaAccessory._change (/Users/tjenvy/.npm-global/lib/node_modules/homebridge-tuya-lan/lib/TuyaAccessory.js:240:18) at TuyaAccessory._msgHandler (/Users/tjenvy/.npm-global/lib/node_modules/homebridge-tuya-lan/lib/TuyaAccessory.js:176:26) at /Users/tjenvy/.npm-global/lib/node_modules/homebridge-tuya-lan/node_modules/async/dist/async.js:4096:9 at Object.process (/Users/tjenvy/.npm-global/lib/node_modules/homebridge-tuya-lan/node_modules/async/dist/async.js:2344:17) at /Users/tjenvy/.npm-global/lib/node_modules/homebridge-tuya-lan/node_modules/async/dist/async.js:2252:19

AMoo-Miki commented 5 years ago

Your bulb is very different. the RGBTWLight will not work for it. I presume 2 and 3 are for brightness and white temperature. It would be great if you could figure which one is which and what they temperature values stand for.

Disconnect your phone from the home WiFi. Define the device as a SimpleLight and open the logs. Try changing the brightness in the Tuya app and monitor the logs to see what changes and what the values are; I guess 0 is fully dimmed and 255 is fully lit. Then try changing the white temperature in the Tuya app and see which key changes and what values in the logs correspond to what values in the Tuya app.

If the Tuya app is connected to the home WiFi, it wouldn't allow the plugin to interact with the device and that's why we need to make sure Tuya talks to the device via the cloud.

Best of luck.

tjenvy commented 5 years ago

-turn off [TuyaAccessory] SimpleLight changed: {"1":false,"2":255,"3":255} -turn on [TuyaAccessory] SimpleLight changed: {"1":true,"2":255,"3":255} -brightness 0 [TuyaAccessory] SimpleLight changed: {"1":true,"2":25,"3":255} -brightness 100 [TuyaAccessory] SimpleLight changed: {"1":true,"2":255,"3":255} -color warm [TuyaAccessory] SimpleLight changed: {"1":true,"2":255,"3":0} -color cool [TuyaAccessory] SimpleLight changed: {"1":true,"2":255,"3":255}

So your assumption was right.

1 is on/off

  1. is brightness
  2. is color temp from 2700-5000K
AMoo-Miki commented 5 years ago

Awesome. I will start on it right away.

tjenvy commented 5 years ago

Awesome. Thanks for the great work! I appreciate it as do others I’m sure. I’m great at hardware, but wish I was much better at software to do this stuff.

AMoo-Miki commented 5 years ago

Change your config to use TWLight as the type and you should be good to go. Here is my sample config:

{
  "name": "Bedroom Light",
  "type": "TWLight",
  "manufacturer": "Iotton",
  "model": "Smart Light Bulb",
  "id": "...",
  "key": "..."
}

Lemme know if you have any problems, or otherwise.

PS: Software is easy; you just need to find the easiest one to start with. I propose JavaScript over others.

tjenvy commented 5 years ago

SWEET, that worked!! Thank you so very much!!

nicklayb commented 5 years ago

I used a Globel tunable white buld which has a smiliar signature {"1":false,"3":255,"4":255}. I impletemented it on my fork by adding getBrightnessIdentifier and getColorTemperatureIdentifier and extended the TWLight class to override those methods. I would love to open a PR if you're interested https://github.com/nicklayb/homebridge-tuya-lan

AMoo-Miki commented 5 years ago

@nicklayb Thanks. PRs are always welcome. I made these field ids configurable in the latest commit.