He añadido tu programación a la anterior poniendo la anterior después de "acción" y colocando el "end" al final. Así:
--[[
%% properties
86 value
90 value
412 value
--]]
local id_luz1 = 86
local id_luz2 = 90
local id_presencia = 412
local id_led1= 87
local id_led2= 89
local id_led3= 92
local tiempoApagado = 90
--[[
_esNoche(timeStamp)
función para averiguar si en un momento dado es de noche
--------------------------------------------------------------------------------]]
function _esNoche(instante)
local miInstante = os.date("*t", instante)
-- amanecer
local amanecer = fibaro:getValue(1, 'sunriseHour')
miInstante.min = tonumber(string.format("%1d", amanecer:sub(4,5)))
miInstante.hour = tonumber(string.format("%1d", amanecer:sub(1,2)))
local sunriseTime = os.time(miInstante)
-- anochecer
local anochecer = fibaro:getValue(1, 'sunsetHour')
miInstante.min = tonumber(string.format("%1d", anochecer:sub(4,5)))
miInstante.hour = tonumber(string.format("%1d", anochecer:sub(1,2)))
local sunsetTime = os.time(miInstante)
--
if (instante >= sunsetTime) then return true
elseif (instante >= sunriseTime) then return false
else return true end
end
if condicion=_esNoche(os.time()) then
-- funciona para saber si un dispositivo está activo
function _esActivo(id)
if (fibaro:getValue(id, "value") ~= nill and
tonumber(fibaro:getValue(id, "value")) > 0) then
return true
end
return false
end
-- obtener el origen del inicio de la escena
local startSource = fibaro:getSourceTrigger()
-- si se lánzo por un dispositivo ...
if (startSource["type"] == "property") then
-- obtener el dispositivo que lanzó la escena
local sourceDevice = startSource['deviceID']
-- Si se detecta presencia, no hay luzces encendidas
-- y la tira de les está apagada
if (sourceDevice == id_presencia) and
not _esActivo(id_luz1) and
not _esActivo(id_luz2) and
not _esActivo(id_led1)and
not _esActivo(id_led2)and
not _esActivo(id_led3) then
-- encender la tira de led
fibaro:debug('encender tira de leds')
fibaro:call(id_led1, "turnOn")
fibaro:call(id_led2, "turnOn")
fibaro:call(id_led3, "turnOn")
-- esperar
fibaro:sleep(1000*tiempoApagado)
-- si sigue encendido apagar
if _esActivo(id_led1) or _esActivo(id_led2) or _esActivo(id_led3) then
fibaro:debug('apagar tira de leds')
fibaro:call(id_led1, "turnOff")
fibaro:call(id_led2, "turnOff")
fibaro:call(id_led3, "turnOff")
end
end
-- si se enciende alguna luz y la tira de led está encendida
if (sourceDevice == id_luz1 or sourceDevice == id_luz2) and _esActivo(id_led1) and _esActivo(id_led2) and _esActivo(id_led3) then
-- apagar la tira de led
fibaro:debug('apagar tira de leds')
fibaro:call(id_led1, "turnOff")
fibaro:call(id_led2, "turnOff")
fibaro:call(id_led3, "turnOff")
end
else -- si no lo lanza un dispositivo se entiende que es a mano
fibaro:debug('Lanzado a mano, nada que hacer')
end
end
Pero esto me da error en la línea:
if condicion=_esNoche(os.time()) then
Lo de "condicion" a qué se refiere?
Aún me cuesta enternder algunos pasos aunque claramente entiendo mucho más que antes. Es cuestión de tiempo que deje de darte la lata con estas pequeñeces.
Jokin