Neopixel Battery Gauge ?

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
chr2002_2
New user
Posts: 3
Joined: 24 Sep 2023, 12:22

Neopixel Battery Gauge ?

#1 Post by chr2002_2 » 24 Sep 2023, 12:25

Hello

Can ESPeasy show a battery gauge on a Neopixel ring ?
Can this be done by a Rule ?

I want to read a 0-100 (%) Value using MQTT_Import and visualize the Value with a Neopixel Ring on e.g. 40 LEDs with coloring from red (low battery) over yellow (medium charge) to green (nearly full / full charge)
Is this possible with espEasy ?

Greetings Chris

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

Re: Neopixel Battery Gauge ?

#2 Post by TD-er » 24 Sep 2023, 12:42

We do support some battery gauge chips, like these: https://espeasy.readthedocs.io/en/lates ... 5-typename

So using rules, you should be able to turn it into a NeoPixel command to update the number of LEDs on your ring and also set the color if you like.

chr2002_2
New user
Posts: 3
Joined: 24 Sep 2023, 12:22

Re: Neopixel Battery Gauge ?

#3 Post by chr2002_2 » 24 Sep 2023, 14:21

Ah, i saw this feature,

But I want to monitor my PV Battery. Its a 9,6 KWh Battery system. The Inverter reports a value 0 - 100 via Modbus to my MQTT Broker.
I think, its not as easy zu visualize / scale this value on a Neopixel Ring.

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

Re: Neopixel Battery Gauge ?

#4 Post by Ath » 24 Sep 2023, 15:07

You can configure the MQTT Import plugin (name: MQTTImport) to receive that value, and name that value BatteryPercentage, enable that task and add this to the rules:

Code: Select all

on MQTTImport#BatteryPercentage do
  let,1,40 // Number of LEDs
  let,2,%eventvalue1%/(100/%v1%) // Number of LEDs to light up
  if %eventvalue1%<15
    NeoPixelLine,1,[int#2],255,0,0 // Red
  elseif %eventvalue1%<85
    NeoPixelLine,1,[int#2],255,127,80 // Orange (coral)
  else
    NeoPixelLine,1,[int#2],0,255,0 // Green
  endif
endon
This assumes you have the NeoPixel (Basic) plugin configured and enabled, so these commands can work.
You can determine the max. brightness using the plugin settings. This may alter the actual color unexpectedly if the brightness is (very) low, as it uses integer division to calculate a new value per color.

NB: Air code :D
/Ton (PayPal.me)

chr2002_2
New user
Posts: 3
Joined: 24 Sep 2023, 12:22

Re: Neopixel Battery Gauge ?

#5 Post by chr2002_2 » 28 Sep 2023, 18:58

Thanks :-)

I had to add some lines, to clear the LEDs.
Otherwise the "consumed LEDs" keep on.


on MQTT_W#PV_CAP_BAT do
let,1,24 // Number of LEDs
let,2,%eventvalue1%/(100/%v1%) // Number of LEDs to light up
if %eventvalue1%<25
NeoPixelLine,[int#2]+1,25,0,0,0 // clear/poweroff consumed LEDs
NeoPixelLine,1,[int#2],100,0,0
elseif %eventvalue1%<85
NeoPixelLine,[int#2]+1,25,0,0,0 // clear/poweroff consumed LEDs
NeoPixelLine,1,[int#2],58,74,0
else
NeoPixelLine,[int#2]+1,25,0,0,0 // clear/poweroff consumed LEDs
NeoPixelLine,1,[int#2],0,100,0
endif
endon

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

Re: Neopixel Battery Gauge ?

#6 Post by Ath » 28 Sep 2023, 22:21

chr2002_2 wrote: 28 Sep 2023, 18:58 I had to add some lines, to clear the LEDs.
Otherwise the "consumed LEDs" keep on.
Ah, yes, didn't think of that :oops:

A few minor corrections:

Code: Select all

on MQTT_W#PV_CAP_BAT do
  let,1,24 // Number of LEDs
  let,2,%eventvalue1%/(100/%v1%) // Number of LEDs to light up
  if %eventvalue1%<25
    NeoPixelLine,[int#2]+1,[int#1],0,0,0  // clear/poweroff consumed LEDs
    NeoPixelLine,1,[int#2],100,0,0 
  elseif %eventvalue1%<85
    NeoPixelLine,[int#2]+1,[int#1],0,0,0 // clear/poweroff consumed LEDs
    NeoPixelLine,1,[int#2],58,74,0 
    else
    NeoPixelLine,[int#2]+1,[int#1],0,0,0 // clear/poweroff consumed LEDs
    NeoPixelLine,1,[int#2],0,100,0 
   endif
endon
Using the set number of LEDs "[int#1]" to clear to the end instead of the fixed (and AFAICS wrong) number 25.
/Ton (PayPal.me)

Post Reply

Who is online

Users browsing this forum: No registered users and 38 guests