LCD2004

Moderators: grovkillen, Stuntteam, TD-er

Message
Author
User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

Re: LCD2004

#51 Post by Ath » 16 May 2021, 17:02

bonti69 wrote: 16 May 2021, 16:27 PS: tried "LCD,1,1,DateTime" but does not display "Datetime:2021-05-16 17:43:41" which results in console, only "Datetime"...what's the correct synthax?
Or: let,1,Datetime ...then LCD,1,1,[var#1]
''The <text> parameter must be a single command parameter. Meaning, it must be wrapped in quotes when using a space or comma as text.

If double quote characters are needed, wrap the parameter in single quotes or back quotes.

All template notations can be used, like system variables, or reference to a task value.''
In the "on system#boot do" event the initial text "System time %systime%" is displayed, and in the "on rules#timer=4 do" only the time is overwritten with the current time
I copied both events here so you can easily find them.

Code: Select all

on rules#timer=4 do // Called often so placed at top
  if %v1%=1 // If display is on
    if %v2%=0 and %v4%=1
	  asyncEvent,DisplaySet1 // Add to queue
    endif
    if %v2%=1 and %v5%=1
	  asyncEvent,DisplaySet2 // Add to queue
    endif
    LCD,4,13,"%systime%" // update time only on line 4
  endif
endon


on system#boot do
  lcdcmd,clear
  event,switch#state=1 // display on and start timer (time-out disabled)
  let,2,1 // second mode
  event,switch#state=11 // flip mode showing 1st set, start time-out timer
  LoopTimerSet,4,1 // 1 second timer
  LCD,4,1,"System time %systime%" // Show time on line 4
endon


NB: Just found a few small typo's in my code (I forgot to add the standard disclaimer: Untested code!), but I've fixed them here (can't seem to edit the previous post, for some reason :o ).

The "on rules#timer=4 do" event should be replaced by the one that's here, there are a few 'endon' statements where an 'endif' should be.
/Ton (PayPal.me)

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: LCD2004

#52 Post by TD-er » 16 May 2021, 20:15

@Ath:
Editing a post older than 48h has been deleted since spammers do that a lot.
They first post something slightly related or just a "Thanks nice post" and then days/weeks later they change it into spam links to some casino, essay writing services, etc.

About using GPIO-16 as a push button.
Please be aware that GPIO-16 cannot be used via interrupts, so you cannot have a callback function monitoring GPIO-16.

@bonti69:
I don't think Ath meant to say with "it is all software so everything is possible" that you need to change it yourself.
It was probably meant as an encouragement to let your imagination go wild :) (or at least don't hold back on your imagination, thinking it might not be possible)

bonti69
Normal user
Posts: 119
Joined: 08 Apr 2021, 12:16

Re: LCD2004

#53 Post by bonti69 » 16 May 2021, 21:36

Ath wrote: 16 May 2021, 17:02

In the "on system#boot do" event the initial text "System time %systime%" is displayed, and in the "on rules#timer=4 do" only the time is overwritten with the current time
I copied both events here so you can easily find them.

Code: Select all

on rules#timer=4 do // Called often so placed at top
  if %v1%=1 // If display is on
    if %v2%=0 and %v4%=1
	  asyncEvent,DisplaySet1 // Add to queue
    endif
    if %v2%=1 and %v5%=1
	  asyncEvent,DisplaySet2 // Add to queue
    endif
    LCD,4,13,"%systime%" // update time only on line 4
  endif
endon


on system#boot do
  lcdcmd,clear
  event,switch#state=1 // display on and start timer (time-out disabled)
  let,2,1 // second mode
  event,switch#state=11 // flip mode showing 1st set, start time-out timer
  LoopTimerSet,4,1 // 1 second timer
  LCD,4,1,"System time %systime%" // Show time on line 4
endon


NB: Just found a few small typo's in my code (I forgot to add the standard disclaimer: Untested code!), but I've fixed them here (can't seem to edit the previous post, for some reason :o ).

The "on rules#timer=4 do" event should be replaced by the one that's here, there are a few 'endon' statements where an 'endif' should be.
My little project is:
when a switch#state=1 then send to Lcd command on and display something like :

line1 : WARNING
line2 : "Firealarm ON %systime%"
//actually I want something like : Firealarm ON %date&time% aka Datetime:2021-05-16 21:35:09 (this results from Datetime command in console, %systime% is only time)
line3 : "CHECK SOMETHING"
line4 : ""Firealarm OFF %systime%"

The code:

Code: Select all

on switch#state=1 do
lcdcmd,on
LCD,1,1,"WARNING"
LCD,2,1,"Firealarm ON %systime%"
LCD,3,1, "CHECK WATER PUMPS"
endon
on switch#state=0 do
LCD,4,1,"Firealarm OFF %systime%"
on pushbutton#state=1 do //or double click/longpress for example
lcdcmd,off
lcdcmd,clear
endon


This project could be useful to monitor some switch,hardware connected to: intrusion alarm, doorswitch, firealarm, pump, whatever and give a permanent warning message to LCD , until some supervisor turn off the lcd with a pushbutton connected to same device.
The real configuration will be 2 devices connected somehow, same lan via http or same mqtt server.One device will have a hardware switch to monitor fire,intrusion or pump, and the other device ,on remote location will have the display in some monitoring room, maintenance bureau etc. and a task as virtualswitch to command the LCD.
Well, at last,the issue is how to display on lcd "date & time" , not only system time
datetime command.png
datetime command.png (13.32 KiB) Viewed 6296 times
lcd datetime.png
lcd datetime.png (10.87 KiB) Viewed 6296 times

bonti69
Normal user
Posts: 119
Joined: 08 Apr 2021, 12:16

Re: LCD2004

#54 Post by bonti69 » 16 May 2021, 21:55

TD-er wrote: 16 May 2021, 20:15

@bonti69:
I don't think Ath meant to say with "it is all software so everything is possible" that you need to change it yourself.
It was probably meant as an encouragement to let your imagination go wild :) (or at least don't hold back on your imagination, thinking it might not be possible)
@TD-er
Is there on the forum, a place to share our struggles, some database with tested,working projects where can be loaded for ethernity, for our succesors, in some simple recipies: hardware,config files,rules,pictures. Apropos, very frustrating to save/upload the configuration file , (File MUST be renamed to "config.dat" before upload!), save /upload the rules separately...Make it doable like some vaccine, one shot :P...here begun my struggles with ESP,yet still uncured disease https://github.com/arendst/Tasmota/issues/905

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: LCD2004

#55 Post by TD-er » 16 May 2021, 22:38

Nope not yet.
In the past the Wiki was intended to be something like this, but the problem is -as always- that those described steps might become outdated.
So if you look at the wiki, then you'll find a lot of descriptions which may no longer work exactly as described back then.

User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

Re: LCD2004

#56 Post by Ath » 17 May 2021, 07:54

bonti69 wrote: 16 May 2021, 21:36 Well, at last,the issue is how to display on lcd "date & time" , not only system time
Check out the Tools/System Variables page (on your ESP's web interface) for all available variables you can use on the display. You are looking for %lcltime% I presume? If that's not the desired format you can use the %sys...% variables to create your own layout.
/Ton (PayPal.me)

bonti69
Normal user
Posts: 119
Joined: 08 Apr 2021, 12:16

Re: LCD2004

#57 Post by bonti69 » 17 May 2021, 10:23

Thanks
Yes, %lcltime% is what I wanted, but needs a full row on LCD, so I stay on %systime%

User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

Re: LCD2004

#58 Post by Ath » 17 May 2021, 10:52

And if you add %sysday_0% %sysmonth_0% just before that %systime% ? it will only take 5 positions for the day/month
/Ton (PayPal.me)

bonti69
Normal user
Posts: 119
Joined: 08 Apr 2021, 12:16

Re: LCD2004

#59 Post by bonti69 » 17 May 2021, 11:10

ENHANCED lcd2004 PROJECT
Scope: Warning message on LCD screen from a remote device connected to a residential alarm,fire alarm,water pump ,doorswitch etc...
One ESP device has attached a hardware switch, switch#state. It's on remote location,another site,building or another town.
Other one ESP has a task named virtualswitch and a LCD 2004 attached
The two devices communicate eachother, via http command if it's in the sama Lan, or via mqtt/internet.
The virtualswitch of the local device replicate the state of hardware switch of remote device (via http or mqtt)
The code:

Code: Select all

on system#boot do
lcdcmd,off
lcdcmd,clear
endon
on Virtualswitch#state=1 do
lcdcmd,on
LCD,1,1,"WARNING"
LCD,2,1,"Pump ON %systime%"
LCD,3,1, "CHECK WATER PUMPS"
endon
on Virtualswitch#state=0 do
LCD,4,1,"Pump OFF %systime%"
endon
When remote switch activate:
pump1.jpeg
pump1.jpeg (47.27 KiB) Viewed 6275 times
When remote switch deactivate:
pump2.jpeg
pump2.jpeg (56.6 KiB) Viewed 6275 times
While LCD stays off everything it's OK, when LCD shines ,something happened, go check what and when.LCD 2004 it's large enough and visible,fit in a proper place...
Of course we can use same LCD to monitor more than one remote switch...LCD will log the event
Advanced use:
The local ESP device with LCD could also have a i2c sensor for monitoring temp,hum,baro, and a pushbutton used as "display button", for 15s ...When remote switch activates the warning message will override the display. A doubleclick or longpress on pushbutton will reset the warning message and return to weather station
WhatsApp Image 2021-05-05 at 22.47.05.jpeg
WhatsApp Image 2021-05-05 at 22.47.05.jpeg (86.11 KiB) Viewed 6272 times

bonti69
Normal user
Posts: 119
Joined: 08 Apr 2021, 12:16

Re: LCD2004

#60 Post by bonti69 » 20 May 2021, 12:52

Is there any command to disable parameter "interval" of LCD2004 plugin? Or modifying via some rule? Because does not accept value 0.Only more than 1.And maximum around 65235. "0" will be non-refreshing data on display. Load once the Lines with text and stays forever...
Question 2: The "display timeout" can be disabled or set via some command,some rule? Maximum timeout seems to be around 32600.Minimum is 0, aka never...
It would be useful when The LCD displays usually some variables,temp,hum,pressure, with refresh interval set and display timeout, and ,at certain time, you send some specific message to LCD, and wants to stay on,freeze the message and backlight...
Notice:
LCD command works also with http://192.168.4.32/control?cmd=LCD,4,1,Pompa ...diplays Pompa on line 4. But does not wake up backlight. http://192.168.4.32/control?cmd=LCD,4,1,Pompa%systime% only display "Pompa"
Can be used one http command to multiple lines?
Seems like the command lcdcmd,on or http://192.168.4.32/control?cmd=lcdcmd,on starts the backlight, and somehow disable display timeout.Backlight remains on after command.
Last edited by bonti69 on 20 May 2021, 15:20, edited 5 times in total.

User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

Re: LCD2004

#61 Post by Ath » 20 May 2021, 13:09

If you read back up a few messages, I already provided a solution for that, where the timer is set to either 15 or 60 seconds, depending on the set of data to be displayed. You can easily extend that for a 3rd case where the message should stay indefinitely (setting the timer to 0).
The timeout, and button, should then not be configured at the LCD device, only controlled from rules.
/Ton (PayPal.me)

bonti69
Normal user
Posts: 119
Joined: 08 Apr 2021, 12:16

Re: LCD2004

#62 Post by bonti69 » 20 May 2021, 13:29

Yes,Ath
Starting from one blank LCD task, nothing on lines,no timeout,no interval set...YOU can do what you want,almost anything,almost everything ;)
I started from lcdtemp, a valid task, with interval & timeout, and send some warning text via rule...I solved the problem with two tasks, I know you don't like it...Maybe downthere,inside the plugin,is there some %var% ,which can be easily modified by rule command...In that case, a standalone lcd task,easy manageable via webui, will be overriden with a little rule,no need timers,variables,skill

User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

Re: LCD2004

#63 Post by Ath » 20 May 2021, 15:52

It is not possible to change task settings, like you want to change, from the rules. That could be a feature request, so you could create one in the ESPEasy issue-tracker in Github if you like.
/Ton (PayPal.me)

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: LCD2004

#64 Post by TD-er » 20 May 2021, 16:40

Maybe a bit "out of the box", but would it also help your use case to enable/disable the task?
Then you can turn on the LCD task in a rule, acting on a GPIO event (in the rules) and set a timer to disable the task.

bonti69
Normal user
Posts: 119
Joined: 08 Apr 2021, 12:16

Re: LCD2004

#65 Post by bonti69 » 20 May 2021, 18:19

Improvement LCD2004 backlight
Add a small resistor 560 ohm to 1kohm between K (cathode of LED backlight) and ground. The backlight will lit softly, enough to see display ,indoor. When lcdcmd,on is applied, the full brightness is enabled,internal transistor will short the added resistor. Risk-free...Eco-friendly: 0.5W with dim backlight, 0.75W full backlight.
20210520_184838.jpg
20210520_184838.jpg (546.31 KiB) Viewed 6163 times
Last edited by bonti69 on 20 May 2021, 23:46, edited 2 times in total.

bonti69
Normal user
Posts: 119
Joined: 08 Apr 2021, 12:16

Re: LCD2004

#66 Post by bonti69 » 20 May 2021, 18:43

TD-er wrote: 20 May 2021, 16:40 Maybe a bit "out of the box", but would it also help your use case to enable/disable the task?
Then you can turn on the LCD task in a rule, acting on a GPIO event (in the rules) and set a timer to disable the task.
I have already 3 task with LCD2004:
lcdtemp with temperatures,humid,pressure, timeout 15s, display button = gpio 16 shortpress
lcdina with current,voltage,power from sensor INA219, timeout 120s, display button = gpio 16 shortpress
lcdalarm , no text lines (will be loaded by rule), no display button, timeout =0 (disabled), interval set to maximum, 60000s, aka 18hours for display emergency/warning message
gpio 16 longpress will disable lcdtemp and enable lcdina task and viceversa
gpio15 ,external driven via mqtt or http, will disable lcdtemp,lcd ina and enable lcdalarm,load warning screen and lock until gpio 16 doubleclick will disable lcdalarm/enable lcdtemp, back to "normal life"
Notice: lcdcmd,on will lighten screen and remains on,regardless display timeout, which is good,last command executed
All this can be written in rules, as Ath suggested but,for me,at the moment was convenient to use three task and some little rules enable/disable task.
Last edited by bonti69 on 21 May 2021, 00:07, edited 3 times in total.

bonti69
Normal user
Posts: 119
Joined: 08 Apr 2021, 12:16

Re: LCD2004

#67 Post by bonti69 » 20 May 2021, 19:09

Ath wrote: 20 May 2021, 15:52 It is not possible to change task settings, like you want to change, from the rules. That could be a feature request, so you could create one in the ESPEasy issue-tracker in Github if you like.
Feature request:
Interval : from 1 to 65535. "O" is not allowed ,meaning never. Or accept more than 65535, 18 hours. So message will be locked, for longer time. Let it be 14 days, 1.209.600 sec,in case device is placed in some less frequented location.Or when the owner is away from home,longtime,vacation. Needed when a task is created especially for "ALERT" display. Surely will not burden the code, I believe...Also will reduce cpu load and i2c bus
Add more command for LCD plugin:
I tested http://<ipaddress>/control?cmd=LCD,<row>,<col>,<text> and works as expected. Maybe some concatenated command to fill all the lines via one http send,separated by semicolon.Or maybe a full lcd code, launched via a single http command...
Accept http://<ipaddress>/control?cmd=LCD,<row>,<col>,<%lcltime% or %systime% or any internal variable>
Add lcd, <timeout> command
Add lcd, <refresh interval> command, for fast/slow screen refresh, mostly for locking screen or quick refresh in some cases,fast reading. My lcdina task has 1s interval for fast reading values, during measurements
Add one more parameter on every line of text : flashing interval = 0 (steady), 1 (1s display line text/1s blank)...blink text line for effects , alerts/ex. temp < or > given value, switch changes state etc. some timer,time event
Maybe Ath can take a look and figure what's doable...then I make a "official" feature request
THX
Last edited by bonti69 on 20 May 2021, 23:53, edited 1 time in total.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: LCD2004

#68 Post by TD-er » 20 May 2021, 21:18

Settings.TaskDeviceTimer is an unsigned long, so it is a 32 bit value.
We could extend the max allowed value, or use the unused bits for extra flags.
Maybe we could add some flags like "no interval" or maybe other options.

bonti69
Normal user
Posts: 119
Joined: 08 Apr 2021, 12:16

Re: LCD2004

#69 Post by bonti69 » 20 May 2021, 22:42

TD-er wrote: 20 May 2021, 21:18 Settings.TaskDeviceTimer is an unsigned long, so it is a 32 bit value.
We could extend the max allowed value, or use the unused bits for extra flags.
Maybe we could add some flags like "no interval" or maybe other options.
Switch plugin accept interval '0' value, aka non refresh..."no interval" will be just fine, or extend, what's easier...
Attachments
sw.png
sw.png (16.58 KiB) Viewed 6168 times

bonti69
Normal user
Posts: 119
Joined: 08 Apr 2021, 12:16

Re: LCD2004

#70 Post by bonti69 » 20 May 2021, 23:25

@Ath
Please take a look at the code below. I want to make the backlight on and off intermittently, 1s period, when a switch change state. Seems a little too long ,for such a small job. Is there a better way,shorter,simpler? looptimer?

Code: Select all


on switch#state=1 do
timerSet,3,1
let,3,=!%v3% // flip state
if %v3%=1
lcdcmd,on
else 
lcdcmd,off
endif
endon

On Rules#Timer=3 do
let,3,=!%v3% // flip state
if %v3%=1
lcdcmd,on
else 
lcdcmd,off
endif
timerSet,3,1
endon
on switch#state=0 do // stop blinking
timerSet,3,0
endon
Is there a command to enable/disable ruleset? Would be nice to have a "button" with tick enable/disable each rule . Also access to rule status as variable,in code,via http etc. RuleSet<x>#state or something...
Ruleset1,0 = disable ruleset1 ... Ruleset1,1 = enable ruleset1
http://<ipaddress>/control?cmd=Ruleset1,1 ... launch a rule remotely
Could be useful,for example , to activate backlight blinking, with a simple command to enable/disable a rule. Not need to embed inside a large code,making things easier to mantain...
(Tasmota sniff: rule1,on...rule2,off...rule3,1...rule4,0 )

bonti69
Normal user
Posts: 119
Joined: 08 Apr 2021, 12:16

Re: LCD2004

#71 Post by bonti69 » 22 May 2021, 00:08

Code for turn on/off backlight of lcd, 3sec period:

Code: Select all

on System#Boot do
loopTimerSet,1,3
endon

On Rules#Timer=1 Do
let,1,=!%v1%
if %v1%=1
 lcdcmd,on
else 
lcdcmd,off
endif 
endon
Simple bistable of a gpio, every 3sec

Code: Select all

on System#Boot do
loopTimerSet,2,3
endon

On Rules#Timer=2  Do
gpiotoggle,5
endon

Post Reply

Who is online

Users browsing this forum: No registered users and 37 guests