AN05 PowerUp email alert (Lua) | NETIO products: Smart power sockets controlled over LAN and WiFi
Tags: 
User library

AN05 is a simple Lua script that sends an e-mail every time the NETIO device is restarted. This Application Note AN05 shows how to send e-mail using Lua.

Do you have any questions?

Supported devices: NETIO 4All, NETIO 4, NETIO PowerPDU 4C

 

The AN05 Lua script starts whenever the device is started and sends an e-mail via a SMTP server. In order to successfully send and deliver the e-mails, the NETIO 4x device must be connected to a network with access to the SMTP server, and all parameters relevant for the sending of e-mails must be correctly configured (see E-mail configuration).

 

In case of concerns such as that the network may not yet be fully operational when the NETIO 4x device is powered up, the sending of the e-mail can be delayed e.g. by 60 seconds.

 

NETIO 4x web interface – E-mail configuration

  • In the Settings-Email section of the NETIO 4x web administration interface, set the parameters as follows:
    • SMTP server
      • Address of the SMTP server of your e-mail provider (such as smtp.google.com, smtp.seznam.cz)
    • Enable SMTP authentication
      • Checked
      • Username – your e-mail address
      • Password – password associated with your e-mail address
      • Enable TLS encryption – checked
    • To
      • E-mail address
    • Use custom sender address
      • Optional but often necessary
    • Send daily reports about NETIO 4All health
      • Optional
      • Concerns reports about the device operation (not related in any way to the AN05 Lua script). This function periodically informs about the status of the NETIO device. For details, see the user manual.

 

Note: These are the recommended settings. Different e-mail service providers may require different settings. We recommend checking the settings against your provider’s recommended settings.

 

Some SMTP servers require that the recipient’s e-mail address is serviced by the same SMTP server as the sender’s address, others do not, and so on.

 

Send a test e-mail, which looks like this:

 

Creating the Lua rule

  • In the Actions section of NETIO 4x web administration, click Create Rule to add a rule.

 

AN05-PowerUp email script

1) Fill in the following parameters:

  • Enabled: checked
  • Name: Power up email (user-defined)
  • Description: Power up email (user-defined)
  • Trigger: System started up
  • Schedule: Always

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

 

 

------------NETIO AN05------------

------------Section 1------------
local emailReport = "recipient@gmail.com" -- your email
---------End of Section 1---------

local time = os.date("%c")

function powerUpEmail()
  local text = "NETIO was powered up at: " .. time
  mail(emailReport,"NETIO PowerUp email",text,5)
end

powerUpEmail()

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

 

Method of operation

  • The script is started every time the NETIO 4x device is powered up, and sends an e-mail to the specified e-mail address.

 

Setting the variables

  • email
    • Recipient’s e-mail address to which the power-up e-mail notification is sent.
    • It is a string so it has to be enclosed in double quotes.
    • For example, to send the notifications to my.email@gmail.com: local email =  "my.email@gmail.com"



FAQ

1) What happens with the e-mail if the NETIO 4x device is not connected to the network when the Lua script is started?

In this case, the e-mail is not sent. NETIO 4x does not queue the e-mails to be sent.
 

2) Is it possible to send the e-mail only after a certain time has elapsed after powering the device up?

Yes. Simply replace the last line of the script (powerUpEmail()) with the following:

 
delay(10,function() powerUpEmail() end)

The number in the delay function is the time (in seconds) to wait after the device is powered up before the e-mail is sent.

 

3) Is it possible to include the states of outputs or the device MAC address in the e-mail body?

Yes. All of these values can be read with Lua statements and appended to the string to send with the double-dot operator. A list of all available Lua commands is available at: https://wiki.netio-products.com

For example, to send the state of the first output:

local text = "NETIO was powered up at: " .. time .. " First output state: " .. devices.system.output1_state

 

4) Is it possible to send an e-mail when the device is being powered off?

No. Unfortunately, Lua scripts cannot be started when the device is being powered down.

 

5) Is it possible to include the time when the power went out into the e-mail?

No. The NETIO 4x device does not know the time when was the power interrupted. When the power fails, only the cumulative energy consumption counters for individual outputs are stored. 

 

6) How can I send such an e-mail periodically, not just when the device is powering up?

It is possible to use the delay function. Add the following line at the end of the powerUpEmail() function:

 
delay(3600,function() powerUpEmail() end)

The number is the time period to use for sending the e-mails. We also recommend modifying the e-mail text as it is no longer a “PowerUp Email” notification.

For a daily report about the state of the device and its outputs, the script in AN06 can be used.

 

 


 

Supported FW versions

3.1.0 and higher (Firmware archive)

 


 

 

This Application Note is compatible with:

Smart power socket NETIO

 

NETIO 4

NETIO 4 is smart power socket (smart power strip) with four 230V/8A sockets, connected to LAN and WiFi. Each of the four power sockets can be individually switched on/off using various M2M API protocols. NETIO 4 is a unique product designed for IT, industry, smart homes, multimedia installations and other applications. Use the product whenever you need 230V sockets controlled by a mobile app, by a computer program (via M2M API) or by a custom script (Lua), and featuring a timer (Scheduler) or auto reboot functionality (IP WatchDog). 

More about NETIO 4

 

Smart power socket NETIO 4All

 

NETIO 4All

NETIO 4All is a PDU module featuring four 230V/8A power sockets with consumption metering for each socket as well as LAN and WiFi connectivity. Each of the four sockets can be individually switched on/off over the Web or using various M2M API protocols. Electricity consumption (A, W, kWh) can be measured at each power socket. NETIO 4All smart sockets are designed for remote measurement and control of electrical sockets. Use the product whenever you need 230V sockets controlled by a mobile app, by a computer program (via M2M API) or by a custom script (Lua) that runs directly in the NETIO 4All smart socket device.

More about NETIO 4All

 
NETIO PowerPDU 4C is small PDU with power measurement and IEC-320 outputs

 

NETIO PowerPDU 4C

NETIO PowerPDU 4C is a small 110/230V PDU (Power Distribution Unit). Each of the four IEC-320 C13 outlets can be independently controlled (On / Off / Reset / Toggle). Electrical parameters (A, W, kWh, TPF, V, Hz) are measured with high accuracy at each outlet. The device features two LAN ports (and a built-in Ethernet switch) for connecting to a LAN. Each power output supports ZCS (Zero Current Switching) to protect the connected equipment.

More about NETIO PowerPDU 4C

 

Ask for a price or technical parameters

For device testing use name/password demo/demo