ESPEasy Battery Tester

Moderators: grovkillen, Stuntteam, TD-er

Message
Author
rspecht
New user
Posts: 2
Joined: 01 Apr 2022, 18:14

ESPEasy Battery Tester

#1 Post by rspecht » 01 Apr 2022, 22:34

Hello Everybody,

greetings from Germany. I am new here and i hope this application wasn't a topic before. I searched a lot inside this Forum and haven't found anything.

So Back to my Plans:
I have some Vehicles around my House and want to get a reminder to charge their Batteries. First i thought about measure Voltage only but this is not that good.
I am a Electronic Engineer - so i know what's needed. I Want to build a simple Measurement Device to Calculate the Internal Resistance from my Battery.
For this i need a solution to toggle a GPIO to switch on a resistive Path and then Measure the Current and Voltage and then untoggle the GPIO.
This should be "hard Coded" so i know everything works in defined State. So where should i start?
I have the Code in Platform IO and have no glue where to start. Should i pick out a I2C ADC Chip and modifies the Driver?

So let me know your thoughts.

BR Raphael

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

Re: ESPEasy Battery Tester

#2 Post by Ath » 01 Apr 2022, 22:55

I'd expect that a regular setup with ESPEasy should suffice. GPIO switching is supported by default, and measuring a voltage has support in f.e. the ADS1115 plugin, available in all NORMAL and TEST builds, probably only needing some external voltage divider to scale down to the proper input range.
In rules you can do calculations and start a notification, if needed.
So no need to adjust any plugins I'd expect ;)
/Ton (PayPal.me)

rspecht
New user
Posts: 2
Joined: 01 Apr 2022, 18:14

Re: ESPEasy Battery Tester

#3 Post by rspecht » 03 Apr 2022, 00:00

So is it also possible to do this fast? The faster it get measured the better it is for battery life :)
Is it possible to do a "State Machine" or so inside Rules?
Where can i Read something about? :)

Thanks a lot. BR

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

Re: ESPEasy Battery Tester

#4 Post by TD-er » 03 Apr 2022, 10:02

The internal ADC (on ESP8266) is read before the WiFi is started, as reading it while WiFi connects (or is started) will affect the reading of A0.
So you could add the ADC plugin to a task and in the rules decide to enter deep sleep immediately if it is too low.
But.... the first reading may fluctuate a bit, so it might need a few samples to base a "go/no-go" decision on it.

Peter83
New user
Posts: 6
Joined: 10 Dec 2022, 19:27

Re: ESPEasy Battery Tester

#5 Post by Peter83 » 10 Dec 2022, 19:47

So you could add the ADC plugin to a task and in the rules decide to enter deep sleep immediately if it is too low.
But.... the first reading may fluctuate a bit, so it might need a few samples to base a "go/no-go" decision on it.
Hello.
So i have a Wemos D1 mini on a battery with solar. Espeasy is flashed.
I am measuring battery power and i want to put the esp back to sleep, when voltage is too low.

whats the best way after waking up/ how do i write those rules?
should i have a timer going on for some seconds, so its best booted? vs how fast is wifi connection there (i do not want it be connected to wifi or send mqtt, when voltage is too low)?
actually im not sure if it shouldnt be starting anytime since i dont know if i can work with deep sleep when bat voltge is high enough
how long can it stay in deep sleep maximum? is it still 71 minutes?

can someone help me with writing these rules?

Code: Select all

On „VBat"<3,1 do    //VBat is Name, GPIO is ADC (TOUT)
	Deepsleep, 3600
Endon
 
Second Question:
If i have deepsleep+awake going on for everytime (maybe 3570s sleep, 30s awake), whats the best way to have a reboot at 0:01 every day?

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

Re: ESPEasy Battery Tester

#6 Post by Ath » 10 Dec 2022, 20:14

Peter83 wrote: 10 Dec 2022, 19:47 can someone help me with writing these rules?

Code: Select all

On „VBat"<3,1 do    //VBat is Name, GPIO is ADC (TOUT)
	Deepsleep, 3600
Endon
 
That should look like: (Assuming default Values name of 'Analog' for the "Analog input - Internal" plugin)

Code: Select all

On VBat#Analog<3.1 do    //VBat is Name, GPIO is ADC (TOUT), values should use US notation, 3.1 not 3,1
	Deepsleep, 3600
Endon
 
Edit: Made some small but significant edits...
/Ton (PayPal.me)

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

Re: ESPEasy Battery Tester

#7 Post by TD-er » 10 Dec 2022, 23:01

Deepsleep is no longer limited to 71-ish minutes.
However the max. duration is a bit vague as it seems to depend on the current uptime... I think. (it differs, I do show the actual reported max. next to where you can set the deep sleep time)
On ESP8266 this is roughly 3.5 hour.

Micha_he
Normal user
Posts: 369
Joined: 07 Feb 2018, 19:14
Location: Helmstedt, Germany

Re: ESPEasy Battery Tester

#8 Post by Micha_he » 11 Dec 2022, 20:45

Can we get the deep-sleep-max-value in the sysvar-page ?

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

Re: ESPEasy Battery Tester

#9 Post by Ath » 11 Dec 2022, 21:03

Micha_he wrote: 11 Dec 2022, 20:45 Can we get the deep-sleep-max-value in the sysvar-page ?
It is currently shown on the Config page, next to the Sleep time field, that's not enough?
/Ton (PayPal.me)

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

Re: ESPEasy Battery Tester

#10 Post by TD-er » 11 Dec 2022, 21:33

... Not if you want to use it to show on a display, in a published topic, etc :)

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

Re: ESPEasy Battery Tester

#11 Post by Ath » 11 Dec 2022, 22:27

On my ESP32 that value is 281474976, that doesn't make much sense to display, I guess :o
/Ton (PayPal.me)

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

Re: ESPEasy Battery Tester

#12 Post by TD-er » 11 Dec 2022, 22:34

On ESP8266 this is a somewhat variable limit.

Micha_he
Normal user
Posts: 369
Joined: 07 Feb 2018, 19:14
Location: Helmstedt, Germany

Re: ESPEasy Battery Tester

#13 Post by Micha_he » 11 Dec 2022, 22:59

For me, the value on the config page is enough. I didn't see it.

Peter83
New user
Posts: 6
Joined: 10 Dec 2022, 19:27

Re: ESPEasy Battery Tester

#14 Post by Peter83 » 12 Dec 2022, 16:42

That should look like: (Assuming default Values name of 'Analog' for the "Analog input - Internal" plugin)

Code: Select all

On VBat#Analog<3.1 do //VBat is Name, GPIO is ADC (TOUT), values should use US notation, 3.1 not 3,1
Deepsleep, 3600
Endon


Edit: Made some small but significant edits...
tank you and TD for ypur answers

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

Re: ESPEasy Battery Tester

#15 Post by Ath » 12 Dec 2022, 17:00

Peter83 wrote: 12 Dec 2022, 16:42 tank you and TD for ypur answers
You're welcome.

NB: Please leave the user and post info in your reply when quoting, so a) the quoted user gets a notification that a message was quoted, and b) we can see where and from whom the quoted text originated ;), TIA
/Ton (PayPal.me)

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

Re: ESPEasy Battery Tester

#16 Post by bonti69 » 20 Feb 2023, 11:56

Hi there,
Is there a solution to measure a real Ah capacity of a battery with ESpeasy?...using a current sensor (ex. INA219) or using PCF8591/ADS1115 connected to ACS711/712 or something.
The idea is to fully charge the battery (let's assume a car battery), then start the discharge until the voltage of battery get's to a certain level (assume 11V). The load will be a 50W bulb , or 21W or less connected to a relay module... higher currents will deplete the battery sooner.
There is a chinese cheap module doing exactly the same thing [ https://www.instructables.com/ZB2L3-BAT ... TY-TESTER/ ]
F0VBJVHJQWSX4VV.jpg
F0VBJVHJQWSX4VV.jpg (441.77 KiB) Viewed 8694 times
Espeasy will measure voltage, current, power, then a rule is needed to calculate Ah, maybe increment every second the current ampere or something. Then, when the voltage drop to Uv level, stop the discharge and send the value to email or just save it on a dummy device...

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

Re: ESPEasy Battery Tester

#17 Post by TD-er » 20 Feb 2023, 12:39

I don't see why this can't work.
However, please make sure your shunt can handle the current you draw.
Those INA219 boards out there do have some shunt, but I don't think those will handle 5+ Amp very well.
Also the used relay must be of good quality, or perhaps use some FET.
N.B. whenever you might consider a solid-state relay, please check it is suitable for switching DC as not all are.


For car batteries, there are also other tools available which may give you an indication of the left over capacity in seconds.
For example, tools like these: https://www.aliexpress.com/item/1005003270269274.html

I've seen similar tools (different brand, same working principle) been used by road-assist people (ANWB in Dutch) to quickly determine the state of a car battery.
It measures the internal resistance of the battery as this is a good indicator of the quality of the battery and the voltage is some indicator of the charge left.

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

Re: ESPEasy Battery Tester

#18 Post by bonti69 » 20 Feb 2023, 13:25

Thank's TD-er.
Yes, I know there are a plenty of Battery meters for accumulators, based on some calculations,estimation of Ah... You put the labeled capacity of battery, in Ah, then the meter apply a huge load, obtaining CCA , then see the voltage drop after few seconds, resulting the "real" Ah. On solar system, not interested of starting current, internal resistence, just how much time the battery can sustain a small load, few amperes in my case...
I did that before with the solar charge controller, wich has a low voltage disconnect at about 10.8-11v, and connecting a 100-150W (light bulbs) and see how much time the battery can sustain the load... Just note the start time on a piece of paper , then note the time when the light goes off. Knowing amperes, let's take 10A, 2 hours means 20 Ah. Pretty simple , but rudimentary :)
Sure is feasible by ESPeasy, will see...

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

Re: ESPEasy Battery Tester

#19 Post by bonti69 » 23 Feb 2023, 15:30

Big disappointment: Internal ADC of ESPEasy is useless. 10 bit resolution means discrete values from 0 to 1024. Maximum input voltage is 1V, that means 1mV steps. Well, a steady voltage of 535mV from an ACS711/30A current sensor via a voltage divider 10k&22k resistors , injected to ADC pin, get random results from 534 to 542. That means 1.4A to 1.7A. Sorry about that... seems a common issue related to wifi activity.
We'll go with INA219, 12bits resolution and steady readings

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

Re: ESPEasy Battery Tester

#20 Post by TD-er » 23 Feb 2023, 15:45

I don't disagree on the usability of the internal ADC, but I want to point out that not all boards have the same analog input range.
Most boards have some resistors present, which stretches the analog input range to 3.3 or 3.6V

Still, you can't measure the voltage drop over a shunt with it, as the shunt would then probably get way too hot if you really need to have a voltage drop of several 100 mV or even > 1V.

For measuring currents, you need an ADC which measures in the mV range, as the typical shunt resistance is often in the order of upto tens of mOhm.

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

Re: ESPEasy Battery Tester

#21 Post by bonti69 » 23 Feb 2023, 16:59

Yes, some who got fried with internal ADC of ESP8266 got the conclusion that the real resolution is maybe 8bit , because of noisy/ random readings. I allready have some ACS711 modules, in 15Amps and 30Amps , they are very simple, 3.3V supply, gnd and Vout. Vout stays at Vcc/2 when is no current. At 30A rise up close to the 3.3v , at -30A the Vout falls to the ground
711.jpg
711.jpg (9.85 KiB) Viewed 8591 times
Screenshot 2023-02-23 at 21-57-14 ACS711-Datasheet-1.pdf.png
Screenshot 2023-02-23 at 21-57-14 ACS711-Datasheet-1.pdf.png (107.79 KiB) Viewed 8525 times
No fuss about the shunt, the sensor are based on Hall effect
Maybe next try will be on ADS1115: A precision 16 bit ADC with Amazing Accuracy...A high precision 16bit ADC with differential or single ended inputs.
Until then, the module with INA219 is working, max 3Amps, a 25W light bulb
Screenshot 2023-02-23 at 17-59-37 ESP_Easy 35.png
Screenshot 2023-02-23 at 17-59-37 ESP_Easy 35.png (142.32 KiB) Viewed 8589 times
Something like that: https://www.instructables.com/DIY-Ardui ... ster-V10-/
Attachments
20230223_174958.jpg
20230223_174958.jpg (4.26 MiB) Viewed 8591 times
20230223_175123.jpg
20230223_175123.jpg (4.22 MiB) Viewed 8591 times
Last edited by bonti69 on 23 Feb 2023, 21:00, edited 2 times in total.

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

Re: ESPEasy Battery Tester

#22 Post by bonti69 » 23 Feb 2023, 17:20

So, we got the voltage, the current and instant pwer, thanks to INA.
Screenshot 2023-02-23 at 18-14-19 ESP_Easy 35.png
Screenshot 2023-02-23 at 18-14-19 ESP_Easy 35.png (35.1 KiB) Viewed 8578 times
We got a power output, bulb 25W on it.
Fully charge the battery, then connect the module. Power the light bulb , and start discharge the battery. Voltage start to decrease. At a certain value (11V for a car AGM battery) stop discharge. Mean time we have to calculate the cumulating amperes-hours. Let say a rule to increment every minute the current value. The current is about 2amps. After a minute we have 2ampere-minutes. After 4 hours we have 2x4x60 ampere-minutes. So battery has 8Ah. If the discharge stops after 324 minutes, then is 10.8Ah
I need your help with that... I know it's simple

Code: Select all

On Clock#Time=All,**:** Do
 
  If [releu#out0] =1 Do
  Let, 1,[ina#current] + %v1%
  Endif
 Endon
Last edited by bonti69 on 23 Feb 2023, 19:43, edited 1 time in total.

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

Re: ESPEasy Battery Tester

#23 Post by bonti69 » 23 Feb 2023, 17:41

First attempt:

Code: Select all

On Clock#Time=All,**:** Do
 
  If [releu#out0] =1
  Let, 1,[ina#current] + %v1%
  TaskValueSet 9,1,[var#1]
  Endif
 Endon
Task 9 is a dummy device where capacity is incremented every minute
but is not incrementing, only 2.19 or 2.20, synthax beats me, (Please Ath when you have time...)

Code: Select all

6839: EVENT: Ah#Capacity=2.20
658192: EVENT: Clock#Time=Thu,18:54
658217: ACT : Let, 1,2.20 + 2.2
658219: Too many arguments: cmd=Let Arg1=1 Arg2=2.20 ExtraArg3=+ ExtraArg4=2.2 lineLength=17
658220: Line: _Let, 1,2.20 + 2.2_
658221: Command not executed! See: https://github.com/letscontrolit/ESPEasy/issues/2724
658226: Command unknown: Let, 1,2.20 + 2.2
658230: ACT : TaskValueSet 9,1,2.2
659321: INA219 0x40: Voltage: 11.67 Current: 2.20 Power: 25.72
659379: EVENT: ina#All=11.67,2.20,25.72
659740: Dummy: value 1: 2.20
659752: EVENT: Ah#Capacity=2.20
662185: INA219 0x40: Voltage: 11.68 Current: 2.20 P

OMG, now is incrementing

Code: Select all

On Clock#Time=All,**:** Do
 
  If [releu#out0] =1 
  Let,1,[ina#current]+[var#1]
  TaskValueSet 9,1,[var#1]
  Endif
 Endon
Attachments
Screenshot 2023-02-23 at 18-51-14 ESP_Easy 35.png
Screenshot 2023-02-23 at 18-51-14 ESP_Easy 35.png (122.84 KiB) Viewed 8573 times

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

Re: ESPEasy Battery Tester

#24 Post by bonti69 » 23 Feb 2023, 18:06

Now we have to do some corrections.
Screenshot 2023-02-23 at 19-02-03 ESP_Easy 35.png
Screenshot 2023-02-23 at 19-02-03 ESP_Easy 35.png (118.99 KiB) Viewed 8570 times
Ina reports current in amperes: 2.2Ah . After a minute 4.4Ah ... and so on
We have to increment the real capacity, divided by 60
Made a new dummy device and inserted a line in rule:

Code: Select all

On Clock#Time=All,**:** Do
 
  If [releu#out0] =1 
  Let,1,[ina#current]+[var#1]
  TaskValueSet 9,1,[var#1]
  TaskValueSet 10,1,[Ah#ampmin]/60
  Endif
 Endon
Screenshot 2023-02-23 at 19-12-45 ESP_Easy 35.png
Screenshot 2023-02-23 at 19-12-45 ESP_Easy 35.png (153.01 KiB) Viewed 8569 times

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

Re: ESPEasy Battery Tester

#25 Post by bonti69 » 23 Feb 2023, 18:37

Final rule to be tested. Email when voltage gets low level,send final capacity on email, reset to zero counters. Final capacity, task 10 will be reset on reboot or via pushbutton...

Code: Select all

On Clock#Time=All,**:** Do
 
  If [releu#out0] =1 
  Let,1,[ina#current]+[var#1]
  TaskValueSet 9,1,[var#1]
  TaskValueSet 10,1,[Ah#ampmin]/60
  Endif
 Endon
 On [ina#voltage]<11.2 Do
  GPIO,5,0
  notify,1
  Let,1,0
  TaskValueSet 9,1,0
  Endon

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

Re: ESPEasy Battery Tester

#26 Post by Ath » 23 Feb 2023, 19:42

bonti69 wrote: 23 Feb 2023, 18:37 Final rule to be tested. Email when voltage gets low level,send final capacity on email, reset to zero counters. Final capacity, task 10 will be reset on reboot or via pushbutton...
A few minor improvements, and a bugfix:

Code: Select all

On Clock#Time=All,**:** Do
  If [releu#out0] =1
    Let,1,[ina#current]+%v1%
    TaskValueSet,Ah,ampmin,%v1% // Use taskname,valuename for portability and readability
    TaskValueSet,Real,Capacity,[Ah#ampmin]/60
  Endif
Endon

On ina#voltage<11.2 Do // 'bug' Don't use [] around the event name
  GPIO,5,0
  notify,1
  Let,1,0
  TaskValueSet,Ah,ampmin,0
Endon
/Ton (PayPal.me)

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

Re: ESPEasy Battery Tester

#27 Post by bonti69 » 23 Feb 2023, 20:11

Thank you, Ath

Really difficult for me to understand Button#State=1 and [Button#State]=0...
Button#State is the event button with value state. Button#State is triggered when you push the button or periodically if interval is different from 0. Every 10s for example. The [Button#State] is the value, 0 or 1.
Screenshot 2023-02-23 at 21-06-04 Rules — ESP Easy 2.1-beta1 documentation.png
Screenshot 2023-02-23 at 21-06-04 Rules — ESP Easy 2.1-beta1 documentation.png (13.53 KiB) Viewed 8532 times
Screenshot 2023-02-23 at 21-06-31 Rules — ESP Easy 2.1-beta1 documentation.png
Screenshot 2023-02-23 at 21-06-31 Rules — ESP Easy 2.1-beta1 documentation.png (22.91 KiB) Viewed 8532 times
Really not sure when an event is triggered...

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

Re: ESPEasy Battery Tester

#28 Post by bonti69 » 23 Feb 2023, 20:50

Schematic
Attachments
battery capacity tester.jpg
battery capacity tester.jpg (427.32 KiB) Viewed 8527 times

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

Re: ESPEasy Battery Tester

#29 Post by Ath » 23 Feb 2023, 21:07

bonti69 wrote: 23 Feb 2023, 20:11 Really not sure when an event is triggered...
For (most) plugins an event "taskname#valuename=(value)" is generated on Plugin_Read, that happens every interval seconds. If you enable the Single event... option, all values (max. 4) are combined into a single "taskname#all=(value1),(value2)..." event, and these events can be handled by an event handler, or Rule.
To be able to recognize an event, the rule has to be specified by name with the required resolution, so that can be a generic "on taskname#valuename do" catching all values, or the more specific "on taskname#valuename=(value)", where the comparison can also be > or < or <>.
Besides the task events, there are also system events and special events.

For an elaborate description of events, have a look at the Events reference and many examples in the Rules documentation.
/Ton (PayPal.me)

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

Re: ESPEasy Battery Tester

#30 Post by bonti69 » 23 Feb 2023, 21:27

Thanks Ath , I'm working on ;) the book is in my hand...
Currently the Oled displays the voltage, current, power. It is possible to send a command after the test is completed , with resulting capacity, and to freeze / disable all other lines? Until a reboot is done. The oled is framed with one line, the 3 lines are scrolling
Attachments
Screenshot 2023-02-23 at 22-09-31 ESP_Easy 35.png
Screenshot 2023-02-23 at 22-09-31 ESP_Easy 35.png (50.27 KiB) Viewed 8519 times
Last edited by bonti69 on 23 Feb 2023, 21:50, edited 1 time in total.

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

Re: ESPEasy Battery Tester

#31 Post by Ath » 23 Feb 2023, 21:40

bonti69 wrote: 23 Feb 2023, 21:27 Currently the Oled displays the voltage, current, power. It is possible to send a command after the test is completed , with resulting capacity, and to freeze / disable all other lines? Until a reboot is done. The oled is framed with one line, the 3 lines are scrolling
I think you can clear the lines 2..4 from rules, and set the desired text/value on line 1. As only 1 line is remaining, the frames won't be scrolled, AFAICS.

Something like:

Code: Select all

on freezebutton#state=0 do
  OledFramedCmd,2," " // May need more spaces to clear the entire line
  OledFramedCmd,3," "
  OledFramedCmd,4," "
  OledFramedCmd,1,"R: [Real#Capacity]" // R: = Result. Should maybe [Ah#ampmin] be used?
endon
To avoid scrolling, you could set the Scroll option to "Instant".
/Ton (PayPal.me)

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

Re: ESPEasy Battery Tester

#32 Post by bonti69 » 23 Feb 2023, 21:58

I'll do it my own way
Create another task oled and disable first oled with V,A,W and enable the second with one line with [real#capacity].[Real#Capacity] it's in Ah, should be in a car battery or solar one in 5-200AHh range
Simple is better.
Or maybe KISS [ https://en.wikipedia.org/wiki/KISS_principle ]
Kelly Johnson's 14 Rules of Management [ https://en.wikipedia.org/wiki/Kelly_Johnson_(engineer) ]
Last edited by bonti69 on 23 Feb 2023, 22:03, edited 1 time in total.

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

Re: ESPEasy Battery Tester

#33 Post by TD-er » 23 Feb 2023, 21:58

One tip to understand the difference between these two.

Take the following example.

Code: Select all

On foo#bar Do
  LogEntry,"Foo Bar: [foo#bar]"
Endon
Taskname: "foo", taskvalue: "bar"

The Task "foo" has a new sample and thus generates a new event:

Code: Select all

foo#bar=123.4
This is the literal event.
So this event needs to be matched literally (so no replacements whatsoever) matched with the rules.

If you use things written within [...] or %...%, then the rules parser MUST first try to replace these with some value, before processing it.
Thus [foo#bar] will be replaced by the current value (probably "123.4" as that was the last value)
So this line (2nd is the replacement)

Code: Select all

LogEntry,"Foo Bar: [foo#bar]"    <<< Line in Rules
LogEntry,"Foo Bar: 123.4"      <<< Replaced all within [] and %%
If you would use [] in the On ... Do line, you would get something like this:

Code: Select all

On [foo#bar] Do  << Original (incorrect) line in rules
On 123.4 Do  << Replaced (incorrect) line
As you can see, there is never going to be any event matching "123.4" here.


So remember:
- Everything within [...] or %...% will first be replaced before the rule is parsed.

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

Re: ESPEasy Battery Tester

#34 Post by bonti69 » 23 Feb 2023, 22:32

Thanks for support, TD-er
Everything within [...] or %...% will first be replaced before the rule is parsed.
Remarcable to waste your time with bad students. And do it pro bono ...
30 years ago, as a student in electronics, I failed my Pascal test. Passed on autumn at last. 3D matrix, have to order the items on a diagonal in ascending order of birth age. My mind is something more deterministic, i'm lost in loops and "if this... then that..."
For now I'm in mimetic phase, I'm able to understand and reproduce with some modifications/adaptations
I have a text file where I have all the rules from my projects, I'm less than a year with EspEasy.
For guys like me will be nice a Bible with submodules, code and task. I know, it is on documentation but it's not easy to search and find fast the solution.Very good here: https://espeasy.readthedocs.io/en/lates ... g-examples
with https://espeasy.readthedocs.io/en/lates ... Rules.html#
Thanks again for your kindly explanations
Great job
Over again: please implement in the device page possibility to direct toggle a switch state, with a click on the mouse.
click.jpg
click.jpg (339.87 KiB) Viewed 8485 times
I have to make a mqtt connection or console command just to turn on/off a damn relay
Sursum corda

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

Re: ESPEasy Battery Tester

#35 Post by bonti69 » 24 Feb 2023, 00:03

On the ground again.
I mount a pushbutton to toggle on/off the relay. On longpress I wanted to clear the variable/task reset to zero
2 rules

Code: Select all

On System#Boot Do
GPIO,5,0
Let,1,0
TaskValueSet 9,1,0
TaskValueSet 10,1,0

TaskValueSet 8,1,[releu#out0]
TaskValueSet 8,2,[ina#Voltage]
TaskValueSet 8,3,[ina#Current]
TaskValueSet 8,4,[ina#Power]
timerSet,1,60
endon

On Rules#Timer=1 do
TaskValueSet 8,1,[releu#out0]
TaskValueSet 8,2,[ina#Voltage]
TaskValueSet 8,3,[ina#Current]
TaskValueSet 8,4,[ina#Power]
timerSet,1,60
endon
and

Code: Select all

On Clock#Time=All,**:** Do
  If [releu#out0] =1
    Let,1,[ina#current]+%v1%
    TaskValueSet,Ah,ampmin,%v1% // Use taskname,valuename for portability and readability
    TaskValueSet,Real,Capacity,[Ah#ampmin]/60
  Endif
Endon

On ina#voltage<11.2 Do // 'bug' Don't use [] around the event name
  GPIO,5,0
  notify,1
  Let,1,0
  TaskValueSet,Ah,ampmin,0
Endon

  On button#state do
  GPIOtoggle,5
  Endon
  
On button#state=10 Do
   GPIO,5,0
   Let,1,0
  TaskValueSet 9,1,0
  TaskValueSet 10,1,0
 Endon
The longpress is working, because GPIO,5,goes off, but TaskValueSet 9,1,0 and TaskValueSet 10,1,0 are not cleared. Because they appear in the 1st rule??? If I remember what Ath said...
SOLVED

Code: Select all

On Clock#Time=All,**:** Do
  If [releu#out0] =1
    Let,1,[ina#current]+%v1%
    TaskValueSet,Ah,ampmin,%v1% // Use taskname,valuename for portability and readability
    TaskValueSet,Real,Capacity,[Ah#ampmin]/60
  Endif
Endon

On ina#voltage<11.2 Do // 'bug' Don't use [] around the event name
  GPIO,5,0
  notify,1
  Let,1,0
  TaskValueSet,Ah,ampmin,0
Endon

  On button#state=0 do
  GPIOtoggle,5
  Endon
  
On button#state=10 Do
   GPIO,5,0
   notify,1
   Let,1,0
  TaskValueSet,Ah,ampmin,0
  TaskValueSet,Real,Capacity,0
 Endon
Switch Button Type: changed to "normal switch" instead of "push button active low"

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

Re: ESPEasy Battery Tester

#36 Post by Ath » 24 Feb 2023, 07:35

bonti69 wrote: 24 Feb 2023, 00:03 The longpress is working, because GPIO,5,goes off, but TaskValueSet 9,1,0 and TaskValueSet 10,1,0 are not cleared. Because they appear in the 1st rule??? If I remember what Ath said...
SOLVED
On button#state=0 do
On button#state=10 Do
It wasn't working initially because the more generic "On button#state do" was listed first, so the more specific "On button#state=10 do" was never handled.
Your solution to make them both equally specific (On button#state=0 do) does work.
/Ton (PayPal.me)

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

Re: ESPEasy Battery Tester

#37 Post by bonti69 » 24 Feb 2023, 19:55

Maybe this is acceptable?

Code: Select all

 On button#state do
 If button#state=0
  GPIOtoggle,5
  Endif
  
if button#state=10 
   GPIO,5,0
   notify,1
   Let,1,0
  TaskValueSet,Ah,ampmin,0
  TaskValueSet,Real,Capacity,0
  Endif
 Endon
or maybe this

Code: Select all

 On button#state do
 If [button#state]=0
  GPIOtoggle,5
  Endif
  
if [button#state]=10 
   GPIO,5,0
   notify,1
   Let,1,0
  TaskValueSet,Ah,ampmin,0
  TaskValueSet,Real,Capacity,0
  Endif
 Endon

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

Re: ESPEasy Battery Tester

#38 Post by Ath » 24 Feb 2023, 20:09

That should be fine.
Only improvement could be to work on the indentation, to make it easier readable. ;)
/Ton (PayPal.me)

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

Re: ESPEasy Battery Tester

#39 Post by bonti69 » 24 Feb 2023, 23:19

First TEST
Screenshot 2023-02-24 at 23-45-03 ESP_Easy 35.png
Screenshot 2023-02-24 at 23-45-03 ESP_Easy 35.png (48.21 KiB) Viewed 8378 times
Screenshot 2023-02-25 at 00-17-59 ESP_Easy 35.png
Screenshot 2023-02-25 at 00-17-59 ESP_Easy 35.png (47.27 KiB) Viewed 8378 times
The gpio5 does not off at the 11.2v , as we set in rule

Code: Select all

On Clock#Time=All,**:** Do
  If [releu#out0] =1
    Let,1,[ina#current]+%v1%
    TaskValueSet,Ah,ampmin,%v1% // Use taskname,valuename for portability and readability
    TaskValueSet,Real,Capacity,[Ah#ampmin]/60
  Endif
Endon

On ina#voltage<11.2 Do // 'bug' Don't use [] around the event name
  GPIO,5,0
  notify,1
  //Let,1,0
  //TaskValueSet,Ah,ampmin,0
Endon

On button#state=0 do
  GPIOtoggle,5
Endon
  
On button#state=10 Do
   GPIO,5,0
   //notify,1
   Let,1,0
  TaskValueSet,Ah,ampmin,0
  TaskValueSet,Real,Capacity,0
Endon
 
What could be wrong in 3 lines of code????
On ina#voltage<11.2 Do
GPIO,5,0
notify,1
//Let,1,0
//TaskValueSet,Ah,ampmin,0
Endon


log:

18046662: EVENT: ina#All=11.09,2.14,23.70
18049600: EVENT: Clock#Time=Sat,0:29
18049620: ACT : Let,1,2.14+655.27
18049634: ACT : TaskValueSet,Ah,ampmin,657.41
18049646: FS : Error while reading/writing config.dat in 14273
18049663: FS : Error while reading/writing config.dat in 14273
18049670: ACT : TaskValueSet,Real,Capacity,657.41/60
18049681: FS : Error while reading/writing config.dat in 14273
18049694: Calculate: Unknown token input: ina#voltage = 0
18049796: INA219 0x40: Voltage: 11.09 Current: 2.14 Power: 23.70
18049812: EVENT: ina#All=11.09,2.14,23.70
18050795: Dummy: value 1: 657.41
18050807: EVENT: Ah#ampmin=657.41
Last edited by bonti69 on 24 Feb 2023, 23:30, edited 1 time in total.

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

Re: ESPEasy Battery Tester

#40 Post by TD-er » 24 Feb 2023, 23:29

Best check for only the event without value and then test the %eventvalue1%

Code: Select all

On ina#voltage Do
  if %eventvalue1% < 11.2
  
  
  endif
EndOn
Also check to see if you checked the checkbox to combine all task values of the "ina" task.
If it is, then the event would be like "ina#All"

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

Re: ESPEasy Battery Tester

#41 Post by bonti69 » 24 Feb 2023, 23:38

BINGO
TD-er , YOU ARE... A M A Z I N G

Code: Select all

On Clock#Time=All,**:** Do
  If [releu#out0] =1
    Let,1,[ina#current]+%v1%
    TaskValueSet,Ah,ampmin,%v1% // Use taskname,valuename for portability and readability
    TaskValueSet,Real,Capacity,[Ah#ampmin]/60
  Endif
Endon
On ina#All Do
  if %eventvalue1% < 11.2
  GPIO,5,0
  notify,1
  Endif
Endon

 
  //Let,1,0
  //TaskValueSet,Ah,ampmin,0


On button#state=0 do
  GPIOtoggle,5
Endon
  
On button#state=10 Do
   GPIO,5,0
   //notify,1
   Let,1,0
  TaskValueSet,Ah,ampmin,0
  TaskValueSet,Real,Capacity,0
Endon
The voltage goes up to 11.65V after bulb was disconnected
Screenshot 2023-02-25 at 00-39-27 ESP_Easy 35.png
Screenshot 2023-02-25 at 00-39-27 ESP_Easy 35.png (62.22 KiB) Viewed 8370 times
We got a nice email

Screenshot 2023-02-25 at 00-42-18 Battery test capacity - @gmail.com - Gmail.png
Screenshot 2023-02-25 at 00-42-18 Battery test capacity - @gmail.com - Gmail.png (24.83 KiB) Viewed 8368 times

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

Re: ESPEasy Battery Tester

#42 Post by bonti69 » 24 Feb 2023, 23:57

That is the battery under test, Panasonic, 17Ah
20230225_004951.jpg
20230225_004951.jpg (468.71 KiB) Viewed 8362 times
The real capacity depends on the discharge current
panasonic17ah.png
panasonic17ah.png (138.96 KiB) Viewed 8362 times
We use 2.2Amps , that means real 13Ah
Also the cut-off voltage was ~11.1V, the datashhet specifies 10.8V at 2.29A/ 6hours discharge
Panasonic 17Ah ampere.jpg
Panasonic 17Ah ampere.jpg (183.19 KiB) Viewed 8362 times

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

Re: ESPEasy Battery Tester

#43 Post by bonti69 » 25 Feb 2023, 00:07

Very happy
Because THEY told us not to discharge a solar battery under 50% SoC, to have as much cycles battery can provide
AGM.png
AGM.png (137 KiB) Viewed 8361 times
battery-condition.jpg
battery-condition.jpg (72.35 KiB) Viewed 8361 times
battery-cycles.jpg
battery-cycles.jpg (34.3 KiB) Viewed 8360 times
But, as we see, only 2 amps load drops the voltage of a fully charged battery from the beggining to 12.2V
Panasonic 17Ah.jpg
Panasonic 17Ah.jpg (132.1 KiB) Viewed 8361 times
Attachments
graph.jpg
graph.jpg (88.88 KiB) Viewed 8361 times

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

Re: ESPEasy Battery Tester

#44 Post by TD-er » 25 Feb 2023, 00:44

Cool :)

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

Re: ESPEasy Battery Tester

#45 Post by bonti69 » 25 Feb 2023, 20:39

A small problem, however
gpio 4 is the button on/off, pushswitch
gpio 5 is the relay switch
The relay gets on after boot, even I have these rules:

Code: Select all

On System#Boot Do
GPIO,5,0
Let,1,0
TaskValueSet 9,1,0
TaskValueSet 10,1,0
endon
....

On button#state=0 do
  GPIOtoggle,5
Endon
  
On button#state=10 Do
   GPIO,5,0
   //notify,1
   Let,1,0
  TaskValueSet,Ah,ampmin,0
  TaskValueSet,Real,Capacity,0
Endon
 
On gpio 4 only internal pullup is tick-ed, I don't have a hardware pullup resistor. Could be that the cause? Gpio 5 is on after ESP fully boot, the oled is ready...

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

Re: ESPEasy Battery Tester

#46 Post by Ath » 25 Feb 2023, 21:14

Often GPIOToggle isn't turning out the result that you would expect...

Have you disabled "Send Boot state", as that will do as stated, send the Boot state, possibly causing the GPIO toggle...
/Ton (PayPal.me)

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

Re: ESPEasy Battery Tester

#47 Post by TD-er » 25 Feb 2023, 21:20

Also, you toggle on the switch being 0.
How is the switch task configured? As a 'normal' switch or a pushbutton?
Do you have a debounce set? If not, I suggest something like 100 msec.
And perhaps use a pull-up resistor instead of the internal pull-up.
The internal pull-up is quite weak, with only 80kOhm.
Typically a pull-up resistor is like 4k7 .. 10k.

How long is the cable between the ESP and the button?

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

Re: ESPEasy Battery Tester

#48 Post by bonti69 » 25 Feb 2023, 22:11

Screenshot 2023-02-25 at 23-09-30 ESP_Easy 35.png
Screenshot 2023-02-25 at 23-09-30 ESP_Easy 35.png (66.57 KiB) Viewed 8234 times
cable is short, 15cm, just a mini switch between gpio4 and gnd
Screenshot 2023-02-25 at 23-14-29 ESP8266 Pinout Reference Which GPIO pins should you use Random Nerd Tutorials.png
Screenshot 2023-02-25 at 23-14-29 ESP8266 Pinout Reference Which GPIO pins should you use Random Nerd Tutorials.png (33.81 KiB) Viewed 8233 times
https://rabbithole.wwwdotorg.org/2017/0 ... -gpio.html

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

Re: ESPEasy Battery Tester

#49 Post by bonti69 » 26 Feb 2023, 12:29

A car battery on benchmark, since yesterday 17.00 hour with a 25W bulb
Attachments
graph2.jpg
graph2.jpg (101.54 KiB) Viewed 8179 times
Screenshot 2023-02-26 at 13-25-36 ESP_Easy 35.png
Screenshot 2023-02-26 at 13-25-36 ESP_Easy 35.png (71.37 KiB) Viewed 8179 times

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

Re: ESPEasy Battery Tester

#50 Post by bonti69 » 26 Feb 2023, 12:35

10 minutes pause, the voltage rise from 11.34 to 11.85V
graph2_crr.jpg
graph2_crr.jpg (27.95 KiB) Viewed 8178 times
graph2_cr.jpg
graph2_cr.jpg (33.59 KiB) Viewed 8178 times

Post Reply

Who is online

Users browsing this forum: No registered users and 15 guests