steve228uk / homebridge-magichome

A Homebridge plugin for Magic Wifi devices
MIT License
82 stars 47 forks source link

LEDENET UFO #6

Open ckreed opened 7 years ago

ckreed commented 7 years ago

I can cycle power on the strip, but I cannot control brightness or color(s). This uses the MagicHome app just fine, but homebridge only controls the power on/off.

Here is what I have: https://www.amazon.com/LEDENET-Controller-Android-Smartphone-Control/dp/B00MDKOSN0/ref=redir_mobile_desktop?_encoding=UTF8&keywords=ledenet%20ufo&pi=SY200QL40&qid=1482177267&ref=mp_s_a_1_1&sr=8-1

steve228uk commented 7 years ago

Thanks @ckreed. Guessing you've tried the various configs? I'm gonna buy one of these next week and see if I can figure it out.

ckreed commented 7 years ago

Yes, I tried RGB, RGBW (which is what this is supposed to be) and RGBWW. I also tried those in combination with the purewhite setting. After posting this I found a ruby gem ledenet-ufo that I can run via command line that works perfectly. But I lack the skill in integrating something like this as a homebridge plugin. It might help you identify the differences. Thanks much!!

https://github.com/sidoh/ledenet_api

steve228uk commented 7 years ago

@ckreed That link doesn't seem to be working. If you can send it over I'll have a look to see what's different.

ckreed commented 7 years ago

So strange - clicking the link results in a 404, copy/paste into browser will take you there. I am obviously comment challenged some how (I cannot get the link to paste properly here). Just put that address in your browser and it should work. Sorry.

ghost commented 7 years ago

Hey first of all thanks for the great module! I also have the Magic Home Ufo. The on/off function is working great, but I have the same problem like steve. Is there already a solution? Thanks!

steve228uk commented 7 years ago

@ckreed @HangJezz Okay, this is the file that's doing the work:

https://github.com/sidoh/ledenet_api/blob/b6f0c5cba03c535cdc877ac2f9787e88763d16be/lib/ledenet/packets/update_color_request.rb#L10-L20

This is what my plugin is currently doing

https://github.com/steve228uk/homebridge-magichome/blob/master/flux_led.py#L576-L590

It looks like RGBWW is the correct pattern to use on this.

Are you able to try the flux_led.py script from this plugin via the command line and see if setting that as RGBWW works?

steve228uk commented 7 years ago

It looks like @tmarcus02 has created a fork with multiple RGBWW options.

https://github.com/tmarcus02/homebridge-magichome/commit/3240b5e534796a4a9b471705b31084b4022d611b

Perhaps they can weigh in as to whether they got the UFO to work? I'd be more than happy to merge a PR if so 😊

ghost commented 7 years ago

I will try that tomorrow.. Thanks for your fast answer! I am sure to get the UFO working xD

ckreed commented 7 years ago

I tried the flux_led.py before posting here. It can discover and turn on and off, but I cannot control the color or brightness of the warm white. One thing I noticed is that if I use the constant Red or "#FF0000" with the -c parameter I get an error of bad color specification. Using 255,0,0 notation is accepted without an error but nothing happens. The Ruby Gem that I mentioned earlier works perfectly. Hope that helps!

ckreed commented 7 years ago

Here is a screen shot of the command line.

screen shot 2017-02-01 at 1 54 08 pm

and the errors on the color

screen shot 2017-02-01 at 1 56 10 pm

tmarcus02 commented 7 years ago

The fork I created was to add in support for the following controllers which I am using.

For the controller XCSOURCE® Magic UFO WiFi LED Controller specify RGBWWv3 in the homebridge config file i.e. "setup": "RGBWWv3"

For the controller Sunix® Wireless WiFi RGB/RGBWWCW LED Strip Light Controller specify RGBWWv1 in the homebridge config file i.e. "setup": "RGBWWv1"

tmarcus02 commented 7 years ago

If these options don't work for your controller you need to do a packet capture when using the Magic Home app to change the colour. This will help identify how the data in the packet being sent to the controller is formatted.

If you have a iPhone and a Mac, you can follow these instructions:-

  1. Connect your iOS device to your Mac via USB.

  2. Get the UDID for the connected device from iTunes or organiser.

  3. Open terminal in your Mac

  4. type the following commands in the terminal

$ ifconfig -l// First get the current list of interfaces.

$ rvictl -s <udid> // Then run the tool with the UDID of the device.

// This adds a new virtual network interface rvi0.

$ ifconfig -l// Get the list of interfaces again, and you can see the new virtual network interface, rvi0, added by the previous command.

  1. Open Wireshark and run a capture on the rvi0 interface. Should look like this on the capture:-

wireshark2

  1. To remove the virtual interface, type the following command in the terminal

$ rvictl -x <udid>

ghost commented 7 years ago

Yes I also have the XCSOURCE UFO. Are there differences between this Ufos? There are a lot of Ufos on the market. I tought they all have the same hard- and software. 🙈

steve228uk commented 7 years ago

@tmarcus02 Thanks for confirming. I have that second device but haven't tried RGBWW with it yet. Are you cool with submitting a PR for your changes? If not I'm happy to add them manually.

tmarcus02 commented 7 years ago

@HangJezz - I don't know if they are all the same hardware and software, when using the Magic Home App it identifies the type of the controller and the version, So I don't know if there is a Magic UFO available which are other versions - mine is v3

img_0063

tmarcus02 commented 7 years ago

@steve228uk - I haven't tested yet using a RGBWW strip, I am just running RGB on both of my controllers. I test it out to confirm there is no further changes required for these type of controllers

ckreed commented 7 years ago

Well crap. Even with @tmarcus02 version (and the RGBWWv3 setup) mine still doesn't work. I have setup wireshark and can see the data. Here is what I got when setting the color to R=131,G=92,B=87. Not sure if this helps.

screen shot 2017-02-02 at 6 40 09 am

tmarcus02 commented 7 years ago

@ckreed - Looking at the data 3183515100000f6531835c5700000f76, the Magic App will send larger packets when you slide you finger around the colour wheel, A single colour change the data is 8 byte in length.

So going by the RGB colour you selected the data is made up like this 31835c5700000f76

31 - persist=True 83 - R= 131 5c - G= 92 57 - B = 87

00000f - matches the RGBWW padding, so setting "setup": "RGBWW" in the home bridge config file should work for your controller.

ckreed commented 7 years ago

@tmarcus02 MagicHome app shows v3. I tried RGBWW, RGBWWv2, RGBWWv3. shrug Not sure what is up. Still only turns on and off. No brightness or colors. The Ruby Gem ledent-ufo version (command line) works fine. The flux_led.py version (command line) does not. I appreciate everyone's help in looking at this. I guess it will be easier to just go buy one that has been tested. :-(

ghost commented 7 years ago

So I have 3 UFOS at home and all have the version v3. So now I have to edit the flux_led.py and the config to RGBWWv3? What are the Commands for testing the flux thing in command line?

ckreed commented 7 years ago

@HangJezz screen shot 2017-02-02 at 9 15 46 am

ghost commented 7 years ago

ahh ok thanks!

ghost commented 7 years ago

Ok now I have the same problem. I can set the stripe on and off, set the color, only warm white is not working. I am using the modified script and RGBWWv3

steve228uk commented 7 years ago

@ckreed Does the colour wheel show at all in home.app?

ghost commented 7 years ago

Every time I send a color, the color is working, but warm white turns always to 100%. Funny Bug : /

tmarcus02 commented 7 years ago

@ckreed - When using the command line to execute the Flux_led.py script, are you stating the options like the following, I have tested the Flux_led.py this way and it is working ok

untitled

ckreed commented 7 years ago

@steve228uk Yes, I can pull up the brightness slider and the color wheel (when editing the pre-selects), but I can only turn on/off the strip. No color changes, no warm white changes, no brightness changes on either (RGB or WW). Behaves just like the flux_led.py script. Another note, upon startup of homebridge, it looks like it goes out and gets the status of the strip. It figures out that the strip is on/off, but it always returns (255,100,50) as the current color, which is not correct.

ckreed commented 7 years ago

screen shot 2017-02-02 at 10 31 01 am @tmarcus02 Yes, that is how I have tried the command. Here is a screenshot issuing a color change. It executes with no errors but nothing happens. Then I immediately check the color and you can see it never set the color. So the -info works, but making any change (other than on/off) does not work.

screen shot 2017-02-02 at 10 26 06 am

tmarcus02 commented 7 years ago

@HangJezz - Glad to see the colour change is now working, I have not been using RGBWW just RGB so the modification I made was to just get the colour change working quickly via homekit for my controllers

I have today connected a white strip up to the Magic UFO controller and I'm getting the same results you are getting. So I'm looking into it and will update.

ghost commented 7 years ago

@tmarcus02 Thank you very much! If there is anything I can doo to help just say it!

tmarcus02 commented 7 years ago

Apologies @ckreed my mistake your padding is different 00000f - RGBWW is 0000f0.

I'll modify the code and add in the option RGBWWv3a

tmarcus02 commented 7 years ago

Ok updated Flux_led.py, try it again and set the setup option to RGBWWv3a

ghost commented 7 years ago

Where can I get it?

ghost commented 7 years ago

Ok I found it... Sry I am new on github xD

ghost commented 7 years ago

So the color is working great now, but the brightness of warm white does not work or is this my mistake? This is my Command: python flux_led.py 192.168.178.49 -x RGBWWv3a -w 20

ckreed commented 7 years ago

@tmarcus02 @HangJezz Confirmed flux_led.py color now works also on/off! Warm white does not work with flux_led.py. Also the home.app is completely broke. Cannot turn on/off, cannot color change, cannot warm white change.

tmarcus02 commented 7 years ago

Sry @HangJezz I was talking about the problem @ckreed was having with his controller which seems to be different and wasn't able to change the colour yet, So I added the option RGBWWv3a for his controller.

I'm still thinking about the Warm white option and how to handle it, as it is setting white to 100% when setting the colour.

The way I am think about it is if you were selecting white as the colour you would want the white LEDs to illuminate not at 100% but at the same brightness level as the RGB LEDs. Also when selecting a colour you would not want the white LEDs to illuminate.

@steve228uk can you confirm what way the other controllers work via homebridge-magichome when using RGBWW. I have attached screenshots of the homekit controls for magichome plugin but there doesn't seem to be a control to adjust the warm white brightness in the same way there is in the Magic Home app

img_0064 img_0066 img_0067

img_0068

tmarcus02 commented 7 years ago

@ckreed You may need to remove the old homebridge-magichome plugin if it is not working via homekit

Step 1 sudo npm uninstall -g homebridge-magichome

Step 2 sudo npm install -g tmarcus02/homebridge-magichome

Once the warm white bugs are sorted I'll submit a PR so @steve228uk can approve the changes and then the install directory would return to homebridge-magichome using the command sudo npm install -g homebridge-magichome

ghost commented 7 years ago

I am very happy, that the colors and the brightness are working now. I can control my LED-Strips with Siri now xD. I would say the only option with homekit is to use the the normal white, but I am not a expert... Finallay thanks for the fast answers and the good work!

ckreed commented 7 years ago

@tmarcus02 That did it! Very nice. Appreciate it. I would think that there is some homekit interfaces that now support the warm white. Probably just have to figure out how to publish that feature to homekit for discovery. Thank you very much for all the effort. I even learned a few things. :-)

steve228uk commented 7 years ago

@tmarcus02 Currently the light temperature isn't controllable at all. The temperature dial returns a mix of HSL just like the colour dial and that's what's converted into temperature by other bulbs such as Philips Hue.

You can see here that if the purewhite option is set to true and the saturation and hue are 0 (the middle of the colour wheel) then it will send the warm white option

https://github.com/steve228uk/homebridge-magichome/blob/master/index.js#L114-L117

We could potentially set a range based on what's sent from the temperature wheel to set either warm white or cool white based on the config and the temperature selected.

ghost commented 7 years ago

@tmarcus02 Sadly your fix doesn't work for me. Can't controll anything via the app. If I try to run the script this message appears:

sudo python /usr/lib/node_modules/homebridge-magichome/flux_led.py 192.168.2.104 -x RGBWWv1 -w 20
  File "/usr/lib/node_modules/homebridge-magichome/flux_led.py", line 604
    def setRgb(self, r,g,b, persist=True, setup="RGBW"):
                                                       ^
IndentationError: unindent does not match any outer indentation level

I got this version: https://www.amazon.de/gp/product/B01J5A5YYM/ref=oh_aui_detailpage_o00_s01?ie=UTF8&psc=1

ckreed commented 7 years ago

@whitechapplin Hmmmm, that is a python error. You might try to download or reload again? The script is not running due to spaces or tabs. I did not see anything similar when I ran the script (though I am not a python expert).

ckreed commented 7 years ago

@steve228uk @tmarcus02 Just an FYI - one package I had to add to my python environment was webcolors (I used pip to install). After I did that all complaints about colors not defined went away. Not sure if that can be packaged in or if just a note should be added saying if you want to use "Red" or color names you must have the webcolors package installed.

tmarcus02 commented 7 years ago

I made some changes last night around 00:00 to 01:30, these were to fix white control on RGBWW & RGBW led strips and I created a new branch to test them.

The Magic UFO now has the setup options of RGBW, RGBWv3 & RGBWv3a.

I tested the changes which were working, so merged the branch into the master but it seems to have messed things up as when I installed the new version on my server it loaded into home bridge ok but no features are working i.e. on/off, change colour, etc.. and I wasn't getting any errors on the homebridge console.

It isn't even getting the status of the Controllers via homebridge, I revert the changes but I'm still having the same problem, I'm update my Server currently so going to retest again this morning.

ghost commented 7 years ago

@tmarcus02 Seems like your newest fixes doesn't work :(

tmarcus02 commented 7 years ago

Ok I'm still having problems but I think its to do with Homebridge.

I have removed the fix for white control on RGBWW & RGBW strips, The changes were made on the scripts flux_led.py and index.js. I have reset any changes to index.js by replacing it with a unmodified version.

The setup options for the Magic UFO controller are still in place these are RGBW, RGBWv3 & RGBWv3a I have tested the flux_led.py script and it is working correctly.

I can't test via homekit currently, the latest is I can't add Homebridge to the Home.app even after removing the homebridge-magichome plugin.

ghost commented 7 years ago

@tmarcus02 The script is working correctly for me right now. But sadly there is still no response via homekit

tmarcus02 commented 7 years ago

Updates @whitechapplin @ckreed @HangJezz

Was able to get Homebridge working again with the Home app, Details were on the homebridge homepage to do this.

Two reasons why Homebridge may not be discoverable:

  1. Homebridge server thinks it's been paired with, but iOS thinks otherwise. Fix: deleted persist/ directory which is next to your config.json.
  2. iOS device has gotten your Homebridge username (looks like a MAC address) "stuck" somehow, where it's in the database but inactive. Fix: change your username in the "bridge" section of config.json to be some new

I have been able to sort out the main issue with been unable to control (on/off, change colour, etc) from the Home app. For some reason I had to declare "python" to execute the flux_led.py from index.js which wasn't necessary before.

MagicHomeAccessory.prototype.sendCommand = function(command, callback)
{
    var exec = require('child_process').exec;
    var cmd = "python " +  __dirname + '/flux_led.py ' + this.ip + ' ' + command;

White control is work currently via the way @steve228uk detailed before and I think it would be better if the temperature control adjusted white between warm and cool and the brightness control could dim white LEDs in this case.

You can see here that if the purewhite option is set to true and the saturation and hue are 0 (the middle of the colour wheel) then it will send the warm white option

https://github.com/steve228uk/homebridge-magichome/blob/master/index.js#L114-L117

We could potentially set a range based on what's sent from the temperature wheel to set either warm white or cool white based on the config and the temperature selected.

The controllers setup options are RGBW, RGBWv3, RGBWW & RGBWWv1

ckreed commented 7 years ago

@tmarcus02 So did we drop the v3a that was working for the UFO? It no longer works as the previous version did with the RGBWWv3a setting.

Also, I can confirm that the FLUX WiFI Smart LED Light does work with the RGBW setting.