Basic LIFX Support

Post your working scripts, libraries and tools for AHK v1.1 and older
Reasel
Posts: 3
Joined: 31 Aug 2016, 19:45

Basic LIFX Support

12 Dec 2018, 16:37

Hey guys I made a really basic script for connecting to LIFX lights API so you can control your lights with AHK. Thought I might post it so that others could find it.

LIFX.ahk

This is based on the API as seen here

Some cool things you can do are make your own custom scenes that you otherwise would not be able to make in the LIFX app. Things like pulsing a series of colors or syncing color with desktop wallpaper...
freakkk
Posts: 25
Joined: 21 Sep 2014, 20:14

Re: Basic LIFX Support

22 Jul 2019, 02:27

This is amazing! I just started playing around with the LIFX cloud api and was considering creating an ahk wrapper for it, but found you have it thoroughly done already!! :D

Thanks for sharing!
nperfo
Posts: 7
Joined: 04 Aug 2019, 02:51

Re: Basic LIFX Support

28 Nov 2019, 14:26

Hi Reasel!
Thank you so much for your web api lifx interface.
At the moment I need a LAN interface for lifx because web interface is very very slow and works only if internet is up.
Can you please help me to create a LAN lifx autohotkey interface?
User avatar
elModo7
Posts: 217
Joined: 01 Sep 2017, 02:38
Location: Spain
Contact:

Re: Basic LIFX Support

29 Nov 2019, 04:57

Awesome I as going to get hues but I may get LIFX now, thanks for sharing!!
nperfo
Posts: 7
Joined: 04 Aug 2019, 02:51

Re: Basic LIFX Support

29 Nov 2019, 21:24

elModo7 wrote:
29 Nov 2019, 04:57
Awesome I as going to get hues but I may get LIFX now, thanks for sharing!!
To control HUE is easy using AHK:
https www.reddit.com /r/Hue/comments/52adx2/autohotkey_script_i_made/ Broken Link for safety
https developers.meethue.com /develop/get-started-2/ Broken Link for safety

Controlling LIFX is harded, because LIFX.AHK from Rasel using only online web interface and its slow lag *about 1-2 sec delay
to control LIFX in fast response mode
I downloaded and installed Python
and this module: (LAN LIFX control)
https://github.com/mclarkk/lifxlan

and I'm calling Python to run script from inside the AHK: my code is here:

Code: Select all

#Persistent
#SingleInstance force

global tests := ""

global lightdata := [0, 0, 65535, 9000]

tests = 
(  
import sys
from time import sleep
from lifxlan import Light
bulb = Light("mac1:mac2:mac3:mac4:mac5:mac5", "192.168.YOURLANIP1.YOURLANIP2")
newcolor = (val1, val2, val3, val4)
bulb.set_color(newcolor)
)  

loop, read, lightdata.txt
{
	var := a_loopreadline
	i := a_index
	;tooltip i=%i% var=%var%
	;sleep 1000
	lightdata[i] := var
}

/*
c := 0xBF40BF
c := 0xFEF888
c := 0xFF0000
c := 0x411BEA

v:=getcolorhue(c)
v:=round(getcolorhue(c) / 360 * 65535)

tooltip v=%v%
;sleep 1000
;exitapp

lightdata[1] := v
*/

setcurlightdata()

q::
mousegetpos, x, y
cc := 0x1
PixelGetColor, cc, x, y, rgb

;tooltip x = %x% y = %y% cc = %cc%
huebig := round(getcolorhue(cc) / 360 * 65535)

tooltip huebig = %huebig%

lightdata[1] := huebig
setcurlightdata()
return





/*
Hue: range 0 to 65535
Saturation: range 0 to 65535
Brightness: range 0 to 65535
Kelvin: range 2500°(1500?) (warm) to 9000° (cool)
;#Hue Surat Bright Kelvin: (16128, 65535, 65535, 3500)
*/

1::
2::
3::
4::
5::
6::
7::
8::

num := A_ThisHotkey
chet := mod(num, 2)
mul := -2 * chet + 1

if (num=1 or num=2)
	p = 1
if (num=3 or num=4)
	p = 2
if (num=5 or num=6)
	p = 3
if (num=7 or num=8)
	p = 4

;tooltip p = %p% mul = %mul%
;return

val := lightdata[p]
step = 2000

val := val + mul*step

if (val < 0)
	val = 0
if (val > 65535)
	val = 65535
if (p = 4) and (val < 2500)
	val = 2500
if (p = 4) and (val > 9000)
	val = 9000

lightdata[p] := val

setcurlightdata()

return

setcurlightdata()
{
	val1 := lightdata[1]	
	val2 := lightdata[2]	
	val3 := lightdata[3]
	val4 := lightdata[4]

	filedelete, lightdata.txt
;/*
	fileappend, %val1%`n, lightdata.txt
	fileappend, %val2%`n, lightdata.txt
	fileappend, %val3%`n, lightdata.txt
	fileappend, %val4%`n, lightdata.txt
;*/
	tooltip %val1% %val2% %val3% %val4%

	PythonDll := "C:\Program Files\Python38\python38.dll"

	runstr := tests
	runstr := strreplace(runstr, "val1", val1)
	runstr := strreplace(runstr, "val2", val2)
	runstr := strreplace(runstr, "val3", val3)
	runstr := strreplace(runstr, "val4", val4)

	;tooltip runstr=%runstr%
	;sleep 10000

	res:=DllCall("LoadLibrary", "Str", PythonDll, "Ptr")
	global VMR_MODULE := DllCall("LoadLibrary", "Str", PythonDll, "Ptr")
	if (ErrorLevel || VMR_MODULE == 0)
	{
		tooltip ERRLOAD
		sleep 1000
		exitapp
	}

	DllCall(PythonDll "\Py_Initialize", "Cdecl")
	DllCall(PythonDll "\PyRun_SimpleString", "AStr", runstr)
	DllCall(PythonDll "\Py_Finalize", "Cdecl")

	return
}



esc::exitapp


getcolorsat(RGB)
{
    blu := 255 & ( RGB )
    grn := 255 & ( RGB >> 8 )
    red := 255 & ( RGB >> 16 )

    if ( blu = grn ) && ( blu = red )
        return 0 + 0.0

    else if ( blu < grn )
        if ( red < blu )
            return ( grn - red ) / ( 255 - Abs( 255 - grn - red ) )
        else if ( grn < red )
            return ( red - blu ) / ( 255 - Abs( 255 - red - blu ) )
        else
            return ( grn - blu ) / ( 255 - Abs( 255 - grn - blu ) )
    else
        if ( red < grn )
            return ( blu - red ) / ( 255 - Abs( 255 - blu - red ) )
        else if ( blu < red )
            return ( red - grn ) / ( 255 - Abs( 255 - red - grn ) )
        else
            return ( blu - grn ) / ( 255 - Abs( 255 - blu - grn ) )
} ; END - HSL_Sat( RGB )


getcolorlum(RGB)
{
    blu := 255 & ( RGB )
    grn := 255 & ( RGB >> 8 )
    red := 255 & ( RGB >> 16 )

    if ( blu < grn )
        if ( red < blu )
            return ( red + grn ) / 510
        else if ( grn < red )
            return ( blu + red ) / 510
        else
            return ( blu + grn ) / 510
    else
        if ( red < grn )
            return ( red + blu ) / 510
        else if ( blu < red )
            return ( grn + red ) / 510
        else
            return ( grn + blu ) / 510
}


getcolorhue(RGB)
{
    blu := 255 & ( RGB )
    grn := 255 & ( RGB >> 8 )
    red := 255 & ( RGB >> 16 )

    if ( blu = grn ) && ( blu = red )
        return 0 + 0.0

    else if ( blu < grn )
        if ( red < blu )
            return 60 * ( blu - red ) / ( grn - red ) + 120
        else if ( grn < red )
            return 60 * ( grn - blu ) / ( red - blu )
        else
            return 60 * ( blu - red ) / ( grn - blu ) + 120
    else
        if ( red < grn )
            return 60 * ( red - grn ) / ( blu - red ) + 240
        else if ( blu < red )
            return 60 * ( grn - blu ) / ( red - grn ) + ( blu = grn ? 0 : 360 )
        else
            return 60 * ( red - grn ) / ( blu - grn ) + 240
} ; END - getcolorhue( RGB )

this is "bad" way of organizing the AHK code to LAN-control LIFX with fast response
but this is the best fast way I found for LIFX LAN with AHK.

with Hue it is easier to control your Hue thru LAN hue bride using AHK

I own BOTH Hue and LIFX
Because I want to buy a celing light with open-style bulbes - I prefere to have LIFX because they have clear looking bulbs
Philips bulbs have a lot of tech text on them and they are not looking as clean and nice without cover as LIFX bulbes.

I will use both hue and lifx at my home.
Hue for many small GU10 bulbs. Because HUE bridge is ONE IP device on my LAN
but for LIFX - every single bulb has own IP address.

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 250 guests