Digital Loggers

Customize your power controller using simple, powerful Lua scripting.


Updated 07/02/2019

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 lights on and off weekdays on a schedule


To start automatically upon power up, set the start script

-- Starts all of the threads
function start_my_scripts()
    thread.run(turn_on_lights_schedule, "Turn on the lights weekday mornings")
    thread.run(turn_off_lights_schedule, "Turn off the lights weekday evenings")    
end

-- returns true if it's a weekday day
local function weekday(day_of_week)
	return day_of_week<7 and day_of_week>1
end

-- Turn on lights at 7:00am weekdays -- Outlets 1-5 are lights function turn_on_lights_schedule() while true do wait_until({wday=weekday,hour=7,min=0}) for i = 1,5 do outlet[i].on() end delay(60) -- prevent it from running more than once in the same minute end end -- Turn off lights at 6:30pm weekdays -- Outlets 1-5 are lights function turn_off_lights_schedule() while true do wait_until({wday=weekday,hour=18,min=30}) for i = 1,5 do outlet[i].off() end delay(60) -- 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