Page 1 of 1

Mi-light UDP Trigger

Posted: Thu Apr 24, 2014 9:10 pm
by skeltonmfc
Hi I'm hoping that someone could point me in the right direction. I'm trying to control some wifi controlled LED RGB bulbs made by Milight (cheap version of philips hue) the protocol is at this web address (http://www.limitlessled.com/dev/) if i use a packet sender to send the code 0x41 0x00 0x55 to 192.168.1.68 (milight wifi bridge address on my lan) on port 8899 i can control my lighting.

how do i go about using even ghost to control i have tried adding the plugin broadcast with the following settings

Broadcast zone: 192.168.1.68
port:8899
listen address: already set to my pc ip address
listen to self broadcast: unticked
payload: blank

then i added an action broadcast:

command: 0x41 0x00 0x55
port: 8899

but this doesn't seem to control my lighting can anyone advise what might be wrong or if there is another way to control them using any other plugins

Re: Mi-light UDP Trigger

Posted: Mon Dec 01, 2014 9:16 pm
by iotarho
Hi, hoping now that these lights (milights, limitless led lights, easy bulbs, etc.) are becoming a little cheaper and more widely available there will be some interest. I followed this same path of trying to figure out how to format EventGhost's UDP broadcaster.

It seems the UDP string that gets broadcast (the so-called 'Payload') by UDP broadcaster needs to be in ASCII format, not the hex codes that are pretty easy to find for these bulbs. The problem is that the '00' that is the second hex code transmitted in all the milight commands doesn't have an ASCII symbol that lends itself to copy/pasting into the Payload box. Some codes seem to be alright just omitting the middle digit, for instance:

turn lights off ---(hex code)---> 41 00 55 -----(ascii code)----> AU

Entering AU as the Payload on my broadcaster (which goes to my milight wifi box IP address, port 8899) indeed allows EventGhost to turn all the lights off. But the 42 00 55 hex code to turn the lights back on doesn't work. The "easy solution"--would be for someone with a little Python to incorporate a hex-to-ascii translator function in the UDP broadcaster plugin's python code. I've looked at this once but so far I'm out of my element!

Re: Mi-light UDP Trigger

Posted: Mon Dec 01, 2014 9:26 pm
by iotarho
Also, maybe helpful to post the kluge I'm using to use EventGhost to control my milights. I borrowed a bit of the milight php code from the web and stuck it in a file called milight2.php on my local NAS box. This has a built-in function for converting the milight hex string to binary strings that the milight wifi box then responds to. I'll paste the code below.

So basically if I go to my webbrowser and type in "http://MYIPADDRESS/milight2.php?method=on", it sends the appropriate code to the milight box's IP address, port 8899.

For EventGhost, you can then use the "Python Command" action item and trigger the php script by doing a one-line python command:
import urllib; urllib.urlopen("http://MYIPADDRESS/milight2.php?method=on")

Not the prettiest solution, but seems to work in the absence of someone with better scripting skills! If anyone builds on these, please do share (I've only put some of the more useful milight commands in this php code). Moreover, if someone updates EventGhost's UDP broadcaster plugin to be able to convert the published milight hex commands into an ascii payload, I think that would solve this and be a much more elegant solution!

<?php
$do = $_GET['method'];
$val = $_GET['value'];
// Usage: localhost/milight2.php?method=(ON OFF ETC.)&value=

function hex2bin( $str ) {
$sbin = "";
$len = strlen( $str );
for ( $i = 0; $i < $len; $i += 2 ) {
$sbin .= pack( "H*", substr( $str, $i, 2 ) );
}

return $sbin;
}

function updateBulbs($string)
{
$ip = "MILIGHT WIFI BOX IP";
$port = 8899;
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_set_option($sock, SOL_SOCKET, SO_BROADCAST, 1);
socket_sendto($sock, $string, 6, 0, $ip, $port);
socket_close($sock);
}

$HD = dechex($val);
$HD_pad = \sprintf("%02s", $HD);
$HD_bin=hex2bin($HD_pad);
echo 'doing '.$do.' value '.$val.' hex '.$HD.'('.$HD_pad.') ' . $HD_bin . ' ' . $sbin;

switch($do)
{
case 'on':
updateBulbs(hex2bin("420055"));
break;
case 'off':
updateBulbs(hex2bin("410055"));
break;
case 'white':
updateBulbs(hex2bin("420055"));
updateBulbs(hex2bin("C20055"));
break;
case 'color':
$string='40'.$HD_pad.'55';
updateBulbs(hex2bin("$string"));
break;
case 'disco':
updateBulbs(hex2bin("400055"));
break;
case 'brightness':
if($val>27) {
$HD_pad="1b";
}
if($val<0) {
$HD_pad="02";
}
$string='4e'.$HD_pad.'55';
#$string='4e0255';
updateBulbs(hex2bin("$string")); //range of 2 to 1B
break;
} ?>

Re: Mi-light UDP Trigger

Posted: Tue Dec 30, 2014 5:09 pm
by Bigert
Very interesting.
I have a lot of MiLights, but a noob at programming.
Plugin would be nice.