From Let's Control It
Jump to: navigation, search



This page is under contruction.
The OLED page is being used as a donor.


This is not an ordinary display. You cannot simply write data to it. You will first have to create an appropriate interface.
This is a very easy process when using the free Itead IDE (just search for Nextion on the web).
It has some good tutorials and once you have created your own display, it is very easy to present data and control devices with it.

The ESP8266 module can be used to control a serial Nextion display. Due to its on-board intelligence and the presence of a touch panel, the display can be used to control devices.



The board is connected to a controller by means of 4 wires.


Connect the Nextion display to a serial port and to +5 V and ground. The Nextion software module provides the use of a software serial port. So, it is not required to use the 'native'Tx and Rx ports of the controller. This display works with 5V and can be connected directly to the ESP module. The Tx pin of the Nextion is regulated to 3.3v making it safe to directly connect.


 VCC    	VCC
 Tx		GPIO port acting as Rx
 Rx		GPIO port acting as Tx

In order to get these displays to work properly you need to activate the pull-up of the Tx pin. A quick test is to set the pin to high (1) but for long turn you should enable the pull-up instead. If the pin is missing a pull-up you can add one yourself by soldering a 10k resistor from 3.3V to the pin.


Screen preparations

Although this is not the place to go into too much detail of the Nextion Editor, the examples help to explain the possibilities of the plugin. Please bear in mind, that this is the result of my experiments, no more, no less.

Let's assume you would like to have a control panel with several pages. Below is an example with 5 pages and some test pages. A front page, an info page and some switching pages. To make browsing between pages run smoothly without having to wait for databoxes to be filled, variables can be used. Several of them are declared and made global on the front page. The variables get their info from the ESPEasy in integer or text format. One timer, tm0, makes sure the control panel dims its backlight and go back to its start screen. Timer tm1 provides an update of the values once every 5000 msec.

Hereunder a step by step explanation.


During pre initialisation, timer tm0 is set to 0 msec and disabled. The backlight is set to faint with dim=10. This is the standby mode


When timer tm0 fires, the backlight is set to very faint, the panel goes to page 0 (front page) and the timer is disabled. Again, this is the standby mode with an even lower brightness, to indicate the difference with start up.


During the post initialisation of the page, after all boxes etc are made available, some data is written to various info boxes.
-clock time panel t0 gets the "actual" time from variable vTime.
-with command cov, the string containing solar energie value in vSold is converted to an int value in va0.
-solar indicator panel j1 gets the relative solar power value from variable va0.
-wifi indicator panel j0 gets the relative rssi power value from variable vRS.


Timer tm1 is programmed to provide periodic update (once every 5000 msec. when tm1 fires, data is written to various info boxes.
-clock time panel t0 gets the "actual" time from variable vTime.
-with command cov, the string containing solar energie value in vSold is converted to an int value in va0.
-solar indicator panel j1 gets the relative solar power value from variable va0.
-wifi indicator panel j0 gets the relative rssi power value from variable vRS.


Normally, the Nextion is in a standby mode. This means that a the Front page is active and the backlight is dimmed. ESPEasy sends updates to the Nextion, with stores them in the appropriate variables and boxes.
After the Nextion gets a tough release trigger, some actions are carried out:
-the backlight is set to 80% of the maximum brightness.
-if timer tm0 is already enabled, page 1 is selected the tm0 of that pages is charged.

this allows for a jump from the Front page, when it is touched for the second time within 10 seconds.

-if this is the first time Front page is touched, its own timer tm0 is charged and enabled.





ESP Easy

Use the device tab on the ESP Easy webinterface and create a new task by editing one of the available tasks. Select "Display - Nextion" from the dropdown box.

Now you first need to prepare your display. It needs to contain textboxes, numerical boxes etc. In the example below, I created variables vHO, vSold and vSolt. Data retrieved from a MQTT tasks can be written to it with:


where page0.vHO.txt describes the variable in the Nextion display, that I created beforehand.

Check this sample on how to get it done:


In the second example


The idx and value fields are used to communicate button presses etc.

This info can be handled in the Rules:


(The upper (MQTT) IDX field will be stuffed with '1', because it's needs a value. But nothing will be send with this device the second one is to write to a debug text box in Domoticz, but could also be 1)


Command Value Extra information
Nextion, - Write text messages to OLED screen, ROW for row, COL for starting column, and Text for text.
Nextion,<value> Switch on or off the OLED or to clear the display. During the off state, the content will be updated according to the latest values or states.

Special characters

Mass update [Domoticz, HTTP]


This HowTo is intended for users who use Domoticz as their domotics platform and wish to synchronize the device settings in Domoticz with those in the Nextion display. This is especially convenient when the ESP/Nextion needs to obtain device settings from domoticz after reset.

Syncing can be initiated in the Rules section of the ESPEasy that interfaces to the display, for examply during boot up or with the flip of a switch.


To make this work, we need to have:
- A Domoticz platform
- An ESPEasy with the latest firmware and Nextion display connected to it
- The devices to be updated in Nextion, must exist in Domoticz
- Some preparations to the attributes of devices in Domoticz
- A switch in Domoticz that directly triggers the update proces
- The update script written in dzVents
- Some basic understanding of the device attributes in Domoticz

This will all be explained in the following parts.

HowTo in steps

Common knowledge on how to use ESPEasy with Nextion in conjunction with Domoticz is assumed to be available. If not, let us know and we will try to help.

dzVents and attributes

The script that actually updates the Nextion, is written in dzVents, the next generation LUA scripting.
It now is an integrated part of Domoticz and it can be deployed with the build in editor. A manual can be found here: <url> <url/>
More details on Domoticz devices and attributes are here: <url><url/>
To get started, you first have to make sure dzVents is enabled at the bottom of page Main/Setup/Settings/Others in Domoticz.

Setup Other1.png
The setting is at the bottom of the page.

Domoticz preparations

Let us assume, for the sake of the example, that we have a Domoticz with:
- One wind sensor, named RFLWsWind and
- Four switches, named RFLPontpump, RFLPontlight, RFLYardlight and RFLDoorlight

These devices have corresponding counterparts in the Nextion display and they relate as follows (note: the windsensor has three counterparts in Nextion):

Domoticz device Device attribute Nextion device Nextion type data type description
RFLWsWind direction page7.t0 textbox txt page7.t0.txt=
RFLWsWind direction page4.z0 gauche val page4.z0.val=
RFLWsWind speed page7.t1 textbox txt page7.t1.txt=
RFLPontPump nValue page0.vFont integer variable val page0.vFont.val=
RFLPontLight nValue page0.vLight integer variable val page0.vLight.val=
RFLYardLight nValue page0.vErf integer variable val page0.vErf.val=
RFLDoorLight nValue page0.vAcht integer variable val page0.vAcht.val=

Also the required Domoticz device attributes are listed, as well as the Nextion data types (Number or String) and the command part of the URL to be send to the EASPEasy.

create a trigger button

To initiate the sync script, a dummy switch has the be created in the setup/hardware section of Domoticz. In this example I named it E16Conf. Upon clicking Edit of E16Conf in the Switches section of Domoticz, the setup of the switch pops up. Here the type of swtich can be modified, but most important is the text in the description box. Here are the names of a user variable that holds the IP address of the ESPEasy with Nextion and that of the uservariable that holds the names of the devices to be synchronised. The two are separated by the pipe "|" symbol. It is very important to use the exact names of the variables, in this specific order.


The E16Conf button in the switches section.


The E16Conf setup with the description text box.

create your variables

In Setup/More Options in Domoticz, are two more relevant options: User Variables and Events. In Events, the synchronisation script can be found, but that is for later.
Setup More1.png

To allow the script to synchronise the devices in Nextion, it needs to know where to find the device (the IP address) and what devices are relevant. The IP address is stored in a variable named E16NextionIP. The names of the devices, separated by the | in E16NextionDev.

The user variables with IP address and the devices of interest

Device preparations

Last but not least, the device attributes, and the appropriate Nextion command, has to be revealed to the script. The easiest way to use is the description attribute, each device has. We use it to express the attibute and the command, separated by a | symbol. More than one combination can be noted, but always in that specific order and speparated by the | symnbol.

The windsensor with three attibutes.

The script