AN01 Getting started with NETIO 4x and Lua scripts | NETIO products: Networked power sockets
Lua tutorials

This NETIO AN01 Application Note describes the first steps to simple programming of NETIO 4x (4 / 4All / 4C) smart socket devices with Lua scripts. In this tutorial, two sockets are switched on/off alternately. 

Do you have any questions?


Supported devices: 



Connecting NETIO to LAN

  • Connect NETIO smart sockets to your LAN with a network (Ethernet) cable.
  • From the NETIO products website (, download and install the NETIO Discover software for discovering your device in the network.
  • Start NETIO Discover, click Find devices and wait until your device is found as in the picture.


  • Click the IP address ( in this example) and open the web interface of the device.

If there is no DHCP server in your LAN, follow the procedure in the QIG (Quick Installation Guide). 


Default login and password: admin / admin.


Switching a socket on/off in the web interface

After logging in to the web interface, click the Outputs tab (see the picture).
Socket No. 1 (output_1) can be turned off or on by clicking the icon highlighted in red. 

  • The socket can be controlled in parallel using the NETIO Mobile App. 
  • All sockets can be controlled with buttons 1 to 4 at the NETIO device. To switch an output on or off, hold the button for at least 2 seconds.


  • The sockets can be controlled in parallel using any of the enabled M2M API protocols. 
  • The sockets can be also controlled by Lua scripts that run in parallel. 


The Log shows which method has caused the given socket to turn on/off. 


Changing the default password 

  • For security reasons, we recommend to change the default admin password. The username must be “admin” but the password can be changed. 
  • Change the password in the Users section of the web interface. Click Save Changes to confirm.


Creating a Lua script       

Lua is a simple programming language. Custom Lua scripts can run directly in the NETIO 4x (4 / 4All / 4C) smart sockets device. Custom scripts are entered in the web interface. Various ready-made scripts are available as AN (Application Notes) at the NETIO products website. 


For a list of functions, see our Wiki:


Simple flasher in Lua

  • In the Actions section, a Lua code can be pasted (or typed) into the corresponding window.
  • Give the script a name (Flasher) and a description (Switching outlets 1 and 2)
  • Choose a Trigger – an event that starts the script. For this example, select System started up. This Lua script is started after the device is powered up (approximately 40 seconds after applying power).
  • The Schedule is unused in this setting. You can leave it set to Always.
  • Copy and paste the following code:


------------Section 1------------
local output1 = 1 -- select output1 number (1 - 4)
local output2 = 2 -- select output2 number (1 - 4)
local interval = 10 -- select the interval between switching (seconds)
---------End of Section 1---------

local state = 0
local function switch()
  state = not state
  devices.system.SetOut{output=output1, value=state}
  devices.system.SetOut{output=output2, value=not state}

  • Make sure that Enabled is checked.
  • Click Create Rule to create the script.


  • A green “OK” mark should appear next to the script name and the script should be added to the list at the left-hand side.


  • In the script header, you can configure which sockets (Power Outputs) out of the four should flash alternately. 
  • You can also set the time delay. 
  • After restarting the NETIO device, the script starts running and periodically switches the chosen sockets on and off alternately. To stop a running script, uncheck Enabled, save changes and restart the NETIO device.


Setting the variables

  • The code contains 3 variables that can be used to change the sockets and the time delay.
  • The variables can be changed in the code header (Section 1).


  • output1
    • Sets first socket to flash
    • For example, to set the socket No. 2: output1=2


  • output2
    • Sets the other socket to flash
    • For example, to set the socket No. 4: output2=4


  • interval
    • Sets the time delay between changing the state (in seconds).
    • For example, to switch every 5 seconds: interval=5


  • If we wanted to switch sockets 1 and 4 every 10 seconds, the variables would be set as follows:



Supported FW versions:

3.0.0 and later



NETIO AN01, NETIO Lua, Lua script, Lua tutorial, NETIO Discover, first steps with Lua, Power sockets switching, 230V socket flasher, programmable power sockets, Lua programmable power outlets



Expand all

When I want to save a script I get a red error message: “Action code is invalid. Please find the errors, fix them, and save the changes.” What should I do?

Most likely there was a mistake when copying and pasting the code. Try to copy and paste the code again, and check that everything is set according to the instructions.

What happens if I change the state of a socket with a button or the mobile app while a script is running?

The script continues to run and sets the socket to the appropriate state during the next iteration.

How can I stop a running script?

Disable the activation of the script upon device power-up (uncheck Enabled in the script configuration) and save the changes. The script continues to run; however, when you restart the NETIO device now, the script does not start again.

How can I change the switching (blinking) interval?

Use the interval variable. See “Setting the variables”.

The “admin” account cannot be renamed or deleted.

The “admin” account is a default built-in account that cannot be renamed. However, it is possible (and we recommend) to change its password.

Ask for a price or technical parameters

For device testing use name/password demo/demo