diyhue / diyHue

Main diyHue software repo
https://diyhue.org/
Other
1.53k stars 276 forks source link

Milight Setup #32

Closed marcdo70 closed 5 years ago

marcdo70 commented 5 years ago

Hello how can I get the device ID of my Milight lights for input in milight setup?

mariusmotea commented 5 years ago

This is more a question to esp8266 milight hub repo. Anyway you choose this id random,can be also the one from the example 0x1234. After you set the id in milight hub web interface pair the light with the hub.

marcdo70 commented 5 years ago

Sorry I'm newbie, have an original milight hub on the run with 2 fut 038th wants to transfer this yes only in diyhue or pair. Wie muss ich genau vorgehen?

darxtorm commented 5 years ago

So, I have a working milight setup. Several other projects are able to detect my light groups and control them subsequently (example - https://github.com/KevinVR/milights-bridge ). I don't know anything about the device IDs described in diyhue's setup process tho. Is there a possibility that the milight setup process could be better documented, since I am unable to get any action out of this project with my configured milights? happy to test and document but honestly stuck at the first step

GitHub
KevinVR/milights-bridge
An application for controlling your Milight lights using any device. Provides GUI and API. - KevinVR/milights-bridge
mariusmotea commented 5 years ago

But you created the circuit from the wiki? This don't work with original milight hub.

marcdo70 commented 5 years ago

So, I have installed your diy-hue software on a Pi Zero and wanted to control my milight Stripe, which is controlled by an original milight Wifi box, in the diy-hue software to control it via hue app. and that does not work? or what do you mean?

mariusmotea commented 5 years ago

You need to build the project esp8266 milight hub specified in the wiki. Is not working with original milight box because so far nobody added support for it.

darxtorm commented 5 years ago

So it doesn't really support milight then, it supports sepcific aftermarket hardware? Can we get milight support added to the To-Do list? I'm happy to try my hand at coding it up, since it's just UDP calls

mariusmotea commented 5 years ago

Is not something you can buy is something you can create with $10 components. Support for original milight bridge is welcomed, it was already requested in the past but so far nobody with python skills and a milight box implement it.

ghost commented 5 years ago

Added to the suggested enhancements project board. You can find out about the ESP8266 MiLight hub here

jespertheend commented 4 years ago

So I wanted to have a try at adding support for the MiLight hub, even though I knew it was probably going to be way more difficult than I'd hope it would be. I've gotten pretty far though. I dug around in the diyhue code for a bit to see how to add new lights and that shouldn't be too complicated. The biggest issue would be figuring out what data to send to the milight hub.

I managed to get a good setup for inspecting what UDP messages are being sent from the iOS app to the MiLight hub. But of course it's all in binary, the protocol is undocumented, and I don't see any information on the internet about the protocol.

I can see what port my phone connects to, and the messages it's sending in hex, but the port seems to be changing when I restart the app, and also I can't make any sense of the hex I'm looking at. The message length doesn't seem to match with the hex data, though I think it might not be showing the headers or something?

If anyone wants to collaborate I'm up for it but I think I'll just try to build the ESP8266 hub lol.

darxtorm commented 4 years ago

I managed to get a good setup for inspecting what UDP messages are being sent from the iOS app to the MiLight hub. But of course it's all in binary, the protocol is undocumented, and I don't see any information on the internet about the protocol.

The protocol is the same as LimitlessLED, i think quite a few hackers have documented their discoveries around interacting with it: https://blog.christophermullins.com/2017/03/18/reverse-engineering-the-new-milightlimitlessled-2-4-ghz-protocol/ https://github.com/home-assistant/home-assistant/issues/4676

Reverse engineering the new Milight/LimitlessLED 2.4 GHz Protocol | Chris Mullins
jespertheend commented 4 years ago

Oh cool, that might come in handy, thanks! I managed to decompile the MiLight apk and I think this might just work. Though they have two bytes that contain a password of some sort, that might become tricky to get out of the app.

jespertheend commented 4 years ago

It seems like the article you linked only talks about the wireless protocol between the hub/remote and the bulbs, not between the app and the hub. The stuff they have to deal with seems super complicated though. I don’t think I’d be able to figure all of that stuff out. Luckily the protocol between the app and hub seems a lot easier. I’ll try some stuff out tomorrow and see if I can actually manage to control the lights from python.

jespertheend commented 4 years ago

It seems like domoticz has implemented support for communicating with the WiFi iBox Controller. This source code does a good job at showing how the protocol works. I'm pretty close, I just need to get a way to receive the session id of the iBox and then send that with every command.

jespertheend commented 4 years ago

Alright I got it working, I can now turn on and off my light with a simple python script.

import socket

UDP_IP = "192.168.2.8"
UDP_PORT = 5987
MAIN_MESSAGE = b'\x80\x00\x00\x00\x11\xb8\x00\x00\x01\x00\x31\x00\x00\x08\x04\x01\x00\x00\x00\x01\x00\x3f' #turn on
# MAIN_MESSAGE = b'\x80\x00\x00\x00\x11\xb8\x00\x00\x01\x00\x31\x00\x00\x08\x04\x02\x00\x00\x00\x01\x00\x40' #turn off
MSG_GET_SESSION_ID = b'\x20\x00\x00\x00\x16\x02\x62\x3A\xD5\xED\xA3\x01\xAE\x08\x2D\x46\x61\x41\xA7\xF6\xDC\xAF\xD3\xE6\x00\x00\x1E' #get session id

sessionId1 = 0
sessionId2 = 0

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

def sendMsg(msg):
    sock.sendto(msg, (UDP_IP, UDP_PORT))

sendMsg(MSG_GET_SESSION_ID)
totalTries = 0
while totalTries < 3:
    totalTries+=1
    data, addr = sock.recvfrom(1024)
    if len(data) == 22:
        sessionId1 = data[19]
        sessionId2 = data[20]
        break

message = bytearray(MAIN_MESSAGE)
message[5] = sessionId1
message[6] = sessionId2
sendMsg(bytes(message))

So now all that's left to do is add support for multiple messages and integrate it into diyHue. I'm thinking it might be best to create a separate project for this with it's own rest service and configuration and everything. I'm not too familiar with the diyHue codebase and that way if I mess up somewhere, diyHue will still be working fine for other devices. We'll be able to connect diyHue to this rest service so you can still controll the lights from hue.

If anyone has any feedback on this idea feel free to let me know!

mariusmotea commented 4 years ago

@jespertheend with diyhue you can create a new protocol file with one file in location https://github.com/diyhue/diyHue/tree/master/BridgeEmulator/protocols. Just follow the same design like yeelight of native lights.

GitHub
diyhue/diyHue
Main diyHue software repo. Contribute to diyhue/diyHue development by creating an account on GitHub.
jespertheend commented 4 years ago

thanks @mariusmotea I just realized diyHue already has support for the domoticz protocol built in. And since domoticz has support for the MiLight WiFi iBox Controller, I can connect the hue app to the migh lights that way. If only I had know this sooner hahah. I almost got it working now, the hue app shows my light and I can change it's brightness and on/off state, no color yet though.

jespertheend commented 4 years ago

I added support for color changing with the domoticz protocol, so you can use the MiLight hub with diyHue #162

jespertheend commented 4 years ago

Alright it turned out domoticz is super broken with the MiLight hub, and also domoticz is not fast at all on my raspberry pi, hue entertainment wasn't working very well for instance. So I just added the MiLight hub protocol to diyHue (#163). It's actually working much better now. The saturation is now working and hue entertainment is working much better as well.

david-strauss-privoro commented 2 years ago

Hi @jespertheend I'm back again with more questions haha.

I was able to add my Mi-Lights to diyhue via the domoticz protocol, but something must not be correct in my config for the lights, as my hue apps cannot change their colors, only brightness and on/off state.

Do you possibly have a sample config you can share with the correct setup for these? TIA

Edit to add my setup: image

image

jespertheend commented 2 years ago

I don't use diyHue anymore myself so I don't have a config example unfortunately. It seems like you have configured it correctly. Are you able to toggle the lights from the Milight app? I only tested rgbww lights so it could be that your hardware is not supported. I believe there are also different types of Milight hubs. That could also be it.

david-strauss-privoro commented 2 years ago

@jespertheend thanks a bunch for the response. I am able to toggle the lights via the Mi-Light app as well as the homebridge-milight plugin. I'm thinking it must be the light type I'm messing up. You wouldn't happen to know where I could find a listing of all accepted light types? I know of RGB/RGBW/RGBWW but isn't there also RGB-CCT and a few others? Anyway, thanks again I really appreciate your work here.

jespertheend commented 2 years ago

Judging from the changes in #163 there's rgbww rgbw and rgb. I'm not sure about cct, I don't think the Milight protocol supports it.

david-strauss-privoro commented 2 years ago

After looking at the python code (which I probably should've done prior to even coming to ask this question) it seems I may have to play with a combination of color mode and light type to see which is the right combo for my setup. If I figure it out I may leave another comment for any future wayward Mi-Lighters. Thanks again!

jespertheend commented 2 years ago

I've seen other Milight implementations online that I think might be much more complete than what I did. So it could very well be that my implementation might simply be sending the incorrect commands for lights other than rgbww.