ESP Easy rules: create a mini home automation server with ESP8266

Table of Contents

Since the version of the ESP Easy firmware, it is possible to create smaller scenarios (Rules) to turn any module ESP8266 mini server automation. The Rules very effectively fill the lack of code editor.

this tutorial is a synthesis of the official documentation available on

Turn on the Rules page

The configuration page is not active by default. To enable it, go to the Tools page and Advanced . Check the box Rules(rules), located at the bottom of the settings page.

espeasy advanced tool page

After registration of the configuration, a new page of Rules is available.

Do not expect a scenario editor, we’re on an ESP8266! You have just a text field can hold 2048 characters. That sounds little but it is already enough to create small scenarios as we shall see. It will have to be sober in the code comments, or even better have a version not commented to win valuable characters.

espeasy rules page



  • event : event
  • comparison operators: = < et >
  • value : value
  • action: runs the action or a block of stock
  • [] allows you to retrieve the value of a variable of a Device [Device Name#Value Name]. For example to retrieve the temperature (Value name: Temperature) of a DHT22 (Device Name: DHT22), we’ll do [DHT22#Temperature]. The case is not taken into account, [dht22#temperature].


  • we… endon: Action trigger when an event occurs. We get the State of a trigger as a variable [Device Name#Value Name]. The setting between hook is not necessary.
  • if… endif or if… else… endif : conditional test

System Variables

  • #Boot System: allows you to launch an action at the start of the ESP8266. For example to configure the status of outputs of GPIO, launch a timer…


One can write the rules online

<event>[=,<,>][value] do <action>


on <event>[=,<,>][value] do


  • timerSet : triggers a timer. For example timerSet, 1, 10. Triggers the timer 1 for 10 seconds
    • timerSet, ID, duration
    • ID : identifier of the timer to trigger an action to the end timer
    • term : the timer duration in seconds
  • we Rules #Timer = 1 do . Triggers an action at the end of the timer 1

Recurring Actions (Time)

Very handy for recurrent actions, we clock #Time = DAYS, HOURS. For example light watering the plants every morning at 7:30:

We clock #Time = All, 7:00 do

days : All (daily) or one day in particular (the first 3 letters of the day in English), Sun, my, kills, Wed, Thu, Fri, Sat

hour in the format HH: mm

Note: at the moment it is not yet possible to perform an action at regular intervals

Triggers a action from a HTTP call

it is possible to trigger an action using a HTTP request received a home automation software or a Web browser. The HTTP request will be of the form

http:// /control? cmd = event, ouvrevannearrosage

on the ESP will suffice to create a Rule that triggers the action called like this

on ouvrevannearrosage do
  gpio,2,1       // ouvre la vanne d'arrosage
  timerSet 1,600 // durant 10 minutes

on Rules#Timer=1 do
  gpio,2,0       // ferme la vanne d'arrosage

Trigger an action on another node ESP Easy (SendTo)

Every ESP Easy module can communicate with each other. Can trigger actions on other ESP using the command whose formalism is

SendTo <UnitNrESP>,<command>

On the first ESP #1, we send the opening drive of the watering valve

on demoEvent do
  sendTo 2,event,ouvrevannearrosage 

On the ESP #2, the previous rule allows to trigger the opening of the valve of watering for 10 minutes.

Level Control

The Device Level Control (page of the Device) can also create a trigger when a threshold is reached. The most common use and heating ignition control when a threshold temperature is reached.

In the Device list, choose Level Control then

  • Name : give a designation
  • IDX : If you use Domoticz, you can retrieve the State of the control relay. In all cases, give a different number of 0.
  • 1 st GPIO : the output that controls the relay
  • Check Task : select the trigger. For example a temperature probe.
  • Check Value : threshold value. We chose the variable of the probe to check
  • Hysteresis : allows to calculate the range to stay the measured value.


esp easy level control mini serveur domotique esp8266

How it work

After analyzing the source code available here, plugin _P021_Level seems to run like that :

  • a high threshold is calculated: limit + hysteresis / 2
  • a low threshold is calculated: threshold – hysteresis / 2
  • then, the algorithm checks if the value measured by the probe is in the range of temperatures (low threshold to high threshold)

It is far from a control loop , but it may be sufficient to regulate just a little heating.

Dummy device : calculated or copied value

We can finally make small calculations or ‘copy’ the value of a variable when an event is triggered (or at the end of a Timer) and store them in a Dummy Device. Dummy Device allows to simulate different type of device that we can simply retrieve the value in a home automation software:

  • Single: 1 output value
  • Temp_Hum : Temperature + humidity
  • Temp_Baro : Temperature-Barometer (air pressure)
  • Temp_Hum_Baro : Temperature + humidity-Barometer (air pressure)
  • Dual : 2 output values
  • Triple : 3 output values
  • Switch : State of a switch
  • Dimmer : level of a drive

esp easy dummy device


  • change of State of a device (present measure, contactor…)
  • at the end of a timer
  • at startup (we System #Boot do)


you can assign a value or a small calculation (+, -, /, *) using the following command

TaskValueSet <task nr>,<taskvalue nr>,<value|formula>

  • task nr : number of the Device (recovered in the Devices table, column Task)
  • taskvalue nr : index of the variable (1 to 4) the Dummy Device
  • value or formula : value assigned to the variable, or calculation.

For example, it affects the temperature measured by the DHT22 the 1st variable to the Dummy Device no. 5

 TaskValueSet [DHT22#TempDHT22], 5.1

We are still far from the power and the possibilities offered by an Automation server but the Rules (rules) of ESP EaSy to deport simple operating rules. The Rules can be very interesting for some applications or a cut of the WiFi network can be problematic. It is easier and more reliable to automate a portal closing, a sprinkler system… directly on the ESP8266. A failure of software, hardware or the WiFi connection will be without effect on the operation of equipment.

    Click to rate this post!
    [Total: 0 Average: 0]

    Thanks for your reading

    Did you like this project ? Don't miss any more projects by subscribing to our weekly newsletter!

    Are you having a problem with this topic?

    Maybe someone has already found the solution, visit the forum before asking your question
    We will be happy to hear your thoughts

    Leave a Reply

    Read more
    DIY Projects
    DIY Projects