Digital Loggers

Customize your power controller using simple, powerful Lua scripting.


Updated 02/09/2021

Advanced Power Control - Lua Scripting

On its own, a power switch isn't very smart.  Add custom functionality using the built-in simple Lua scripting language. It's really simple. No programming experience is required.  Give it a try!

 

Main Lua scripting page

Turn an outlet on and off daily

To start automatically upon power up, set the start script


After entering the scripts (or copy/paste) and saving it, select the script to run and press the Start button to start it.
Start Scripts

-- Start all of my scripts from here.
-- I can start several at once this way.
function start_my_scripts()
	thread.run(outlet_8_schedule, "Turn on/off outlet 8 on schedule.")
end

-- This method requires firmware version 1.7.x or later
-- Remember that if there are multiple functions using the same name, only the last one in the script will run.
-- The event queue will trigger on the time or event defined. No need for additional delays to prevent multiple triggers.
-- Turn on outlet 8 at 6:00am and off at 10:15pm
function outlet_8_schedule()
    for i,t,data in event.stream(event.local_time({hour=6,min=0}),event.local_time({hour=22,min=15})) do
        if i == 1 then
          outlet[8].on()
        else      -- i == 2
          outlet[8].off()
        end        
    end
end

-- This accomplishes the same thing using a wait_until approach.
-- Note the delay to prevent it from running more that once in the same minute.
-- It is not advisable to use seconds in the trigger as if the system is busy, 
-- it is possible to miss a time trigger.
-- Turn on outlet 8 at 6:00am and off at 10:15pm
function outlet_8_schedule()
    while true do 
        local event = wait_until({hour=6,min=0},{hour=22,min=15})
        if event == 1 then
          outlet[8].on()
        else    -- event == 2
          outlet[8].off()        
        end
      delay(120) -- prevent it from running more than once in the same minute
    end
end




Have a smart script or unique way to use your switch?  Let us know!

engineering@digital-loggers.com