Philips Hue Status Updates
Posted: Thursday 31 January 2019 21:20
Wasn't sure, but it seemed that the script behind the below URL had unneeded dependencies (required to install libraries) as it can be done with everything that's available as part of dzVents already (dzVents was upgraded in the meantime I guess). Pasted my code below for others to use. One for the groups (that actually are in Domoticz as devices as part of the default integration) and one for lights. Note that for groups I implemented an if statement to only check for groups with type=room. This can easily be removed if unwanted.
https://www.domoticz.com/wiki/Simple_sc ... Hue_status
Lights
Groups
[2019-02-09: added .checkFirst() to all switch commands]
https://www.domoticz.com/wiki/Simple_sc ... Hue_status
Lights
Code: Select all
return {
on = {
timer = {'every minute'},
httpResponses = { 'huetrigger' }
},
data = {
previousData = {
history = true,
maxMinutes = 5
}
},
execute = function(domoticz,item)
if (item.isTimer) then
domoticz.log('timerworks')
local hueBridgeIP = '192.168.2.XXX'
local hueBridgeAPI = 'XXXXXXXXXXXXXXXXX'
local url = string.format("http://%s/api/%s/lights", hueBridgeIP, hueBridgeAPI)
domoticz.log(url)
domoticz.openURL({
url = url,
method = 'GET',
callback = 'huetrigger'
})
end
if (item.isHTTPResponse) then
if (item.isJSON) then
local lights = domoticz.utils.fromJSON(item.data)
local previousData = domoticz.data.previousData
for i, light in pairs(lights) do
if (domoticz.devices( light.name ) ~= nil) then
local device = domoticz.devices( light.name )
if( light.state.on == true and device.state == 'Off') then
device.switchOn().checkFirst()
elseif( light.state.on == false and device.state == 'On') then
device.switchOff().checkFirst()
elseif( light.state.reachable == false and device.state == 'On') then
previousData.add( light.name )
local olderItems = previousData.subsetSince('00:05:00')
local count = olderItems.reduce(function(acc, item)
if (item.data == light.name) then
acc = acc + 1
end
return acc
end, 0)
if( count > 5 ) then -- last 5 polls were unreachable, assuming light is off
device.switchOff().checkFirst()
end
end
end
end
else
domoticz.log('noJSON',item.data)
end
end
end
}
Code: Select all
return {
on = {
timer = {'every minute'},
httpResponses = { 'huetrigger' }
},
data = {
previousData = {
history = true,
maxMinutes = 5
}
},
execute = function(domoticz,item)
if (item.isTimer) then
domoticz.log('timerworks')
local hueBridgeIP = '192.168.2.XXX'
local hueBridgeAPI = 'XXXXXXXXXX'
local url = string.format("http://%s/api/%s/groups/", hueBridgeIP, hueBridgeAPI)
domoticz.openURL({
url = url,
method = 'GET',
callback = 'huetrigger'
})
end
if (item.isHTTPResponse) then
if (item.isJSON) then
local huegroups = domoticz.utils.fromJSON(item.data)
local previousData = domoticz.data.previousData
for i, huegroup in pairs(huegroups) do
if ( huegroup.type == 'Room' ) then
if (domoticz.devices( "Group "..huegroup.name ) ~= nil) then
local device = domoticz.devices( "Group "..huegroup.name )
if( huegroup.state.any_on == true and device.state == 'Off') then
device.switchOn().checkFirst()
elseif( huegroup.state.any_on == false and device.state == 'On') then
device.switchOff().checkFirst()
end
end
end
end
else
domoticz.log('noJSON',item.data)
end
end
end
}