Re: LIFX Support
Posted: Thursday 16 April 2015 13:43
mattc wrote: I've created a dummy switch based on lightwaverf
mattc wrote: I've created a dummy switch based on lightwaverf
Code: Select all
('0.0.0.0', 56700)
Found light at 192.168.1.132:56700
Traceback (most recent call last):
File "lifx_on.py", line 5, in <module>
lights=lifx.Lifx()
File "/home/pi/lifx-python/lifx/lifx.py", line 11, in __init__
self.network = Network()
File "/home/pi/lifx-python/lifx/network.py", line 27, in __init__
self.connect()
File "/home/pi/lifx-python/lifx/network.py", line 75, in connect
raise serr
socket.timeout: timed out
Code: Select all
commandArray = {}
DomDevice = 'Lifx'
lifxlabel = 'livingroom01'
apikey = 'ca757a2980a58e016bd6c91e79c********************bc94c261b5a91bb054'
if devicechanged[DomDevice] then
if(devicechanged[DomDevice]=='Off') then
print ("Turning off " .. DomDevice);
runcommand = "curl -H \"Authorization: Bearer " .. (apikey) .. "\" -XPUT https://api.lifx.com:443/v1beta1/lights/label:" .. (lifxlabel) .. "/power.json?state=off";
os.execute(runcommand);
return commandArray
elseif(devicechanged[DomDevice]=='On') then
print ("Turning on " .. DomDevice);
runcommand = "curl -H \"Authorization: Bearer " .. (apikey) .. "\" -XPUT https://api.lifx.com:443/v1beta1/lights/label:" .. (lifxlabel) .. "/power.json?state=on";
os.execute(runcommand);
return commandArray
else
DomValue = (otherdevices_svalues[DomDevice]);
end
CalcValue = DomValue / 31.25;
print ("Dimming " .. (DomDevice) .. " to " .. (CalcValue) .. " ");
runcommand = "curl -H \"Authorization: Bearer " .. (apikey) .. "\" -XPUT https://api.lifx.com:443/v1beta1/lights/label:" .. (lifxlabel) .. "/color.json?color=brightne$
os.execute(runcommand);
end
return commandArray
I notice that some people have " after the url string in the runcommand lines, some people don't. For me, removing this " caused lots of errors, so I put it back.2016-01-28 12:50:15.157 User: Admin initiated a switch command
2016-01-28 12:50:15.182 LUA: Turning off Lifx
2016-01-28 12:50:15.159 (Lifx) Lighting 5 (Lifx)
Code: Select all
pi@raspberrypi ~/lifx-python $ python lifx_on.py
('0.0.0.0', 56700)
Found light at my.ip.address:56700
Traceback (most recent call last):
File "lifx_on.py", line 6, in <module>
lifx.Lifx().on()
File "/home/pi/lifx-python/lifx/lifx.py", line 11, in __init__
self.network = Network()
File "/home/pi/lifx-python/lifx/network.py", line 27, in __init__
self.connect()
File "/home/pi/lifx-python/lifx/network.py", line 75, in connect
raise serr
socket.timeout: timed out
Code: Select all
pi@raspberrypi ~/domoticz/scripts/lua $ lua script_device_LIFXoffice.lua
lua: script_device_LIFXoffice.lua:1: unexpected symbol near '▒'
Code: Select all
commandArray = {}
DomDevice = 'Lifx'
lifxlabel = 'LIFXoffice'
apikey = 'c1emyapi677'
if devicechanged[DomDevice] then
if(devicechanged[DomDevice]=='Off') then
print ("Turning off " .. DomDevice);
runcommand = "curl -H \"Authorization: Bearer " .. (apikey) .. "\" -XPUT https://api.lifx.com:443/v1beta1/lights/label:" .. (lifxlabel) .. "/power.json?state=off";
os.execute(runcommand);
return commandArray
elseif(devicechanged[DomDevice]=='On') then
print ("Turning on " .. DomDevice);
runcommand = "curl -H \"Authorization: Bearer " .. (apikey) .. "\" -XPUT https://api.lifx.com:443/v1beta1/lights/label:" .. (lifxlabel) .. "/power.json?state=on";
os.execute(runcommand);
return commandArray
else
DomValue = (otherdevices_svalues[DomDevice]);
end
CalcValue = DomValue / 31.25;
print ("Dimming " .. (DomDevice) .. " to " .. (CalcValue) .. " ");
runcommand = "curl -H \"Authorization: Bearer " ..
(apikey) .. "\" -XPUT https://api.lifx.com:443/v1beta1/lights/label:" .. (lifxlabel) .. "/color.json?color=brightness:" .. (CalcValue) .. " ";
os.execute(runcommand);
end
return commandArray
Code: Select all
pi@raspberrypi ~/domoticz/scripts/lua $ lua script_device_LIFXoffice.lua
lua: script_device_LIFXoffice.lua:7: attempt to index global 'devicechanged' (a nil value)
stack traceback:
script_device_LIFXoffice.lua:7: in main chunk
[C]: ?
Code: Select all
sudo systemctl enable lightsd
Code: Select all
sudo nano /usr/lib/systemd/system/lightsd.service
Code: Select all
sudo systemctl daemon-reload
sudo systemctl restart lightsd
Code: Select all
sudo systemctl status lightsd
● lightsd.service - LIFX WiFi smart bulbs control service
Loaded: loaded (/usr/lib/systemd/system/lightsd.service; enabled)
Active: active (running) since Sun 2015-12-06 01:45:48 UTC; 1h 59min ago
Main PID: 19060 (lightsd)
CGroup: /system.slice/lightsd.service
└─19060 lightsd: listening_on([::]:32069, /run/lightsd/socket); command_pipes(/run/lightsd/pipe); lifx_gateways(found=2); bulbs(found=4,...
avgays wrote:My first attempt to write Lifx control, using new Python plugin:
/systemd/system/lightsd.service[/code]
add in the end of "ExecStart=" "-l 0.0.0.0:32069" to listen on all interfaces configured with an IPv4 address on your system and on port 32069Code: Select all
sudo systemctl daemon-reload....... For me - unix socket works bit faster.[/quote] Just done installing the plugin! Great work and many thanks. Would of course be a bit much to ask if you could add color wheel support as well but will certainly look forward to that if you do decide to :)
Currently Domoticz's RGB and RGBW switches sends to plugin only Color(Hue) and Brightness, but no Saturation. So it's very limited support to set Lifx colorsuperczar wrote: Would of course be a bit much to ask if you could add color wheel support as well but will certainly look forward to that if you do decide to
How about using a predefined saturation setting?avgays wrote:Currently Domoticz's RGB and RGBW switches sends to plugin only Color(Hue) and Brightness, but no Saturation. So it's very limited support to set Lifx colorsuperczar wrote: Would of course be a bit much to ask if you could add color wheel support as well but will certainly look forward to that if you do decide to
Just now I had the same issue, but using the Lifx API with the Lua script does work. However I would also like to see better support. Right now the switch does not get the active status. For example when I use the Lifx app or lightswitch to turn the light on, domoticz still shows it turned off...I have tried the python scripts that have been around since 2015, but that only detects one bulb at random. Not of much use..