This tutorial will explain basics of EasyIoT server automation. Sometimes we want to automate functions in EasyIoT server. For example we want to get SMS alarm if water leak occurs or get Email notification if some event occurs, do more actions if we press one button or execute specific commands on predefined time schedule.

All settings can be done in configuration with admin username. In web interface go to Configure->Automation. Here you can add automation group. The purpose of automation group is to group similar automation programs together.

 

To test automation program we firs create one group and then add new automation program:

Add automation program

We name program and press button Add. We leave cron job empty for now.

As we can see, program is now disabled with no cron settings. To go to program editor press Edit program. 

Automation program settings

Automation engine creates template program. All programs are written in C# and use EasyIoT helper function to access EasyIoT server objects and events. We will write more about helper functions in next automation tutorial.

For now we will explain how automation module works. We see two functions Setup and Run. Setup function will execute only once at program start (when program is enabled or server started). Run function is executed on Cron schedule. We will explain cron schedule later. 

 

For now we modify program to this:

 

/*

  This code is running one time when program is enabled

*/

public void Setup()

{

  Console.WriteLine("My test program Setup executed");

}

 

/*

  This code is running periodicaly when program is enabled. 

  Cron job detirmine running period.

*/

public void Run()

{

  Console.WriteLine("My test program Run executed");

}

 

Update program and go back. When you update program program is compiled and checked for errors. Now enable program and look in EasyIoT server console. You should see something like this:

 

You will see console output written in setup function. Setup function executes only once when you enable it. In this part ob program we usually put EasyIoT event helper functions to setup custom even handlers.

If we want to execute some functions in regular interval we setup Cron settings. Cron settings are in crontab format:

* * * * *
- - - - -
| | | | |
| | | | +----- day of week (0 - 6) (Sunday=0)
| | | +------- month (1 - 12)
| | +--------- day of month (1 - 31)
| +----------- hour (0 - 23)
+------------- min (0 - 59)

 

For example if we write in crontab like this:

* * * * *

It will execute every minute. If we look in our console output we will see:

Setup is executed only once and Run is executed every minute.

For example if we want to execute our program on specific minute, hour, day, month or day of the week we change cron settings accordingly. Next is more complex example:

0 12 * */2 Mon

This Cron will execute at 12:00 PM on Monday of every other month, starting with January. For more cron examples use keyword "cron expressions" in web search engine.

All enabled programs started at EasyIoT server startup with 1 min delay.

 

This are basics of EasyIoT server automation. More will be explained in next tutorial.

See also:

EasyIoT server automation - part II

EasyIoT server automation - part III

 

See more tutorials at ​http://iot-playground.com/build​

Buying guide

To support this site and EasyIoT framework development please buy in our store.

RASPBERRY PI 3 - Model B. 1GB RAM

New Raspberry Pi 3

Raspberry Pi 512MB Model B +

Raspberry Pi Model B+, ARM1176JZF-S Running at 700MHz, 512MB RAM.

Raspberry Pi 3 Ultimate Starter Kit - Wifi, HDMI, Breadboard, SD Card

Everything you need to build basic EasyIoT server on Raspberry Pi platform.

MICRO SD 64GB 32GB 16GB MEMORY CARD

USB STICK SIM Modem 7.2MBPS 3G Wireless USB Dongle

To control EasyIoT server by SMS message.

Acrylic Case Clear Transparent Shell Enclosure Computer Box Kit For Raspberry Pi

Acrylic Case Shell Enclosure for Raspberry Pi B+

Raspberry Pi to NRF24l01+ Shield EasyIoT server compatibile

Raspberry Pi to NRF24l01+ Shield EasyIoT server compatibile, Raspberry Pi, Raspberry PI B, Raspberry Pi 2

Prototyping Shield Module For Raspberry Pi

To build custom sensors and NRF24L01 transmitter/receiver on Raspberry Pi.

NRF24L01+PA+LNA SMA Antenna Wireless Transceiver communication module 2.4G

5V 2A Charger Micro USB

For Raspberry Pi or sensor modules, cheap and easy power solution.

USB Wifi Dongle Adapter 802.11n for for Raspberry Pi Model B+ B

No need for network cables on EasyIoT server. Use WiFI USB dongle.

 


Comments   

+1 #5 Super User 2015-02-24 22:16
Quoting Thar0l:
Can I execute program using sensor data as trigger but not only on crontab timer, eg when motion sensor send data turn light on


Yes, search EventHelper in forum.
+1 #4 Thar0l 2015-02-23 16:29
Can I use sensors data as triggers for executing programs. For example can I turn light on not on crontab timer, but when motion sensor send signal
+1 #3 DarioCdj 2015-02-09 10:01
Thanks for answer, from mobile interface doesn't appear description :-) great for virtual module!
+1 #2 Super User 2015-02-08 21:46
Quoting DarioCdj:
Thanks, but what do the icon near program name? And how to execute manually a program? If I want to turn off lights an dimmer another one manually? I suppose that this are must appear in main screen and every program could be executed manually...
Dario

Just hoover over icon and you will see - enable/disable program.
If you want to manually execute program you need virtual module. It's already implemented in my development and will be soon released in beta. Virtual switch in WEB UI will be trigger for program which can execute some functions for example scenes.
In virtual module it's also possible to show calculated data.
#1 DarioCdj 2015-02-08 19:47
Thanks, but what do the icon near program name? And how to execute manually a program? If I want to turn off lights an dimmer another one manually? I suppose that this are must appear in main screen and every program could be executed manually...
Dario

You have no rights to post comments