Digital Loggers

Customize your power controller using simple, powerful Lua scripting.


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!

Hardware Requirements

This page describes the Lua based scripting language used in DLI products with WiFi.  If you're using a product without the WiFi option, look here for the BASIC scripting commands.

Entering Scripts

First, review this website for a quick overview of the Lua language.  Log in as admin and use the scripting feature.  Click the Scripting link on the left.  Review these sample scripts to start:
 
--[[ This is a sample/test set of scripts for the DLI EPCR5 controller.
The scripting implementation has changed, and is no longer compatible
with the older BASIC implementation. The most important changes are:
- Now Lua-based.
- No more line numbers, blocks of code identified by functions.
- Most of ON, OFF, etc. are kept as legacy functions, which can be called like
 e.g  ON(2345), ON("2345") or ON "2345", your choice.
Execution is still based on threads. Now threads are more visible and
manageable. Try starting some and you'll see them appearing in the
list.
]]--
function turn_outlets_on()
ON(1)
ON(2)
ON(3)
ON(4)
ON(5)
ON(6)
ON(7)
ON(8)
end
function turn_outlets_off()
OFF(12345678)
end
-- Hope this looks familiar so far.
-- Indentation is useful but not mandatory:
function toggle_stuff_and_log()
   LOG "One"
   ON(1)
   OFF(1)
   LOG "Two"
   ON(2)
   OFF(2)
   LOG "Done"
end
function do_some_lua_stuff()
    for i=1,8 do
        if i>4 then OFF(i) else ON(i) end
    end
end
-- Some display of the current states
function test_display() DISPLAY "\1Percent %%\v" DISPLAY "\2Backslash \\\v"
    DISPLAY "\1%a\v" --  current Bus A
    DISPLAY "\2%A\v" --  voltage Bus A
    DISPLAY "\1%b\v" -- current Bus B
    DISPLAY "\2%B\v" -- voltage Bus B
    DISPLAY "\1%o\v" -- Outlets state in the form "12456" (ON are displayed)
    DISPLAY "\1%O\v" -- Outlets state in the form "++-+++--"
    DISPLAY "\1%n\v" -- Serial number
    DISPLAY "\2%f\v" -- Firmware version
    DISPLAY "\f"     -- Clear screen, first line intentionally blank
    DISPLAY "\2%d\v" -- System time/date
    DISPLAY "\1%M\v" -- MAC address of the power controller
    DISPLAY "\2%i\v" -- IP address of the power controller
    DISPLAY "\1%m\v" -- IP network mask
    DISPLAY "\2%g\v" -- IP gateway
end
--[[
   Some additional scripts that may be of use
]]--


-- Swap the state of outlets 7 and 8
function flip_flop_7_8() if(outlet[7].state == on) then outlet[7].state = off outlet[8].state = on else outlet[7].state = on outlet[8].state = off end end --[[ Default OpenWrt configuration is to use the
NTP servers (0|1|2|3).openwrt.pool.ntp.org ]]--

-- Update the time via NTP
function Update_Time()
   TIME("17.151.16.23")
end


--Or via NTP name:
function update_time_too()
   TIME("time.nist.gov")
end


  • Have a smart script or unique way to use your switch? We'll acknowledge your contribution.