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(), "Turn on/off outlet 8 on schedule.")

-- 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{hour=6,min=0}),event.local_time({hour=22,min=15})) do
        if i == 1 then
        else      -- i == 2

-- 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_on_schedule()
    while true do 
        local event = wait_until({hour=6,min=0},{hour=22,min=15})
        if event == 1 then
        else    -- event == 2
      delay(120) -- prevent it from running more than once in the same minute

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