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
}