Network scenarios

Another unique feature of the firmware is the ability to run network scripts.


When the user is faced with the task of handling events that occur within the network as a whole, the automation system has a mechanism for communicating devices with each other. If you assign the global flag to a system element, see the Configurator, then all other devices on the network will immediately receive events from this element via mqtt. For example take a temperature sensor element with id temp. After we enable the flag in this element global, then each interval int the temperature of this sensor will be sent to other devices and on other devices in conditions that can be used id this device.


We can write conditions like:

if temp > 30 then rel = 1


Where temp this id an item located on another remote device.


A special feature of this condition is that the temp id is not present on this device, but is sent to it over the network. Therefore, in some cases, it is necessary to know whether the sending device is online or not (online offline).


To do this, a special timer mechanism is provided inside the system, which is not visible to the user, but is a means of detecting the presence of another device on the network.


A device with the temp element sends its value every int interval, and other devices start a timer to wait for the next device to communicate with the temp element when this value is received. And if this device does not get in touch after the timer expires and does not send new data, then it should be assumed that it is not online.


To process this event, use a macro temp_onError


Then our script will look like:

if temp_onError then telegram ("sensor is offline")
if temp > 30 then rel = 1

The last condition will simply not be met in case of an error, and the user will receive a notification (line 1) that it is necessary to interfere with the system operation process.

Within the same device (when the item is located on the same device), the onError macro works differently.

if pressure_onError then telegram "pressure sensor error"

In this case, the onError macro indicates an internal error of the sensor, if this functionality was laid down by the author of the module of this sensor.


A simple example of creating a job over a network:

Create one

  • on esp1, the temp sensor and its global parameter must be set to 1.
  • on esp2 relay

Enable "Receiving events from other devices" on both ESPs. Learn more about this take a look here.

Connect esp1 and esp2 to the same mqtt broker, if this is not done.

Write a script in esp2:

if temp > 20 then relay = 1;
if temp

and everything will work over the network

Supported the project — saved a DIY maker! And we accept gifts...

X