better hue integration?
Moderator: leecollings
-
- Posts: 10
- Joined: Thursday 26 November 2015 11:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: better hue integration?
I am using the lua script posted above to check the hue status directly from the bridge. This is done every minute.
This is still a workaround. Can I be of some help somewhere?
This is still a workaround. Can I be of some help somewhere?
-
- Posts: 7
- Joined: Monday 11 May 2015 0:33
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: better hue integration?
I read this thread and love the workaround for status update and I want to take the challenge even one step further...
How would one be able to use coca switches to trigger a Hue and set a dim state?
Background; I would like to reuse my already mounted wireless 433mhz coca wall switches to trigger the Hue.
Currently they are triggering a coca dimmer built-in in the wall and I am using regular light bulbs right now.
I want to change them to Hue lamps
How would one be able to use coca switches to trigger a Hue and set a dim state?
Background; I would like to reuse my already mounted wireless 433mhz coca wall switches to trigger the Hue.
Currently they are triggering a coca dimmer built-in in the wall and I am using regular light bulbs right now.
I want to change them to Hue lamps
-
- Posts: 31
- Joined: Monday 27 April 2015 16:19
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2.4547
- Location: The Netherlands
- Contact:
Re: better hue integration?
I use kaku (coco) stuff all the time in combination with HUE. Simply detect the coco events and trigger Hue lights or scenes with domoticz. Using dimmers would be harder I think (I don't have any dimmers so I can't test it). I control various lighting scenes with coco remote through domoticz.
Greets!
Verstuurd vanaf mijn HTC One_M8 met Tapatalk
Greets!
Verstuurd vanaf mijn HTC One_M8 met Tapatalk
-
- Posts: 14
- Joined: Wednesday 11 March 2015 14:03
- Target OS: Linux
- Domoticz version: 2024.2
- Location: Norway
- Contact:
Re: better hue integration?
I use Nexa LYCT-705 remote to control my Hue scenes. Guessing this is similar to Kaku, Coco?florabora wrote:I read this thread and love the workaround for status update and I want to take the challenge even one step further...
How would one be able to use coca switches to trigger a Hue and set a dim state?
Background; I would like to reuse my already mounted wireless 433mhz coca wall switches to trigger the Hue.
Currently they are triggering a coca dimmer built-in in the wall and I am using regular light bulbs right now.
I want to change them to Hue lamps
Don't have any dimmers so I don't know what kind of values you get from the dimmer, but if you get percentage like 10, 20, 30 and so on this could be done with a little work.
Take a look at my scripts below, maybe you can use something there.
Had an issue with my Hue hub and needed to reset the hub and lost all my scenes. To prevent that in the future I wanted to have the most common Hue scenes values stored in Domoticz.
Also use this common scenes from different scripts so I wanted the scenes values in one place. This is how I did it.
Code: Select all
-- ~/domoticz/scripts/lua/functions.lua
local b = {}
-- Philips Hue bridge settings
local HueBridgeIP = "192.168.X.X"
local HueBridgeAPI = "XXXXXX"
-- Philips Hue light ID settings
function b.PhilipsHueID(light_id)
if light_id == "LivingRoom1" then light_id = 1 end
if light_id == "LivingRoom2" then light_id = 2 end
if light_id == "LivingRoom3" then light_id = 3 end
if light_id == "LivingRoom4" then light_id = 4 end
if light_id == "WorkRoom1" then light_id = 5 end
if light_id == "WorkRoom2" then light_id = 6 end
if light_id == "WorkRoom3" then light_id = 7 end
if light_id == "Hall1" then light_id = 8 end
if light_id == "Kitchen" then light_id = 10 end
if light_id == "AlertWorkRoom" then light_id = 13 end
if light_id == "AlertLivingRoom" then light_id = 14 end
return light_id
end
--Function for scene values
--light_id, state, bri, hue, sat, alert, colorType, colorTypeValue, effect
function b.PhilipsHueScenes(room, scene)
if (room == "Livingroom") then
if (scene == "Max") then
b.PhilipsHue("LivingRoom1", "true", 254, 14920, 144, "none", "xy", "[0.4595,0.4105]", "none")
b.PhilipsHue("LivingRoom2", "true", 254, 14920, 144, "none", "xy", "[0.4595,0.4105]", "none")
b.PhilipsHue("LivingRoom3", "true", 254, 14920, 144, "none", "xy", "[0.4595,0.4105]", "none")
b.PhilipsHue("LivingRoom4", "true", 254, 14920, 144, "none", "xy", "[0.4595,0.4105]", "none")
elseif (scene == "Relax") then
b.PhilipsHue("LivingRoom1", "true", 159, 10376, 201, "none", "xy", "[0.5282,0.3963]", "none")
b.PhilipsHue("LivingRoom2", "true", 159, 10376, 201, "none", "xy", "[0.5282,0.3963]", "none")
b.PhilipsHue("LivingRoom3", "true", 159, 10376, 201, "none", "xy", "[0.5282,0.3963]", "none")
b.PhilipsHue("LivingRoom4", "true", 159, 10376, 201, "none", "xy", "[0.5282,0.3963]", "none")
elseif (scene == "MovieMode") then
b.PhilipsHue("LivingRoom1", "true", 29, 12205, 250, "none", "xy", "[0.5455,0.4148]", "none")
b.PhilipsHue("LivingRoom2", "true", 29, 12205, 250, "none", "xy", "[0.5455,0.4148]", "none")
b.PhilipsHue("LivingRoom3", "true", 6, 5249, 115, "none", "xy", "[0.4891,0.3702]", "none")
b.PhilipsHue("LivingRoom4", "true", 6, 5249, 115, "none", "xy", "[0.4891,0.3702]", "none")
commandArray['Movie mode']='On' --Movie mode switch
elseif (scene == "Off") then
b.PhilipsHue("LivingRoom1", "false")
b.PhilipsHue("LivingRoom2", "false")
b.PhilipsHue("LivingRoom3", "false")
b.PhilipsHue("LivingRoom4", "false")
end
--Turn off "Movie mode" if On and other than Movie mode selected
if (otherdevices['Movie mode'] == 'On' and scene ~= "MovieMode") then
commandArray['Movie mode']='Off'
print("Turn Off Movie mode")
end
elseif room == "Workroom" then
if (scene == "Max") then
b.PhilipsHue("WorkRoom1", "true", 254, 14920, 144, "none", "xy", "[0.4595,0.4105]", "none")
b.PhilipsHue("WorkRoom2", "true", 254, 14920, 144, "none", "xy", "[0.4595,0.4105]", "none")
b.PhilipsHue("WorkRoom3", "true", 254, 14920, 144, "none", "xy", "[0.4595,0.4105]", "none")
elseif (scene == "Relax") then
b.PhilipsHue("WorkRoom1", "true", 126, 14130, 179, "none", "xy", "[0.4845,0.4144]", "none")
b.PhilipsHue("WorkRoom2", "true", 126, 14130, 179, "none", "xy", "[0.4845,0.4144]", "none")
b.PhilipsHue("WorkRoom3", "false")
elseif (scene == "Off") then
b.PhilipsHue("WorkRoom1", "false")
b.PhilipsHue("WorkRoom2", "false")
b.PhilipsHue("WorkRoom3", "false")
end
elseif room == "Kitchen" then
if (scene == "Max") then
b.PhilipsHue("Kitchen", "true", 254, 14920, 144, "none", "xy", "[0.4595,0.4105]", "none") -- Kitchen max
elseif (scene == "Relax") then
b.PhilipsHue("Kitchen", "true", 130, 14920, 144, "none", "xy", "[0.4595,0.4105]", "none") -- Kitchen Relax
elseif (scene == "Off") then
b.PhilipsHue("Kitchen", "false")
end
end
end
--Turn on/off Philips Hue Scene lights
--light_id, state, bri, hue, sat, alert, colorType, colorTypeValue, effect
function b.PhilipsHue(light_id, state, bri, hue, sat, alert, colorType, colorTypeValue, effect)
if state == "false" then
os.execute ('curl -X PUT -d "{\\"on\\":false}" http://'..HueBridgeIP..'/api/'..HueBridgeAPI..'/lights/'..b.PhilipsHueID(light_id)..'/state')
elseif state == "true" then
os.execute ('curl -X PUT -d "{\\"on\\": '..state..', \\"bri\\": '..bri..', \\"hue\\": '..hue..', \\"sat\\": '..sat..', \\"alert\\": \\"'..alert..'\\",\\"'..colorType..'\\": '..colorTypeValue..', \\"effect\\": \\"'..effect..'\\"}" http://'..HueBridgeIP..'/api/'..HueBridgeAPI..'/lights/'..b.PhilipsHueID(light_id)..'/state')
end
end
-- Function for checking Philips Hue On/Off state
function b.GetHueState(light_id)
local json = require ("dkjson")
local tmpfile = '/tmp/hueLight_'..b.PhilipsHueID(light_id)..'.txt'
os.execute('curl -s http://'..HueBridgeIP..'/api/'..HueBridgeAPI..'/lights/'..b.PhilipsHueID(light_id)..' > '..tmpfile)
local file = io.open(tmpfile)
local content = file:read()
local obj, pos, err = json.decode (content, 1, nil)
if err then
print ("Error:", err)
else
hue_state=(obj.state.on)
end
file:close()
os.execute('rm -f '..tmpfile..'')
--print (content)
return (hue_state)
end
-- Function for Alarm lights
function b.AlarmLights(status)
if status == "RedAlert" then
b.PhilipsHue("AlertWorkRoom", "true", 254, 65527, 253, "lselect", "xy", "[0.6736,0.3221]", "none")
b.PhilipsHue("AlertLivingRoom", "true", 254, 65527, 253, "lselect", "xy", "[0.6736,0.3221]", "none")
commandArray['Variable:AlarmLights-RedAlert']='1'
print("AlarmLights: Red Alert")
-- Timelapse alert. Only active between kl. 7:00 - 23:45
elseif (status == "Timelapse" and uservariables["AlarmLights-RedAlert"] == 0 and minutesnow >= 420 and minutesnow <= 1425) then
b.PhilipsHue("AlertWorkRoom", "true", 1, 44554, 224, "select", "hs", "[0.2175,0.1298]", "none")
b.PhilipsHue("AlertLivingRoom", "true", 1, 44554, 224, "select", "hs", "[0.2175,0.1298]", "none")
print("AlarmLights: Timelapse")
elseif status == "Off" then
b.PhilipsHue("AlertWorkRoom", "false")
b.PhilipsHue("AlertLivingRoom", "false")
print("AlertLights: Turned off")
if uservariables["AlarmLights-RedAlert"] == 1 then
commandArray['Variable:AlarmLights-RedAlert']='0'
end
end
end
-- Function for time difference
function b.timedifference(s)
year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)
t1 = os.time()
t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference = os.difftime (t1, t2)
return difference
end
return b
Code: Select all
-- ~/domoticz/scripts/lua/script_device_Lights.lua
package.path = package.path .. ';' .. '/home/pi/domoticz/scripts/lua/?.lua'
b = require('functions')
commandArray = {}
-- Living room: On (MAX)
if (devicechanged['$SceneLivingRoom_1-1'] == 'On') then -- Nexa LYCT-705 remote
b.PhilipsHueScenes("Livingroom", "Max") --Set scene "Max" in living room
print('Set scene "Max" in living room')
end
-- living room: Off
if (devicechanged['$SceneLivingRoom_1-1'] == 'Off') then
b.PhilipsHueScenes("Livingroom", "Off")
print('Turn Off lights in living room')
end
-- Living room: Relax
if (devicechanged['$SceneLivingRoom_1-2'] == 'On') then
b.PhilipsHueScenes("Livingroom", "Relax")
print('Set scene "Relax" in living room')
end
-- Living room: Movie mode
if (devicechanged['$SceneLivingRoom_1-2'] == 'Off') then
b.PhilipsHueScenes("Livingroom", "MovieMode")
if (otherdevices['IsDark'] == 'On') and (otherdevices['Night mode'] == 'Off') then
b.PhilipsHueScenes("Kitchen", "Relax")
end
print("Turn On Movie mode")
end
-- Workroom: Max
if (devicechanged['$SceneWorkroom_1-1'] == 'On') then
b.PhilipsHueScenes("Workroom", "Max")
print('Set scene "Max" in workroom')
end
-- Workroom: Off
if (devicechanged['$SceneWorkroom_1-1'] == 'Off') then
b.PhilipsHueScenes("Workroom", "Off")
print('Turn Off lights in workroom')
end
-- Workroom: Relax
if (devicechanged['$SceneWorkroom_1-2'] == 'On') then
b.PhilipsHueScenes("Workroom", "Relax")
print('Set scene "Relax" in workroom')
end
return commandArray
-
- Posts: 7
- Joined: Monday 11 May 2015 0:33
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: better hue integration?
Thought about it some more and maybe it's possible to work with user var in domoticz and some kind of a foreach statement in a script in order to change between a couple of presets?
For instance.
Default = 0
Switch on = var+1 = preset hue #1
Switch on = var+1 = preset hue #2
Switch on = var+1 = preset hue #3
Switch off = var-1 = preset hue #2
Switch off = var-1 = preset hue #1
Switch off = var-1 = preset hue #0
Would that be possible you think?
For instance.
Default = 0
Switch on = var+1 = preset hue #1
Switch on = var+1 = preset hue #2
Switch on = var+1 = preset hue #3
Switch off = var-1 = preset hue #2
Switch off = var-1 = preset hue #1
Switch off = var-1 = preset hue #0
Would that be possible you think?
-
- Posts: 31
- Joined: Monday 27 April 2015 16:19
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2.4547
- Location: The Netherlands
- Contact:
Re: better hue integration?
I did something like that in the past with a coco wall switch. Kept a variable with the number of the active scene and used the wall switch to do the +/-1 trick. All scenes also updated this variable in case I changed a scene through domoticz to keep track of the active scene. I abandoned that solution when my pi crashed and I didn't have a backup.
Verstuurd vanaf mijn HTC One_M8 met Tapatalk
Verstuurd vanaf mijn HTC One_M8 met Tapatalk
-
- Posts: 15
- Joined: Friday 01 May 2015 19:27
- Target OS: Linux
- Domoticz version: 3.5305
- Location: The Netherlands
- Contact:
Re: better hue integration?
For anyone who is interested my script to check the status of all hue lights by looping until no more lights are found.
Code: Select all
-- script to check Philips Hue light status (on/off)
-- m.hagenaars
-- feb. 2016
-- you'll need to install socket library & dkjson, more info can be found here:
-- http://www.domoticz.com/wiki/Upload_energy_data_to_PVoutput#Install_socket_library
-- http://dkolf.de/src/dkjson-lua.fsl/home
-- both need to end up in /usr/local/lib/lua/5.2
-- this time based script wil use the HUE api to check the current status of your lights as reported by the HUE bridge
-- the script starts with light #1 and checks if the status reported by your bridge corresponds with the status in Domoticz
-- if HUE state is not equal to Domoticz state then the script will correct the status in Domoticz
-- the script will keep looping until there are no more lights to check and will then stop
-- in order for the script to work it is important that the names of each light are exactly equal in both your bridge & domoticz
-- I suppose you know the names of the HUE switches in Domoticz, you can check the names in your bridge with the HUE app
-- more info on Philips HUE api and how to get/change your username can be found here:
-- http://www.developers.meethue.com/documentation/getting-started
-- configure Hue Bridge
local hueBridgeIP = 'your IP here'
local hueBridgeAPI = 'your username here'
-- do not change beyond this line
-- this part will get the Hue status
function getHueLight(id)
local http = require('socket.http')
local ltn12 = require('ltn12')
local json = require('dkjson')
t = {}
local url = string.format("http://%s/api/%s/lights/%s", hueBridgeIP, hueBridgeAPI, id)
b, c, h = http.request{url=url, sink = ltn12.sink.table(t), method='GET'}
huestring = tostring(table.concat(t))
local hue, pos, err = json.decode(huestring, 1, nil)
if (hue.name) then
hue_name = (hue.name)
hue_state = (hue.state.on)
else
stop = true
end
return hue_name, hue_state, stop
end
-- now check Hue state & correct Domoticz if needed
commandArray = {}
i = 1
repeat
local hue = getHueLight(i)
if hue_state == true and otherdevices[hue_name] == 'Off' then
commandArray[hue_name] = 'On'
print(string.format("Status %s corrigeren", hue_name))
elseif hue_state == false and otherdevices[hue_name] ~= 'Off' then
commandArray[hue_name] = 'Off'
print(string.format("Status %s corrigeren", hue_name))
end
i = i + 1
until(stop)
return commandArray
Re: better hue integration?
The latest beta should now trigger on/off actions if Hue lights are switched outside of Domoticz.
-
- Posts: 27
- Joined: Monday 13 April 2015 23:19
- Target OS: NAS (Synology & others)
- Domoticz version: 3.5033
- Location: Amsterdam, The Netherlands
- Contact:
Re: better hue integration?
That would be great! I'll try and see if I can test it this weekend. Will this also update the logs off the switches themselves when lights are switched outside of domoticz? Really appreciate your effort.
Re: better hue integration?
Yes, the logs should also be updated.
-
- Posts: 9
- Joined: Tuesday 05 April 2016 10:19
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: better hue integration?
can something like this be done for Niko Home Control lights too? I'm new to Lua, so i need some help...
thanks in advance
Kind regs,
Tom
thanks in advance
Kind regs,
Tom
Who is online
Users browsing this forum: No registered users and 1 guest