Hallo,
Ich habe versucht meinen Hue Motion Sensor mit Fibaro zu verbinden. Dazu verwende ich ein virtuelles Device. Jedoch kommt es immer zu einem Fehler. Ich weiß nicht woran es liegt weshalb ich hier im Forum Hilfe suche.
-----------------------------------------------------------------------------
-- Philips HUE Motion Sensor Virtual Device
-----------------------------------------------------------------------------
local hueTemperatureDeviceID = 2
local hueMotionDeviceID = 3
local hueLightlevelDeviceID = 4
-- enter name of the user that you added to the HUE bridge
local hueUser = "UserID"
-- enter icon ID's for corresponding status of the virtual device
local iconOk = 1002
local iconUnreachable = 1001
local iconError = 1014
local debug = false
-- get this virtual device ID
vDeviceID = fibaro:getSelfId()
-- get IP address and TCP port for PhilipsHUE bridge
hueIP = fibaro:get(vDeviceID, "IP Adresse der Bridge")
huePort = fibaro:get(vDeviceID, "Port der Bridge")
-- connect to the Hue bridge
Hue = Net.FHttp(hueIP, huePort)
-- TEMPERATURE
response, status, errorCode = Hue:GET('/api/'..hueUser..'/sensors/'..hueTemperatureDeviceID);
-- continue if HTTP status code is 200
if (tonumber(status) == 200) then
jsonTable = json.decode(response)
-- get the temperature data
hueTemperature = jsonTable.state.temperature
if debug then fibaro:debug("hueTemperature = " .. tostring(hueTemperature)) end
fibaro:call(vDeviceID, "setProperty", "ui.temperature.value", tostring(hueTemperature/100))
fibaro:call(vDeviceID, "setProperty", "currentIcon", iconOk)
else
fibaro:log("Hue: Bridge not reachable")
fibaro:call(vDeviceID, "setProperty", "currentIcon", iconError)
end
-- MOTION
response, status, errorCode = Hue:GET('/api/'..hueUser..'/sensors/'..hueMotionDeviceID)
-- continue if HTTP status code is 200
if (tonumber(status) == 200) then
jsonTable = json.decode(response)
-- get the motion data
hueMotionDetected = jsonTable.state.presence
if debug then fibaro:debug("hueMotionDetected = " .. tostring(hueMotionDetected)) end
fibaro:call(vDeviceID, "setProperty", "ui.motionDetected.value", tostring(hueMotionDetected))
if hueMotionDetected then
huelastBreached = os.time()
else
if huelastBreached == nil then
huelastBreached = 0
end
end
if debug then fibaro:debug("huelastBreached = " .. tostring(huelastBreached)) end
fibaro:call(vDeviceID, "setProperty", "ui.lastBreached.value", tostring(huelastBreached))
fibaro:call(vDeviceID, "setProperty", "currentIcon", iconOk)
else
fibaro:log("Hue: Bridge not reachable")
fibaro:call(vDeviceID, "setProperty", "currentIcon", iconError)
end
-- LIGHTLEVEL
response ,status , errorCode = Hue:GET('/api/'..hueUser..'/sensors/'..hueLightlevelDeviceID)
-- continue if HTTP status code is 200
if (tonumber(status) == 200) then
jsonTable = json.decode(response)
-- get the lightlevel data
hueLightlevel = jsonTable.state.lightlevel
if debug then fibaro:debug("hueLightlevel = " .. tostring(hueLightlevel)) end
fibaro:call(vDeviceID, "setProperty", "ui.lightLevel.value", tostring(10^((hueLightlevel-1)/10000)))
hueDark = jsonTable.state.dark
if debug then fibaro:debug("hueDark = " .. tostring(hueDark)) end
fibaro:call(vDeviceID, "setProperty", "ui.dark.value", tostring(hueDark))
hueDaylight = jsonTable.state.daylight
if debug then fibaro:debug("hueDaylight = " .. tostring(hueDaylight)) end
fibaro:call(vDeviceID, "setProperty", "ui.daylight.value", tostring(hueDaylight))
fibaro:call(vDeviceID, "setProperty", "currentIcon", iconOk)
else
fibaro:log("Hue: Bridge not reachable")
fibaro:call(vDeviceID, "setProperty", "currentIcon", iconError)
end