Luup Example

From MiOS
Revision as of 19:08, 13 December 2013 by George (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Luup Examples

Here is an example where the lua function luup.call_timer is used as a delay timer rather than using the GUI interface delay

-- Get time and set local variables. local CurrentTime = os.date("*t") local BenchLamp = 5 local StandingLamp = 3 local EntertainmentSwitch = 6

function AllOff()

local BenchLamp = 5
local StandingLamp = 3
local EntertainmentSwitch = 6
luup.call_action("urn:upnp-org:serviceId:SwitchPower1", "SetTarget", {newTargetValue = "0"}, EntertainmentSwitch )
luup.call_action("urn:upnp-org:serviceId:SwitchPower1", "SetTarget", {newTargetValue = "0"}, StandingLamp )
luup.call_action("urn:upnp-org:serviceId:SwitchPower1", "SetTarget", {newTargetValue = "0"}, BenchLamp )

end


-- If it's night time (after 5pm and before 5am) then delay for 10 minutes before turning all off. if tonumber(CurrentTime.hour) >= 17 then

-- evening
luup.call_timer("AllOff", 1, "10m", "", "")
return true

elseif tonumber(CurrentTime.hour) <= 5 then

-- early morning
luup.call_timer("AllOff", 1, "10m", "", "")
return true

else

-- day time
-- turn everything off instantly
AllOff() 

return false end

Personal tools