Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

Mi-light UDP Trigger

Questions and comments specific to a particular plugin should go here.
Post Reply
skeltonmfc
Posts: 1
Joined: Thu Apr 24, 2014 9:02 pm

Mi-light UDP Trigger

Post 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
iotarho
Posts: 5
Joined: Wed Jan 29, 2014 3:27 am

Re: Mi-light UDP Trigger

Post 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!
iotarho
Posts: 5
Joined: Wed Jan 29, 2014 3:27 am

Re: Mi-light UDP Trigger

Post 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;
} ?>
Bigert
Posts: 4
Joined: Sat Dec 10, 2011 10:29 pm

Re: Mi-light UDP Trigger

Post by Bigert »

Very interesting.
I have a lot of MiLights, but a noob at programming.
Plugin would be nice.
Tellstick Duo Batch3 FW5, Nexa/Jula-brytare, temp-mätare (Teknikmag), fuktmätare Ebay, HP MCE MS Remote, Efergy R2, Conrad-antenn.
EventGhost 0.4.1R1600, Telldus Center 2.1.1, SunTracker, EventPhone, websocketsuite, Win7x64, MySQL.

/Bigert
Post Reply