Trying to get a button on LCD2004 to display other data Topic is solved

Moderator: leecollings

Post Reply
User avatar
RonkA
Posts: 115
Joined: Tuesday 14 June 2022 12:57
Target OS: NAS (Synology & others)
Domoticz version: 2025.1
Location: Harlingen
Contact:

Trying to get a button on LCD2004 to display other data

Post by RonkA »

Hello, all.

I'm trying to get a lcd display to work with Domoticz.
IMG_20221223_134503.jpg
IMG_20221223_134503.jpg (49.41 KiB) Viewed 4555 times
It's an 2004a display working via I2c on a ESP8266 board running ESP Easy getting updated every 20 seconds.
Sofarsogood...
The problem i get is this; sometimes the first line is not displaying and gives a blank line instead.
It gets worse if i send more items to the display;

I use the 'openurl' command to send the text, because it cannot send space's to the display i have to use underscores instead of space.
The more elegant way is to send the lines in parts to the correct place in the line;
For the top line i would send "gebruik" from position 2, then send "huis=<value>" from position 5.

So 2 times to send 1 line to the display, repeating for the other lines is a lot of extra times sending to the ESP board at once.

This is the part of the script responsible for getting the text to the display:

Code: Select all

commandArray[35] = {['OpenURL']="http://192.168.178.220/control?cmd=lcd,1,2,Gebruik_huis=".. math.floor(consumption_p).."W" }
commandArray[36] = {['OpenURL']="http://192.168.178.220/control?cmd=lcd,2,3,Zonepanelen=".. math.floor(solar_p) .. "W" }
commandArray[37] = {['OpenURL']="http://192.168.178.220/control?cmd=lcd,3,5,KWH_meter=".. math.floor(consumption_tot).."W" }
commandArray[40] = {['OpenURL']="http://192.168.178.220/control?cmd=lcd,4,2,"..HM.."" }
Gives this in the log:

Code: Select all

2022-12-23 14:33:41.185 Status: EventSystem: Fetching URL http://192.168.178.220/control?cmd=lcd,2,3,Zonepanelen=5W after 0.2 seconds...
2022-12-23 14:33:41.185 Status: EventSystem: Fetching URL http://192.168.178.220/control?cmd=lcd,3,5,KWH_meter=760W after 0.2 seconds...
2022-12-23 14:33:41.185 Status: EventSystem: Fetching URL http://192.168.178.220/control?cmd=lcd,4,2,14:33__Fri_23_Dec after 0.2 seconds...
2022-12-23 14:33:41.185 Status: EventSystem: Fetching URL http://192.168.178.220/control?cmd=lcd,1,2,Gebruik_huis=765W after 0.2 seconds...
Even these 4 commands give this strange order in the log and sometimes results in a loss of line ..

Is there a way to get the next send-command to pause for say 50ms to finish the action?

Greets Ron.
Last edited by RonkA on Wednesday 18 January 2023 11:53, edited 2 times in total.
SolarEdge ModbusTCP - Kaku - Synology NAS - Watermeter - ESPEasy - DS18b20
Work in progress = Life in general..
zicht
Posts: 272
Joined: Sunday 11 May 2014 11:09
Target OS: Windows
Domoticz version: 2023.1+
Location: NL
Contact:

Re: How to pause or wait in script

Post by zicht »

Hi Ron

Introducing a wait would slow down all your lua action including domoticz itself.

1. You can read return values with io.popen to run a curl. then make diffrend scripts with a number in their name.
They will be fired after eachother and each script will make domoticz wait to end the script= having a return value

2. Maybe a better way to write values to a file outside domoticz
and have there some actions done , if needed with the wanted wait ?

I write some text files and send them by curl in a timed script every minute to another device (basucaly the same concept)

3. another way is using a device fired script, but ony send data on fixed seconds
eg. if 0<seconds<10 then action 1 , if 11<seconds<20 then action2 and so on.
You need to be aware that when nothing changes the scipt is not fired. Thats why i suggest to take a 10 sec window

i use this mechanism to do some actions twice a minute.

Be aware that you can slow down domoticz siginificant by wrong lua use and you can even create nasty loops.
For that reason i am using python or powershell a lot to avoid timing issues.

I hope to give you an idea on how to solve your problem ...
Rpi & Win x64. Using : cam's,RFXCom, LaCrosse, RFY, HuE, google, standard Lua, Tasker, Waze traveltime, NLAlert&grip2+,curtains, vacuum, audioreceiver, smart-heating&cooling + many more (= automate all repetitive simple tasks)
User avatar
RonkA
Posts: 115
Joined: Tuesday 14 June 2022 12:57
Target OS: NAS (Synology & others)
Domoticz version: 2025.1
Location: Harlingen
Contact:

Re: How to pause or wait in script

Post by RonkA »

Thanks for the reply, the problem i have with python (and dzVents) is that my Domoticz runs on synology in docker and i am not able to get these type of scripts to work -Yet...- (NOOB am I)

One thing i have sort of managed to clear up,

Code: Select all

commandArray[20] = {['OpenURL']="http://192.168.178.220/control?cmd=lcd,1,2,Gebruik_huis=".. math.floor(consumption_p).."W" }
commandArray[21] = {['UpdateDevice'] = dummymeter_id14 .. "|0|" .. math.floor(nettot_terug) .. ";" .. (nettot_terug/1000)}
commandArray[25] = {['OpenURL']="http://192.168.178.220/control?cmd=lcd,2,3,Zonepanelen=".. math.floor(solar_p) .. "W" }
commandArray[26] = {['UpdateDevice'] = dummymeter_id15 .. "|0|" .. math.floor(nettot_verbr) .. ";" .. (nettot_verbr/1000)}	 
commandArray[30] = {['OpenURL']="http://192.168.178.220/control?cmd=lcd,3,5,KWH_meter=".. math.floor(consumption_tot).."W" }
commandArray[35] = {['OpenURL']="http://192.168.178.220/control?cmd=lcd,4,2,"..HM.."" }
I just stuck 2 other commandArrays inbetween these and result..

Code: Select all

2022-12-23 19:28:05.878 Status: EventSystem: Fetching URL http://192.168.178.220/control?cmd=lcd,1,2,Gebruik_huis=2351W after 0.2 seconds...
2022-12-23 19:28:05.880 Status: EventSystem: Fetching URL http://192.168.178.220/control?cmd=lcd,2,3,Zonepanelen=0W after 0.2 seconds...
2022-12-23 19:28:05.882 Status: EventSystem: Fetching URL http://192.168.178.220/control?cmd=lcd,3,5,KWH_meter=2351W after 0.2 seconds...
2022-12-23 19:28:05.882 Status: EventSystem: Fetching URL http://192.168.178.220/control?cmd=lcd,4,2,19:28__Fri_23_Dec after 0.2 seconds...
But still sometimes missing 1st line, so maybe the cause is something else.
It's irritating but not live-threatening.. :roll:
SolarEdge ModbusTCP - Kaku - Synology NAS - Watermeter - ESPEasy - DS18b20
Work in progress = Life in general..
User avatar
RonkA
Posts: 115
Joined: Tuesday 14 June 2022 12:57
Target OS: NAS (Synology & others)
Domoticz version: 2025.1
Location: Harlingen
Contact:

Re: How to pause or wait in script

Post by RonkA »

Little update;
The missing 1st line of the text is solved.

After looking in the log of the ESP8266 i found that the 4 lines i send from Domoticz are received in random order every time, so it doesnt matter if the order of sending is off.
Searching on i found the following:
display2004.jpg
display2004.jpg (18.9 KiB) Viewed 4503 times
Notice the cross, what that meant is that the line was not empty, it contained a 'space' and this line was printed every 60 seconds..
So clearing the line solved this problem..
Sending more than 4 lines at once still gives dropouts of text on the display so sending every word is still not an option.

The other problem; sending spaces to the display,'<ip>/control?cmd=LCD,1,1,hello everybody' displays 'hello',
Spaces cannot be a part of the message so for the space i use % 20 but gives the same outcome as above.

Looking at the log in ESP8266 the message received is 'hello everybody', the correct sentence, so the problem lies in the display software..
To get it to work i use underscore as space so '<ip>/control?cmd=LCD,1,1,hello_everybody' displays 'hello_everybody', not that pretty but it is what it is..
SolarEdge ModbusTCP - Kaku - Synology NAS - Watermeter - ESPEasy - DS18b20
Work in progress = Life in general..
User avatar
bewo
Posts: 74
Joined: Monday 13 July 2015 12:27
Target OS: Linux
Domoticz version: 2021.1
Location: Bavaria - Germany
Contact:

Re: How to pause or wait in script

Post by bewo »

Hi RonkA,

I don't know if tips are still necessary but an idea to pause the command would to NOT use the OpenURL-command.
The nicest way would to use "curl" but the tool isn't included in the standard-Synology Package. An other way is to use wget. :)

So you could do something like:

Code: Select all

URLcall = "wget -q -O- http://192.168.178.220/control?cmd=lcd,"
Line_1 = "1,2,Gebruik_huis="..math.floor(consumption_p).."W"
Line_2 = "2,3,Zonepanelen="..math.floor(solar_p).."W"
Line_3 = "3,5,KWH_meter="..math.floor(consumption_tot).."W"
Line_4 = "4,2,"..HM
Pause = ' && sleep 0.3 && ' -- Wait for 0.3 Seconds

os.execute(URLcall..Line_1..Pause..URLcall..Line_2..Pause..URLcall..Line_3..Pause..URLcall..Line_4)
This would fire this example command (i've set the calculated values to 1234):
In this way you should also be able to send words to the right position if there really really really is no way to send an space.
You've written "% 20" in your last post. Is this only an typo?
If it isn't an typo: The code for the space is %20 without an space. So for example if you would write "Gebruik huis" you have to send "Gebruik%20huis" without any spaces.
Individual projects:
Domoticz on a Intel Xeon Server | AeonLabs Z-Wave Gen.5 | RFXCOM RFXtrx433E USB | ESP-Wifi-Modules | Shellys
Wall-mounted 22" Touch Control Display (self construct) | LUA wind monitor| LUA heating control | and many many more :)
zicht
Posts: 272
Joined: Sunday 11 May 2014 11:09
Target OS: Windows
Domoticz version: 2023.1+
Location: NL
Contact:

Re: How to pause or wait in script

Post by zicht »

Hi

Take a look at https://www.domoticz.com/wiki/LUA_commands

Code: Select all

commandArray[#commandArray + 1]={["<sensor or command like open url>']='something AFTER 23'} 
commandArray[#commandArray + 1]={["<sensor2 or command2 like open url>']='something AFTER 46'} 
could do the trick, but i did not test it .... so you have to try....
AFTER sets a delay of x seconds to execute the command array line
the commandarray thingy is because it can do only one thing at once, newly with the same name will be overwritten in the array.
So two similar need to have their own specific line in the array.... Hope it makes sense. Difficult to explain in englisch

This is not the case for openurl right now however it can be handy in future to know the possibility
Rpi & Win x64. Using : cam's,RFXCom, LaCrosse, RFY, HuE, google, standard Lua, Tasker, Waze traveltime, NLAlert&grip2+,curtains, vacuum, audioreceiver, smart-heating&cooling + many more (= automate all repetitive simple tasks)
User avatar
bewo
Posts: 74
Joined: Monday 13 July 2015 12:27
Target OS: Linux
Domoticz version: 2021.1
Location: Bavaria - Germany
Contact:

Re: How to pause or wait in script

Post by bewo »

Hi zicht,

Ronka is already using the array of commands... ;)

He uses
commandArray[28] = ....
commandArray[29] = ....
commandArray[30] = ....
commandArray[35] = ....
and so on. In this way the order is easyliy recognizable. But you have to pay attention at programming.

Your posted command does the same. It begin's with the first command in array at position "0" and calculate.
#commandArray ist the actual sum and then plus 1.
So the following
commandArray[#commandArray + 1] = ....
commandArray[#commandArray + 1] = ....
commandArray[#commandArray + 1] = ....
commandArray[#commandArray + 1] = ....
results in:
commandArray[1] = ....
commandArray[2] = ....
commandArray[3] = ....
commandArray[4] = ....
Individual projects:
Domoticz on a Intel Xeon Server | AeonLabs Z-Wave Gen.5 | RFXCOM RFXtrx433E USB | ESP-Wifi-Modules | Shellys
Wall-mounted 22" Touch Control Display (self construct) | LUA wind monitor| LUA heating control | and many many more :)
User avatar
RonkA
Posts: 115
Joined: Tuesday 14 June 2022 12:57
Target OS: NAS (Synology & others)
Domoticz version: 2025.1
Location: Harlingen
Contact:

Re: How to pause or wait in script

Post by RonkA »

This post is now obsolete, i found a workaround to display wat i wanted in the 1st place.
display.jpg
display.jpg (102.68 KiB) Viewed 4426 times
I use the ESP to display the static text in the lines so this can have the spaces without problems.
Because the ESP erases the whole display with the static text every refresh the interval is now set to 600 seconds.
The values are blank at this moment but this is for max 20 seconds before Domoticz sends the new values.
The 4th line has the date comming from the ESP, the time comes from Domoticz.
display2.jpg
display2.jpg (152.26 KiB) Viewed 4426 times
SolarEdge ModbusTCP - Kaku - Synology NAS - Watermeter - ESPEasy - DS18b20
Work in progress = Life in general..
User avatar
RonkA
Posts: 115
Joined: Tuesday 14 June 2022 12:57
Target OS: NAS (Synology & others)
Domoticz version: 2025.1
Location: Harlingen
Contact:

Re: How to pause or wait in script

Post by RonkA »

Another update; Now the workaround is obsolete..

I found the answer to the <%20> probem;
When i was trying to get ℃ to display, I looked in the ESP/tools/system variables to see what the url encoded value would be.
What I found is that <%c2%b0> would get the right caracter, only i got a different caracter displayed.
So i searched and found a caracter matrix for the lcd 2004:
Knipsel.JPG
Knipsel.JPG (81.11 KiB) Viewed 4403 times
The right hex value to get the little o caracter is Binair 11111101= %FD..and this works as it should.
In the matrix are some emty caracters, i chose binair: 11111110= %FE.. and there is the space..
All the workarounds are not necessary anymore.
:) :) :)
But then i wanted an upgrade: other lines with data after a buttonpush.

I have added a phisical button to the esp, set it up so it registers in Domoticz and with some help from openai got a dzVens-script working to display other textlines with other values.

I will start another threat for the next part: viewtopic.php?t=39787
SolarEdge ModbusTCP - Kaku - Synology NAS - Watermeter - ESPEasy - DS18b20
Work in progress = Life in general..
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest