Nextion display plugin

Moderators: grovkillen, Stuntteam, TD-er

Message
Author
agribaldi
Normal user
Posts: 12
Joined: 02 Oct 2018, 17:17

Re: Nextion display plugin

#401 Post by agribaldi » 04 Oct 2018, 20:04

I do not get you.
need to use node red?

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Nextion display plugin

#402 Post by grovkillen » 04 Oct 2018, 20:07

Well if Domoticz is not allowing you to publish to a MQTT topic with only a single value then node red is your best choice I guess.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

agribaldi
Normal user
Posts: 12
Joined: 02 Oct 2018, 17:17

Re: Nextion display plugin

#403 Post by agribaldi » 04 Oct 2018, 20:10

I understood.

agribaldi
Normal user
Posts: 12
Joined: 02 Oct 2018, 17:17

Re: Nextion display plugin

#404 Post by agribaldi » 05 Oct 2018, 14:39

it was possible to transfer temperature data using node red.
now trying to make feedback with the switch nextion display , something is not working yet.

agribaldi
Normal user
Posts: 12
Joined: 02 Oct 2018, 17:17

Re: Nextion display plugin

#405 Post by agribaldi » 05 Oct 2018, 14:47

2018-10-05 15_46_34-ESP_Easy.jpg
2018-10-05 15_46_34-ESP_Easy.jpg (29.85 KiB) Viewed 309491 times
Attachments
2018-10-05 15_46_08-ESP_Easy.jpg
2018-10-05 15_46_08-ESP_Easy.jpg (31.38 KiB) Viewed 309491 times
2018-10-05 15_45_31-ESP_Easy.jpg
2018-10-05 15_45_31-ESP_Easy.jpg (57.44 KiB) Viewed 309491 times

agribaldi
Normal user
Posts: 12
Joined: 02 Oct 2018, 17:17

Re: Nextion display plugin

#406 Post by agribaldi » 05 Oct 2018, 16:55

Can I change the state of the button on the display with this rule?

on STH#Sw-Lamp do
if [STH#Sw-Lamp] = 1
Publish Nextion#page0.bt0.pic=0
if [STH#Sw-Lamp] = 0
Publish Nextion#page0.bt0.pic=1
endif
endon

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Nextion display plugin

#407 Post by grovkillen » 05 Oct 2018, 17:29

Publish command is used for MQTT publishing. It got nothing to do with nextion commands. I think nextion is the command you're looking for?
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

agribaldi
Normal user
Posts: 12
Joined: 02 Oct 2018, 17:17

Re: Nextion display plugin

#408 Post by agribaldi » 05 Oct 2018, 19:00

here is almost a working version
only sometimes on or off works the second time.

on STH#Sw-Lamp do
if [STH#Sw-Lamp] = 0
Nextion,page0.bt0.val=0
endon
on STH#Sw-Lamp do
if [STH#Sw-Lamp] = 1
Nextion,page0.bt0.val=1
endon

User avatar
ThomasB
Normal user
Posts: 1214
Joined: 17 Jun 2018, 20:41
Location: USA

Re: Nextion display plugin

#409 Post by ThomasB » 05 Oct 2018, 19:11

Assuming your page0.bt0.val variable is working correctly, then try this rule code:

Code: Select all

on STH#Sw-Lamp do
 if [STH#Sw-Lamp]=0
  Nextion,page0.bt0.val=0
 endif
 if [STH#Sw-Lamp]=1
  Nextion,page0.bt0.val=1
 endif
endon
- Thomas

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Nextion display plugin

#410 Post by grovkillen » 05 Oct 2018, 19:13

agribaldi wrote: 05 Oct 2018, 19:00 here is almost a working version
only sometimes on or off works the second time.

on STH#Sw-Lamp do
if [STH#Sw-Lamp] = 0
Nextion,page0.bt0.val=0
endon
on STH#Sw-Lamp do
if [STH#Sw-Lamp] = 1
Nextion,page0.bt0.val=1
endon

Code: Select all

on STH#Sw-Lamp do
if [STH#Sw-Lamp] = 0
Nextion,page0.bt0.val=0
else
Nextion,page0.bt0.val=1
endif
endon
You never closed the if chunk with a "endif" and since it's a simple if/else you can make it like I suggest above.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

Bryt
New user
Posts: 1
Joined: 22 Feb 2018, 20:22

Re: Nextion display plugin

#411 Post by Bryt » 11 Oct 2018, 15:11

Hi! Im trying to read out value from an counter n domoticz to send to a textbox in nextion but i cant get it to work.
I can read out sensors and send but not counters.
I have used the luascript Ierlandfan posted earlier her
but cant get it to work.
Domoticz log says LUA: Counter = 75.015
I would be very grateful for help, here is the script

Code: Select all

-- we need this function to send the quotes around the values
function url_encode(str)
  if (str) then
    str = string.gsub (str, "\n", "\r\n")
    str = string.gsub (str, "([^%w %-%_%.%~])",
        function (c) return string.format ("%%%02X", string.byte(c)) end)
    str = string.gsub (str, " ", "+")
  end
  return str
end
 
countervalueintext = otherdevices_svalues['Counter'] --this values can be for example 88.5 or 1433.2, just like temperature can be 2.3 or -4.4)
countervalueinquotes = '"' ..countervalueintext.. '"' --First part of the magic

commandArray = {}
print('Counter = '..countervalueintext) --This shows up in Domoticz log
counter =tonumber(countervalueintext) -- If you want to compare numeric values, see example later on

if (devicechanged['Counter'])then --If value changes of device SolarEnergyLive 

os.execute('curl -s "http://192.168.x.x/control?cmd=NEXTION,page2.t7.txt=' .. url_encode(countervaluesinquotes) .. '"') --sending value to textbox in quotes
print('Sending data to Nextion') --This shows up in Domoticz log
return commandarray --execute the commands
end --To close the If

Wiki
Normal user
Posts: 415
Joined: 23 Apr 2018, 17:55
Location: Germany

Re: Nextion display plugin

#412 Post by Wiki » 24 Oct 2018, 18:46

Hi,

meanwhile I think, I am stupid. I scrolled through the whole thread. My Nextion is connected to a Wemos D1, blue cable=> D7, yellow cable => D5. Serial port disabled.
Configuration of the Nextion in ESPEasy:
extion1.jpg
extion1.jpg (48.58 KiB) Viewed 308746 times
extion2.jpg
extion2.jpg (34.11 KiB) Viewed 308746 times
In Nextion, I have a textfield named "WZt", when I am tying to send esp_ip/control?cmd=NEXTION,page0.WZt.txt="hallo" nothing happens.

Code: Select all

pi@raspberrypi:~ $ man woman
No manual entry for woman
pi@raspberrypi:~ $

User avatar
ThomasB
Normal user
Posts: 1214
Joined: 17 Jun 2018, 20:41
Location: USA

Re: Nextion display plugin

#413 Post by ThomasB » 24 Oct 2018, 22:35

In Nextion, I have a textfield named "WZt", when I am tying to send esp_ip/control?cmd=NEXTION,page0.WZt.txt="hallo" nothing happens.
1. When you issue your http command from a web browser, does the browser show a response that looks like this?

Code: Select all

NEXTION075 : WRITE = page0.WZt.txt="hallo"
2. Your Line 1 Nextion Command Statement is configured to write "24.5" to the Nextion WZt text field every 10 seconds. Do you see this value on the Nextion Display?

- Thomas

Wiki
Normal user
Posts: 415
Joined: 23 Apr 2018, 17:55
Location: Germany

Re: Nextion display plugin

#414 Post by Wiki » 25 Oct 2018, 01:06

Yes, the browser shows me exactly the response that you've posted. Sorry, I should have added this info to my post.

And no, the "24.5" doesn't appear on the Nextion. Thats why I tried to send whatever to the node connected to the Nextion using the http control command.

Code: Select all

pi@raspberrypi:~ $ man woman
No manual entry for woman
pi@raspberrypi:~ $

User avatar
ThomasB
Normal user
Posts: 1214
Joined: 17 Jun 2018, 20:41
Location: USA

Re: Nextion display plugin

#415 Post by ThomasB » 25 Oct 2018, 03:54

Yes, the browser shows me exactly the response that you've posted.
That confirms the Nextion plugin is active.

Code: Select all

And no, the "24.5" doesn't appear on the Nextion. 
1. Check the ESP's serial wiring for problems.
BTW, don't forget the Nextion's black (ground) wire needs to be connected to Wemos ground. Nextion requires 5.0V (not 3.3V).

2. Check your Nextion software that you created. Maybe there is an error in your code.

- Thomas

Wiki
Normal user
Posts: 415
Joined: 23 Apr 2018, 17:55
Location: Germany

Re: Nextion display plugin

#416 Post by Wiki » 25 Oct 2018, 16:35

......and yes, I AM stupid.

Wiring OK, Plugin OK, Nextion OK. But now I've learned, that I should have checked the source of the Nextin for typos. If I want to send to "WZt" but the field was named by me "WWt" it could not work.

Never mind, sorry and thanks for your thoughts and tipps, and thanks for the plugin. Works absolutely perfect now.

Code: Select all

pi@raspberrypi:~ $ man woman
No manual entry for woman
pi@raspberrypi:~ $

User avatar
ThomasB
Normal user
Posts: 1214
Joined: 17 Jun 2018, 20:41
Location: USA

Re: Nextion display plugin

#417 Post by ThomasB » 25 Oct 2018, 16:40

Works absolutely perfect now.
Glad to hear you got it working.
- Thomas

Wiki
Normal user
Posts: 415
Joined: 23 Apr 2018, 17:55
Location: Germany

Re: Nextion display plugin

#418 Post by Wiki » 29 Oct 2018, 17:40

Hi,

Thanks a lot for the efforts you have had with the plugin. The WAF (women's acceptance factor) raised up to 100%.

Short question: using the original RX/TX hard serial on the Wemos D1 mini (GPIO3/1) works 100% reliable (opposite to the soft serial) - you described this some pages earlier. But if I'm configuring the speed higher than 9600 I get no connection to the Nextion. Normal behaviour?

Code: Select all

pi@raspberrypi:~ $ man woman
No manual entry for woman
pi@raspberrypi:~ $

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Nextion display plugin

#419 Post by grovkillen » 29 Oct 2018, 17:44

Wiki wrote: 29 Oct 2018, 17:40 Hi,

Thanks a lot for the efforts you have had with the plugin. The WAF (women's acceptance factor) raised up to 100%.

Short question: using the original RX/TX hard serial on the Wemos D1 mini (GPIO3/1) works 100% reliable (opposite to the soft serial) - you described this some pages earlier. But if I'm configuring the speed higher than 9600 I get no connection to the Nextion. Normal behaviour?
Up to 115200 is supported as far as I know but if the plugin is programmed for 9600 I guess setting it to something else will make the communication miss.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

User avatar
ThomasB
Normal user
Posts: 1214
Joined: 17 Jun 2018, 20:41
Location: USA

Re: Nextion display plugin

#420 Post by ThomasB » 29 Oct 2018, 18:44

The Nextion display module defaults to 9600 baud. It does NOT automatically detect other baud rates.

So if you select anything other than 9600 in the plugin you will also need to change the baud setting in the display module. Nextion's Baud command syntax is found here:
https://nextion.itead.cc/resources/docu ... ction-set/
https://www.itead.cc/wiki/Nextion_Instruction_Set

- Thomas

Wiki
Normal user
Posts: 415
Joined: 23 Apr 2018, 17:55
Location: Germany

Re: Nextion display plugin

#421 Post by Wiki » 30 Oct 2018, 11:44

Thank you for the information and the links.

I did'nt think that it would be useful for me to use a higher speed than 9600 baud because up to now I only fill a few variables and check one button to be pressed. These few bytes seemed to be communicated fast enough between the devices. Just from curiosity I changed the speed to 115200. At 9600 baud I had a lack of around 1.5 seconds betweeen pressing the button and switching the light on. Has been good for me, because the relay for the light is connected to another node in my network. At 115200 the light is switched on almost instantly. Never stop learning....

Code: Select all

pi@raspberrypi:~ $ man woman
No manual entry for woman
pi@raspberrypi:~ $

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Nextion display plugin

#422 Post by grovkillen » 30 Oct 2018, 12:22

I feel that the plug-in should have a baud rate setting.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

Wiki
Normal user
Posts: 415
Joined: 23 Apr 2018, 17:55
Location: Germany

Re: Nextion display plugin

#423 Post by Wiki » 30 Oct 2018, 16:15

Setting the desired baudrate in the initializing section of the Nextion works fine. The plugin in its current state seems to me pretty stable and almost complete.

The one and only thing on my personal wishlist would be the possibility of flashing the Nextion over network. Its such a pain to unmount the display off the wall for only adding a textfield that I have ordered This one to get an useable access to the sd cardslot of the display mounted to the wall. Somehow I will integrate the cable in the future housing of the Nextion.

Code: Select all

pi@raspberrypi:~ $ man woman
No manual entry for woman
pi@raspberrypi:~ $

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Nextion display plugin

#424 Post by grovkillen » 30 Oct 2018, 18:04

Could it be combined with a WiFi SD card or isn't the nextion that simple to set up?
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

Wiki
Normal user
Posts: 415
Joined: 23 Apr 2018, 17:55
Location: Germany

Re: Nextion display plugin

#425 Post by Wiki » 30 Oct 2018, 22:56

The combination should be that ESPEasy plays the Wifi card for the Nextion.

Flashing the Nextion using UART works perfectly out of the Nextion Editor while connected to my Laptop, in the Arduino library published by Itead there is an explicit function for doing this, too.

I am pretty sorry for the fact, that my coding skills are not sufficient do realize this wish. But looking at the Arduino libraries might show the way how to flash the Nextion over network using the existing - in my opinion pretty stable - serial connection of ESPEasy to the display - prerequisit hard serial.

Code: Select all

pi@raspberrypi:~ $ man woman
No manual entry for woman
pi@raspberrypi:~ $

User avatar
ThomasB
Normal user
Posts: 1214
Joined: 17 Jun 2018, 20:41
Location: USA

Re: Nextion display plugin

#426 Post by ThomasB » 31 Oct 2018, 02:40

I've never used the Ser2Net plugin, but maybe it could be used to assist with flashing the Nextion? Or maybe a spinoff of Ser2Net that has been altered to support Nextion's hardware serial wiring scheme. Minor code tweaks shouldn't be a problem, but a major code rewrite would be a deal killer for me.

Ideally we would need a virtual com port on our developer PC that the Nextion IDE could use to redirect its com port to TCP for flashing. Something like this (randomly found with Google):
https://www.hw-group.com/software/hw-vs ... erial-port

It would be great if a Nextion plugin user that has experience with Ser2Net would chime in and offer some insight on this idea.

- Thomas

User avatar
ManS-H
Normal user
Posts: 283
Joined: 27 Dec 2015, 11:26
Location: the Netherlands

Re: Nextion display plugin

#427 Post by ManS-H » 31 Oct 2018, 19:03

Wiki wrote: 24 Oct 2018, 18:46 In Nextion, I have a textfield named "WZt", when I am tying to send esp_ip/control?cmd=NEXTION,page0.WZt.txt="hallo" nothing happens.
Wiki, is it possible to send me that HMI file or a printscreen of the Nextion Editor? I do something wrong, but i don't see the light.
Thanks in advance, Herman

Wiki
Normal user
Posts: 415
Joined: 23 Apr 2018, 17:55
Location: Germany

Re: Nextion display plugin

#428 Post by Wiki » 01 Nov 2018, 00:31

I think, a printscreen would not be helpful.

Pls give some more input.

Code: Select all

pi@raspberrypi:~ $ man woman
No manual entry for woman
pi@raspberrypi:~ $

User avatar
ManS-H
Normal user
Posts: 283
Joined: 27 Dec 2015, 11:26
Location: the Netherlands

Re: Nextion display plugin

#429 Post by ManS-H » 01 Nov 2018, 11:09

Wiki wrote: 01 Nov 2018, 00:31 I think, a printscreen would not be helpful.

Pls give some more input.
Wiki,
I did the same as you, setup the Nextion plugin. And put in the first line: page0.WZt.txt="24.5"

Then i start Nextion Editor, I have selected a font. Then i select in in the Toolbox the first line, Text.
Give it as objname: WZt

Compile it and save is as WZt. After that i bring the two files to the Nextion. I see on the screen "newtxt"

When i do esp_ip/control?cmd=NEXTION,page0.WZt.txt="hallo" it respond with NEXTION075 : WRITE = page0.WZt.txt="hallo"
But i don't see "24.5" on the Nextion screen.

I do something wrong in the Nextion Editor part, and here i need some help.

Wiki
Normal user
Posts: 415
Joined: 23 Apr 2018, 17:55
Location: Germany

Re: Nextion display plugin

#430 Post by Wiki » 01 Nov 2018, 11:32

What you have done is absolutely correct. Talking to the Nextion using the Nextion-plugin is really that simple - if you do have a working serial communication.

Check your wiring twice and triple, assure you have connected GND ESP and GND Nextion, use baudrate 9600, disable serial communication in ESPEasy Tools/Advanced.

In my first step I followed This wiring diagram, except diode and resistor, they are not necessary. My first configuration RX/TX of ESPEasy-plugin is shown here. To use hard serial my Nextion is meanwhile connected to the RX/TX pins of the Wemos.

Code: Select all

pi@raspberrypi:~ $ man woman
No manual entry for woman
pi@raspberrypi:~ $

User avatar
ManS-H
Normal user
Posts: 283
Joined: 27 Dec 2015, 11:26
Location: the Netherlands

Re: Nextion display plugin

#431 Post by ManS-H » 01 Nov 2018, 16:31

Wiki wrote: 01 Nov 2018, 11:32 What you have done is absolutely correct. Talking to the Nextion using the Nextion-plugin is really that simple - if you do have a working serial communication.

Check your wiring twice and triple, assure you have connected GND ESP and GND Nextion, use baudrate 9600, disable serial communication in ESPEasy Tools/Advanced.

In my first step I followed This wiring diagram, except diode and resistor, they are not necessary. My first configuration RX/TX of ESPEasy-plugin is shown here. To use hard serial my Nextion is meanwhile connected to the RX/TX pins of the Wemos.
Thanks Wiki, it works now. You have right, a wiring problem. I was looking to much too the colors. But the wiring of my screen was reversed. Better looking at the rear side of the print was the solution.
Nextion.jpg
Nextion.jpg (28.53 KiB) Viewed 307624 times

User avatar
ManS-H
Normal user
Posts: 283
Joined: 27 Dec 2015, 11:26
Location: the Netherlands

Re: Nextion display plugin

#432 Post by ManS-H » 09 Nov 2018, 16:21

BertB wrote: 22 Jan 2017, 15:34
First I added two variables va0 and va1 and unchecked the Send Component ID of
Bt0, b0 and down buttons.
Next I put some code under the buttons:
Under Tough Release Event of bt0:
if(va1.val==0)
{
va1.val=1
print "|s,i99,sOn"
printh 0a
}else
{
va1.val=0
print "|s,i99,sOff"
printh 0x0a
}

I also added some rules to the ESP.

on Nextion#idx=99 do
if [Nextion#value]=1
sendtohttp 192.168.0.243,8080,/json.htm?param=switchlight&type=
command&idx=304&switchcmd=On
else
sendtohttp 192.168.0.243,8080,/json.htm?param=switchlight&type=
command&idx=304&switchcmd=Off
endif
endon

on Nextion#idx=230 do
sendtohttp 192.168.0.243,8080,/json.htm?param=udevice&type=
command&idx=79&nvalue=0&svalue=[Nextion#value]
endon

With the code below, you can now also send values.
As for now I distinguish |u for update and |s for switch
First of all I will thanks BertB and ThomasB for this plugin. After a lot of reading and trying i can now switched the three lights in the livingroom on and off with the Nextion Display.
With the help of the part I quote it runs fine.
I have only one problem. Domoticz switched the lights automatic on. But i dont seen the state changing of the Nextion.
How can i made that visible?

Wiki
Normal user
Posts: 415
Joined: 23 Apr 2018, 17:55
Location: Germany

Re: Nextion display plugin

#433 Post by Wiki » 10 Nov 2018, 10:39

In general its no problem to show every information you desire on the Nextion using some rules.

But to get help you should provide more information about the infrastructure you are using.

Code: Select all

pi@raspberrypi:~ $ man woman
No manual entry for woman
pi@raspberrypi:~ $

User avatar
ManS-H
Normal user
Posts: 283
Joined: 27 Dec 2015, 11:26
Location: the Netherlands

Re: Nextion display plugin

#434 Post by ManS-H » 13 Nov 2018, 11:17

Wiki wrote: 10 Nov 2018, 10:39 In general its no problem to show every information you desire on the Nextion using some rules.

But to get help you should provide more information about the infrastructure you are using.
My situation, i have three table lights with a ESP01 and ESPEasy build 145.
I switched they on/off with Domoticz with this command:192.168.178.xxx/control?cmd=GPIO,0,1 and 192.168.178.xxx/control?cmd=GPIO,0,0
For this moment i try to use a Nextion as Remote Control. That works good, only when Domoticz switched on a table Light the Remote Control overruled the switch in Domoticz.
My wish, switch the lamp on with Domoticz, see changing the state on the Nextion, and switched the lamp off on the Nextion.
And how to do that i don't seen the light. ;)

Wiki
Normal user
Posts: 415
Joined: 23 Apr 2018, 17:55
Location: Germany

Re: Nextion display plugin

#435 Post by Wiki » 14 Nov 2018, 00:43

Is the Nextion connected to the same device which is switching the lights or are these two different devices? Or are the lights switched by three different devices?

Code: Select all

pi@raspberrypi:~ $ man woman
No manual entry for woman
pi@raspberrypi:~ $

User avatar
ManS-H
Normal user
Posts: 283
Joined: 27 Dec 2015, 11:26
Location: the Netherlands

Re: Nextion display plugin

#436 Post by ManS-H » 14 Nov 2018, 10:51

Wiki wrote: 14 Nov 2018, 00:43 Is the Nextion connected to the same device which is switching the lights or are these two different devices? Or are the lights switched by three different devices?
Nextion has his own device, a Wemos D1 mini, The table lamp has a ESP01 and Domoticz a Raspberry Pi

Wiki
Normal user
Posts: 415
Joined: 23 Apr 2018, 17:55
Location: Germany

Re: Nextion display plugin

#437 Post by Wiki » 14 Nov 2018, 14:48

OK, lets go.

There might be a smarter solution, but I would go through rules. I assume that you have the domoticz configured as MQTT-controller in your ESP12. I assume that you have define a dual-state button in Nextion.

If not already done so, define the gpio port of the relay as a device, an example you can find here, third image of the example using your GPIO 0 as 1st GPIO. On your ESP12 enable rules in the Webgui "Tools/Advanced". Define a rule:

Code: Select all

On Relay#State do
  if [Relay#State]=0
      Publish domoticz/in,{"idx":123456,"nvalue":0,"svalue":"0"} //replace idx 123456 with the correct idx of the switch in domoticz, domoticz will change the state by itself
      SendToHTTP 192.168.xxx.xxx,80,/control?cmd=event,RelayState=0  //put in the ip of your wemos
    else
      Publish domoticz/in,{"idx":123456,"nvalue":1,"svalue":"1"} //replace idx 123456 with the correct idx of the switch in domoticz
      SendToHTTP 192.168.xxx.xxx,80,/control?cmd=event,RelayState=1
  endif
endon
On your Wemos enable rules, too.

Define a rule on your Wemos:

Code: Select all

On RelayState do
  if %eventvalue%=0
    //Here place the action you want to send to Nextion using the correct name 'pagex.bty' for yout button
    //e.g. changing the value of your button: NEXTION,page0.bt0.val=0
  else
    //Here place the action you want to send to Nextion as opposite to switching off
    //e.g. changing the value of yout button: NEXTION,page0.bt0.val=1
  endif
endon
These two rules should change the state of the switch in domoticz as well as the state of your button in Nextion.

Code: Select all

pi@raspberrypi:~ $ man woman
No manual entry for woman
pi@raspberrypi:~ $

User avatar
ManS-H
Normal user
Posts: 283
Joined: 27 Dec 2015, 11:26
Location: the Netherlands

Re: Nextion display plugin

#438 Post by ManS-H » 17 Nov 2018, 16:06

Wiki wrote: 14 Nov 2018, 14:48 OK, lets go.

There might be a smarter solution, but I would go through rules. I assume that you have the domoticz configured as MQTT-controller in your ESP12. I assume that you have define a dual-state button in Nextion.

If not already done so, define the gpio port of the relay as a device, an example you can find here, third image of the example using your GPIO 0 as 1st GPIO. On your ESP12 enable rules in the Webgui "Tools/Advanced". Define a rule:

Code: Select all

On Relay#State do
  if [Relay#State]=0
      Publish domoticz/in,{"idx":123456,"nvalue":0,"svalue":"0"} //replace idx 123456 with the correct idx of the switch in domoticz, domoticz will change the state by itself
      SendToHTTP 192.168.xxx.xxx,80,/control?cmd=event,RelayState=0  //put in the ip of your wemos
    else
      Publish domoticz/in,{"idx":123456,"nvalue":1,"svalue":"1"} //replace idx 123456 with the correct idx of the switch in domoticz
      SendToHTTP 192.168.xxx.xxx,80,/control?cmd=event,RelayState=1
  endif
endon
On your Wemos enable rules, too.

Define a rule on your Wemos:

Code: Select all

On RelayState do
  if %eventvalue%=0
    //Here place the action you want to send to Nextion using the correct name 'pagex.bty' for yout button
    //e.g. changing the value of your button: NEXTION,page0.bt0.val=0
  else
    //Here place the action you want to send to Nextion as opposite to switching off
    //e.g. changing the value of yout button: NEXTION,page0.bt0.val=1
  endif
endon
These two rules should change the state of the switch in domoticz as well as the state of your button in Nextion.
Wiki, Thanks for the rules, after a lot of trying it works for 90%
On the Nextion i have a button on page0 with objname bt0 and vscope global, Touch Release Event Send Component ID active.

This is what i see on my Wemos, the second Sendto is a switch I made for control.
692784: EVENT: RelayState=0
1692798: ACT : SendToHTTP 192.168.178.127,80,/control?cmd=NEXTION,page0.bt0.val=0
1692812: ACT : SendToHTTP 192.168.178.127,80,/control?cmd=GPIO,12,0
1710719: EVENT: RelayState=1
1710735: ACT : SendToHTTP 192.168.178.127,80,/control?cmd=NEXTION,page0.bt0.val=1
1710752: ACT : SendToHTTP 192.168.178.127,80,/control?cmd=GPIO,12,1

It's sends a state but the color of the button didn't change, also the state of the switch didn't change.
When i send in the browser: http://192.168.178.127/control?cmd=NEXT ... .bt0.val=0 of http://192.168.178.127/control?cmd=NEXT ... .bt0.val=1

The colors are changing. Did you maybe have a solution for this behavior?

User avatar
ThomasB
Normal user
Posts: 1214
Joined: 17 Jun 2018, 20:41
Location: USA

Re: Nextion display plugin

#439 Post by ThomasB » 17 Nov 2018, 19:07

I'm a bit confused, but here's what I think is going on.
1. The Nextion is wired to the ESP12 and has IP address 192.168.178.xxx.
2. The Relay is on ESP01 and has IP address 192.168.178.127.
3. The ESP12's rule is sending the NEXTION http command to the ESP01. This is not what is wanted because the NEXTION is wired to the EPS12.

What is needed is a rule in the ESP01 relay device that sends the NEXTION's http commands whenever the relay changes states. For example, in the ESP01 rules try this:

Code: Select all

On Relay#State do
  if [Relay#State]=0
      SendToHTTP 192.168.178.xxx,80,/control?cmd=NEXTION,page0.bt0.val=0  //put in the ip of your NEXTION's ESP12
    else
      SendToHTTP 192.168.178.xxx,80,/control?cmd=NEXTION,page0.bt0.val=1
  endif
endon
If I have misunderstood how things are wired then please ignore my comments.

- Thomas

User avatar
ManS-H
Normal user
Posts: 283
Joined: 27 Dec 2015, 11:26
Location: the Netherlands

Re: Nextion display plugin

#440 Post by ManS-H » 17 Nov 2018, 20:15

ThomasB wrote: 17 Nov 2018, 19:07 I'm a bit confused, but here's what I think is going on.
1. The Nextion is wired to the ESP12 and has IP address 192.168.178.xxx.
2. The Relay is on ESP01 and has IP address 192.168.178.127.
3. The ESP12's rule is sending the NEXTION http command to the ESP01. This is not what is wanted because the NEXTION is wired to the EPS12.

What is needed is a rule in the ESP01 relay device that sends the NEXTION's http commands whenever the relay changes states. For example, in the ESP01 rules try this:

Code: Select all

On Relay#State do
  if [Relay#State]=0
      SendToHTTP 192.168.178.xxx,80,/control?cmd=NEXTION,page0.bt0.val=0  //put in the ip of your NEXTION's ESP12
    else
      SendToHTTP 192.168.178.xxx,80,/control?cmd=NEXTION,page0.bt0.val=1
  endif
endon
If I have misunderstood how things are wired then please ignore my comments.

- Thomas
Hello ThomasB, thanks your answer. Instead of the ESP01 i use a Sonoff Pow for testing.
On the Sonoff Pow with IP: 192.168.178.126 i use this rule:
On Relay#State do
if [Relay#State]=0
SendToHTTP 192.168.178.53,8080,/json.htm?type=command&param=udevice&idx=1534&nvalue=0&svalue=0
SendToHTTP 192.168.178.127,80,/control?cmd=event,RelayState=0
else
SendToHTTP 192.168.178.53,8080,/json.htm?type=command&param=udevice&idx=1534123456&nvalue=1&svalue=1
SendToHTTP 192.168.178.127,80,/control?cmd=event,RelayState=1
endif
endon

On theWemos with the Nextion display, IP: 192.168.178.127 i use this rule:
On RelayState do
if %eventvalue%=0
SendToHTTP 192.168.178.127,80,/control?cmd=NEXTION,page0.bt0.val=0
SendToHTTP 192.168.178.127,80,/control?cmd=GPIO,12,0
else
SendToHTTP 192.168.178.127,80,/control?cmd=NEXTION,page0.bt0.val=1
SendToHTTP 192.168.178.127,80,/control?cmd=GPIO,12,1
endif
endon

Maybe it's so a litle bit clear for you.

User avatar
ThomasB
Normal user
Posts: 1214
Joined: 17 Jun 2018, 20:41
Location: USA

Re: Nextion display plugin

#441 Post by ThomasB » 17 Nov 2018, 20:58

On theWemos with the Nextion display, IP: 192.168.178.127 i use this rule:
On RelayState do
if %eventvalue%=0
SendToHTTP 192.168.178.127,80,/control?cmd=NEXTION,page0.bt0.val=0
SendToHTTP 192.168.178.127,80,/control?cmd=GPIO,12,0
else
SendToHTTP 192.168.178.127,80,/control?cmd=NEXTION,page0.bt0.val=1
SendToHTTP 192.168.178.127,80,/control?cmd=GPIO,12,1
endif
endon
I see that the Nextion Wemos (192.168.178.127) is sending http to itself. That is not supported. The Wemos NEXTION commands that originate from its own rules must use its serial port instead of the http.

As one example, on the Nextion Wemos device you would replace this rule line:

Code: Select all

SendToHTTP 192.168.178.127,80,/control?cmd=NEXTION,page0.bt0.val=0
with this:

Code: Select all

NEXTION,page0.bt0.val=0
Also, what is the reason for these two rules on the Wemos Nextion (IP 192.168.178.127) that are sent to itself?

Code: Select all

 SendToHTTP 192.168.178.127,80,/control?cmd=GPIO,12,0
 SendToHTTP 192.168.178.127,80,/control?cmd=GPIO,12,1
As mentioned, a device should not http to itself. If there is a GPIO-12 I/O controlled device on the Wemos then use direct GPIO statements instead.

- Thomas

User avatar
ManS-H
Normal user
Posts: 283
Joined: 27 Dec 2015, 11:26
Location: the Netherlands

Re: Nextion display plugin

#442 Post by ManS-H » 18 Nov 2018, 14:22

ThomasB wrote: 17 Nov 2018, 20:58
On theWemos with the Nextion display, IP: 192.168.178.127 i use this rule:
On RelayState do
if %eventvalue%=0
SendToHTTP 192.168.178.127,80,/control?cmd=NEXTION,page0.bt0.val=0
SendToHTTP 192.168.178.127,80,/control?cmd=GPIO,12,0
else
SendToHTTP 192.168.178.127,80,/control?cmd=NEXTION,page0.bt0.val=1
SendToHTTP 192.168.178.127,80,/control?cmd=GPIO,12,1
endif
endon
I see that the Nextion Wemos (192.168.178.127) is sending http to itself. That is not supported. The Wemos NEXTION commands that originate from its own rules must use its serial port instead of the http.

As one example, on the Nextion Wemos device you would replace this rule line:

Code: Select all

SendToHTTP 192.168.178.127,80,/control?cmd=NEXTION,page0.bt0.val=0
with this:

Code: Select all

NEXTION,page0.bt0.val=0
Also, what is the reason for these two rules on the Wemos Nextion (IP 192.168.178.127) that are sent to itself?

Code: Select all

 SendToHTTP 192.168.178.127,80,/control?cmd=GPIO,12,0
 SendToHTTP 192.168.178.127,80,/control?cmd=GPIO,12,1
As mentioned, a device should not http to itself. If there is a GPIO-12 I/O controlled device on the Wemos then use direct GPIO statements instead.

- Thomas
ThomasB, thanks for the tips. It let me learn more about rules.

The two rules with GPIO,12,0 and GPIO,12,1 was for me only a check if the rules works, thats all.

In my case Domoticz switched with timers the lights on/off in the livingroom.
The only thing what i want is a rule for a button that send a on/off command from the Nextion to, for example, the Sonoff Pow on 192.168.178.126

Then I can use the Nextion as a Remote Control.

Wiki
Normal user
Posts: 415
Joined: 23 Apr 2018, 17:55
Location: Germany

Re: Nextion display plugin

#443 Post by Wiki » 18 Nov 2018, 17:38

OK, the rules on the ESP12/Sonoff seem to be correct.

On your Nextion the Touch Release event should look like something like this:

Code: Select all

if(bt0.val==0)
{
  print "|s,i99,sOff"
  printh 0a
}else
{
  print "|s,i99,sOn"
  printh 0x0a
}
The term "i99" is interpreted by the Nextion plugin of ESPEasy as Nextion#idx
So on your Wemos you need these rules:

Code: Select all

on Nextion#idx=99 do
  if [Nextion#value]=1
    SendToHTTP 192.168.178.126,80,/control?cmd=gpio,12,1
  else
    SendToHTTP 192.168.178.126,80,/control?cmd=gpio,12,0
  endif
endon

On RelayState do
  if %eventvalue%=0
    NEXTION,page0.bt0.val=0
  else
    NEXTION,page0.bt0.val=1
  endif
endon
Should work...

Code: Select all

pi@raspberrypi:~ $ man woman
No manual entry for woman
pi@raspberrypi:~ $

User avatar
ManS-H
Normal user
Posts: 283
Joined: 27 Dec 2015, 11:26
Location: the Netherlands

Re: Nextion display plugin

#444 Post by ManS-H » 19 Nov 2018, 21:25

When i With Domoticz switch on/off the Sonoff Pow it works fine, it shows on the display the correct state.
Do i the same on the Nextion same result Pow on/ff and on the nextion the correct state.
When i switch on the Pow on Domoticz and off on the Nextion the Pow switched directly on again.
I believe the state of [Relay#State] and [Nextion#value] has a conflict with eachother.
But how to solve that.

Code on Sonoff Pow:

Code: Select all

On Relay#State do
 if [Relay#State]=0
      SendToHTTP 192.168.178.53,8080,/json.htm?type=command&param=udevice&idx=1534&nvalue=0&svalue=0 
      SendToHTTP 192.168.178.127,80,/control?cmd=event,RelayState=0 
else
      SendToHTTP 192.168.178.53,8080,/json.htm?type=command&param=udevice&idx=1534&nvalue=1&svalue=1    
      SendToHTTP 192.168.178.127,80,/control?cmd=event,RelayState=1
  endif
endon 
Code on Wemos with Nextion:

Code: Select all

on Nextion#idx=99 do
  if [Nextion#value]=1
    SendToHTTP 192.168.178.126,80,/control?cmd=gpio,12,1
else
    SendToHTTP 192.168.178.126,80,/control?cmd=gpio,12,0
  endif
endon

On RelayState do
  if %eventvalue%=0
    NEXTION,page0.bt0.val=0
    NEXTION,bt0.txt="Off"
    else
     NEXTION,page0.bt0.val=1
    NEXTION,bt0.txt="On"
  endif
endon

Wiki
Normal user
Posts: 415
Joined: 23 Apr 2018, 17:55
Location: Germany

Re: Nextion display plugin

#445 Post by Wiki » 20 Nov 2018, 13:31

Well for me it looks like a misbehaviour of the dual state button - hard to say without knowing the protocol of the wemos, but possible.

Let's try to get full control of the buttons behaviour in Nextion by the wemos.

So replace the dual state button in Nextion by a normal one. If its the first button it will be named b0 (instead of bt0 as name of a dual state button)

Add a variable to the page. If its the first variable it will be named va0.

In the following example codes replace the object names I am assuming by the correct names.

In the touch release event of the button place the action:

Code: Select all

if(va0.val==0)
{
  va0.val=1
  print "|s,i99,sOn"
  printh 0a
}else
{
  va0.val=0
  print "|s,i99,sOff"
  printh 0x0a
}
Define the following rules in the wemos:

Code: Select all

On Nextion#idx=99 do
  if [Nextion#value]=1
    SendToHTTP 192.168.178.126,80,/control?cmd=gpio,12,1
  else
    SendToHTTP 192.168.178.126,80,/control?cmd=gpio,12,0
  endif
endon

On RelayState do
  if %eventvalue%=1
    NEXTION,page0.b0.txt="On"
    NEXTION,page0.b0.bco=1024
    NEXTION,page0.va0.val=1
  else
    NEXTION,page0.b0.txt="Off"
    NEXTION,page0.b0.bco=48631
    NEXTION,page0.va0.val=0
  endif
endon
If the wemos is rebooted the button might not show the correct state but after the first action of the relay it will be and stay correct. To avoid this you might define an additional pair of request and answer rules between wemos and sonoff for getting the correct state of the relay during boot time of the wemos and setting the button state in Nextion accordingly.

Code: Select all

pi@raspberrypi:~ $ man woman
No manual entry for woman
pi@raspberrypi:~ $

User avatar
ManS-H
Normal user
Posts: 283
Joined: 27 Dec 2015, 11:26
Location: the Netherlands

Re: Nextion display plugin

#446 Post by ManS-H » 21 Nov 2018, 12:58

Thanks Wiki,

Yesterday morning i found the same solution with the trail and error method. It works for me good enough.
I saw the same thing with working with your code and my code.
When i start the Sonoff Pow from Domoticz and i will stop it on the Nextion i must sometimes press the button twice.
That's depend of the state of the variable on the Nextion. But I can live with it.

Thanks for your help, it was a learning period for me.

Wiki
Normal user
Posts: 415
Joined: 23 Apr 2018, 17:55
Location: Germany

Re: Nextion display plugin

#447 Post by Wiki » 21 Nov 2018, 18:19

You're welcome, good to hear it works.
ManS-H wrote: 21 Nov 2018, 12:58 [...]
When i start the Sonoff Pow from Domoticz and i will stop it on the Nextion i must sometimes press the button twice.
That's depend of the state of the variable on the Nextion.
[...]
I have already seen a similar behaviour of my Netxion. I think its a timing problem of the serial connection between your Wemos and the Nextion because the variable - at least in my example - is set to the correct value because the Sonoff should trigger the event RelayState on the Wemos if switched on by Domoticz.

I solved this issue by switching to hard serial using GPIO3 and GPIO1 (on Wemos board these are the RX/TX pins) for connecting the Nextion and chose 115200 baud speed.

Code: Select all

pi@raspberrypi:~ $ man woman
No manual entry for woman
pi@raspberrypi:~ $

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Nextion display plugin

#448 Post by grovkillen » 21 Nov 2018, 18:24

Wiki wrote: 21 Nov 2018, 18:19 You're welcome, good to hear it works.
ManS-H wrote: 21 Nov 2018, 12:58 [...]
When i start the Sonoff Pow from Domoticz and i will stop it on the Nextion i must sometimes press the button twice.
That's depend of the state of the variable on the Nextion.
[...]
I have already seen a similar behaviour of my Netxion. I think its a timing problem of the serial connection between your Wemos and the Nextion because the variable - at least in my example - is set to the correct value because the Sonoff should trigger the event RelayState on the Wemos if switched on by Domoticz.

I solved this issue by switching to hard serial using GPIO3 and GPIO1 (on Wemos board these are the RX/TX pins) for connecting the Nextion and chose 115200 baud speed.
Totally agree, nextion should always use hardware serial. I have seen problems over time when bit banging the S8 sensor. Using hardware serial works "forever".
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

User avatar
ThomasB
Normal user
Posts: 1214
Joined: 17 Jun 2018, 20:41
Location: USA

Re: Nextion display plugin

#449 Post by ThomasB » 21 Nov 2018, 19:09

+1: Hardware serial.

Hardware serial is needed for ESPEasy to reliably receive Nextion touch screen button presses. If the Nextion is only used as a display (touch feature not used) then soft serial is fine.

- Thomas

User avatar
ManS-H
Normal user
Posts: 283
Joined: 27 Dec 2015, 11:26
Location: the Netherlands

Re: Nextion display plugin

#450 Post by ManS-H » 21 Nov 2018, 19:31

Wiki wrote: 21 Nov 2018, 18:19 You're welcome, good to hear it works.
ManS-H wrote: 21 Nov 2018, 12:58 [...]
When i start the Sonoff Pow from Domoticz and i will stop it on the Nextion i must sometimes press the button twice.
That's depend of the state of the variable on the Nextion.
[...]
I have already seen a similar behaviour of my Netxion. I think its a timing problem of the serial connection between your Wemos and the Nextion because the variable - at least in my example - is set to the correct value because the Sonoff should trigger the event RelayState on the Wemos if switched on by Domoticz.

I solved this issue by switching to hard serial using GPIO3 and GPIO1 (on Wemos board these are the RX/TX pins) for connecting the Nextion and chose 115200 baud speed.
i used from the beginning a hard serial with GPIO13 and GPIO15.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest