AN45 PowerUp Outputs sequence for all outputs in Lua | NETIO products: Smart power sockets controlled over LAN and WiFi
Tags: 
User library

AN45 shows a Lua script that switches individual outputs on and off in a timed sequence when the device is powered up. In this way, a precise power-up sequence of the connected appliances can be defined.

 

Do you have any questions?

Supported devices: NETIO PowerPDU 4C

 

The AN45 Lua script shows how to define a timed sequence for setting the individual outputs (output1 – output4 variables) to their desired states.

The script starts as soon as the device is powered up (with a delay of about one minute before the system boots).

 

We recommend setting PowerUpState = Off for all outputs.

  • Unlike the PowerUp sequence setting, the Lua script can define much more complex sequences
  • On the other hand, the script only starts about 60 seconds after the NETIO device is powered up

 

How AN45 works

  • The NETIO device needs some time (about 1 minute) to boot its system. During this time, the outputs are switched off (as long as PowerUpState = Off).
  • For each output, a timed power-up sequence can be defined.
  • The times are relative. The time for each step of the sequence is specified as the first number in the curly braces.

 

  • Output 1:
    • Switched on at time 2 (i.e. after 2 seconds).
    • After 2 more seconds (i.e. at time 4), it is switched off.
    • After 3 more seconds, the output is switched on for 1 second, and then stays off.
  • Output 2:
    • Switched on at time 0.
    • After 7 seconds, it is switched off.
  • Output 3:
    • No sequence defined for this output.
  • Output 4:
    • Switched on 6 seconds after the system boots.
       

PowerUp State - Configuring the default ouput states

First, the outputs need to be configured to be off when the device is powered on.

  • In the web interface, click an output in the Outputs section and set its Output PowerUp state. This parameter needs to be set to OFF.
  • This parameter needs to be set to OFF for all outputs..

 

Creating the rule

To create and run the Lua script, do the following:

1) In the Actions section of NETIO 4 web administration, click Create Rule to add a rule

 

2) Fill in the following parameters:

  • Enabled: checked
  • Name: PowerUp sequence (user-defined)
  • Description: Set PowerUp sequence (user-defined)
  • Trigger: System started up
  • Schedule: Always

3) Copy the following code and paste it into the field for the Lua script:

------------NETIO AN45------------
-- Output PowerUp state must be set to OFF

------------Section 1------------
-- format: {time [sec], value [0=Off, 1=On]}
local output1 = {{0,1},{60,0}}
local output2 = {{60,1},{10,0},{10,1},{10,0},{10,1}}
local output3 = {}
local output4 = {{1,1},{1,0},{1,1},{1,0},{1,1},{1,0},{1,1},{1,0},{1,1},{1,0}}
---------End of Section 1---------


function setTimer(sequence,output)
  local time = 0
  for k, v in pairs(sequence) do
    time = time + v[1]
    local action = v[2]

    if time == 0 then
      devices.system.SetOut{output=output,value=action}
    else
      delay(time,function() devices.system.SetOut{output=output,value=action} end)
    end
  end
end

function checkFormat(sequence)
  for k, v in pairs(sequence) do
    local time = tonumber(v[1])
    local action = tonumber(v[2])
    if time == nil then
      log("Time must be a number!")
      return false
    end
    if time < 0 then
      log("Time must be higher then 0!")
      return false
    end
    if action ~= 0 and action ~= 1 then
      log(tostring(action))
      log("Action can be only 0 or 1!")
      return false
    end
  end
  return true
end

local format1 = checkFormat(output1)
local format2 = checkFormat(output2)
local format3 = checkFormat(output3)
local format4 = checkFormat(output4)

local format = (format1 and format2) and (format3 and format4)

log(tostring(format))
if format then
  setTimer(output1,1)
  setTimer(output2,2)
  setTimer(output3,3)
  setTimer(output4,4)
end


4) To finish creating the rule, click Create Rule at the bottom of the screen.

 

Method of operation

  • The script starts when the NETIO 4x device is powered up.
  • First, the format of output1, output2, output3, and output4 variables is checked. If the format is OK, the script starts setting the outputs according to the sequence.

 

Setting the variables

  • output1
    • This variable contains the power up sequence for output  1.
    • The format of the sequence is: local output1 = {{time, action}, {time, action}, {time, action}, ...}
    • The time is the delay in seconds after the previous action before the specified action is taken.
    • Time values are in seconds. The first value can be set to 0; this means the action is performed as soon as the script starts. The other values must be greater than  0.
    • The action is either 0 (switch off) or 1 (switch on).
    • If the output is to be unchanged, the variable must remain empty (local output1 = {})
    • Example - to switch the output on as soon as the script starts, and switch it off 10 seconds later: local output1 = {{0,1},{10,0}}.

 

  • output2, output3, output4
    • These variables set the sequences for outputs 2, 3 and 4 respectively. The format is the same as for output1.

 

  • Example:
    • Output 1: Switch on as soon as the script starts and switch off 60 seconds later.
    • Output 2: Switch on 60 seconds after the script starts, and then switch on and off 2 times, waiting 10 seconds in between changes.
    • Output 3: Do nothing
    • Output 4: When the script starts, switch on and off 5 times, waiting 1 second in between changes.

 

------------Section 1------------
local output1 = {{0,1},{60,0}}
local output2 = {{60,1},{10,0},{10,1},{10,0},{10,1}}
local output3 = {}
local output4 = {{1,1},{1,0},{1,1},{1,0},{1,1},{1,0},{1,1},{1,0},{1,1},{1,0}}
---------End of Section 1---------


Starting the script

The script is started whenever the NETIO device is powered up. If that does not happen, check the settings and the format of the output sequences.

 

FAQ

1) Is it possible to specify a time shorter than 1 second?

No, 1 second is the shortest possible delay.

 

2) The outputs don’t start switching when the device is powered up but only after a certain time. What is wrong?

This is normal; there is a certain delay from the moment the device is powered on to the moment the Lua script is started. This delay is approximately one minute.

 

3) Is it possible to configure an output to switch at a certain hour and minute?

Yes, for details and a script, see AN17.

 

4) Is it possible to use these power-up sequences and, at the same time, control the outputs over the Web or with the buttons?

Yes. If an output is switched using another method during the sequence, AN45 does not switch it back to the state defined in the sequence and only intervenes at the next point of the sequence.

 

5) Is it possible to define the power up sequence in devices without Lua support?

In devices without Lua support, it is possible to define a power-up delay for each output (https://www.netio-products.com/en/glossary/powerup-sequence).

 

Supported FW versions:

3.3.1 and higher

 

Ask for a price or technical parameters

For device testing use name/password demo/demo