Looking for guidelines on using LED indicators on a Dashboard

Having not found any LED information searching here, I am looking for any information on using the LEDs when creating a dashboard in Emoncms (being fed from an Emonpi and IotaWatt system). It seems the LED colors trigger at some unexpected wattage values (like 0.01W will turn the LED green, while 2.0W will leave the LED black) so I wondered if there are instructions somewhere on the best way to incorporate the LEDs?

One issue I have to work around is that when my heat pump is not operating, I can see a fractional wattage value on the sensor, ranging from 0.01 to 0.04 watts. These values if fed directly to an LED will turn it green, even though I would prefer it to be red. The heat pump draws approx. 2230 watts when running, so I would like to make the LED green if the sensor goes above, say, 0.5 watts and stay red if below 0.5 watts. I’ve been playing with experimental values and calculations but there doesn’t seem to be a simple way to achieve my goal.

I’ve learned the LEDs change to 6 different colors (if you include black) over a range of 0 to 5 watts. Anything over 5 watts stays black. So getting the heat pump to do a “simple” red for off and green for on LED is going to require some clever calculations I’ve not yet figured out, using the very limited modifiers available on the Inputs page. If there are explanations or guidelines for each of those process modifiers, that would be helpful. Some of them I don’t understand.

Any help will be appreciated. :slightly_smiling_face:

Just change the value’s in led_reder.js in the /Modules/dashboard/widget/led directory.
After that replace led’s in your dashboard.

That sounds like an ideal solution! Thanks! But I can’t seem to find a /Modules directory on my PiTop notebook, running a downloaded image of emonpi. Can you tell me how to find it?

When I try cd/Modules from the [email protected]:~$ prompt I get “No such file or directory”.

try cd /var/www/emoncms/Modules/dashboard/widget/led

“no such file or directory”. Do I need to be logging in as pi or as something else? When I do ls -a from pi the list of available directories is quite short. Only readme.md is there not prefixed with s period. The other names are .bash_history .bash_logout .bashrc .gnupg .local .profile .wget-hsts

Modules is with capitalized M at the beginning.

Yes, I noticed that, and typed it that way.

This is how it should look:

[email protected]:~ $ cd /var/www/emoncms/Modules/dashboard/widget/led

[email protected]:/var/www/emoncms/Modules/dashboard/widget/led $

Ah. there is no space between cd and /var/www/emoncms/Modules/dashboard/widget/led

Ah, bollocks! I missed the space after cd. :roll_eyes:
I’ll try again

OK, Thanks! I’ve opened the js file with nano. But I’m not sure which values I need to change? There seem to be a lot of references to the LED colors. Can you give me an example of how to change one, so I can see what to look for in the file?

  if (ledstyle ==="1"){
  var radgrad = circle.createRadialGradient(width/2,height/2,0,width/2,height/2,dimension/2);
    if (status==0) {                   // Black
      radgrad.addColorStop(0, "#555555");
      radgrad.addColorStop(0.9, "#000000");
    } else if (status>1 && status <=9) {            // Red
     radgrad.addColorStop(0, "#CC0000");
      radgrad.addColorStop(0.9, "#550000");
    } else if (status>10 && status <=2000) {           // Green
      radgrad.addColorStop(0, "#00FF00");
      radgrad.addColorStop(0.9, "#005500");
    } else if (status>2000 && status <=3000) { 		  //Blue
      radgrad.addColorStop(0, "#CC00CC");
      radgrad.addColorStop(0.9, "#CC00CC");
    } else if (status>3000 && status <=4000) {		  // Purple
      radgrad.addColorStop(0, "#FF5F98");
      radgrad.addColorStop(0.9, "#FF0188");
    } else if (status>4000 && status <=5000)   {         // yellow
      radgrad.addColorStop(0, "#F4F201");
      radgrad.addColorStop(0.9, "#E4C700");
    } else {					  // Black
      radgrad.addColorStop(0, "#000000");
      radgrad.addColorStop(0.9, "#000000");

Edit - formatted code for readability. BT, Moderator

Well, I don’t know JavaScript, so sadly I don’t have any idea what to do with your example. I was hoping it would be at least a little intuitive. Sorry. I do appreciate your efforts though! Thanks!!

0W = Black
1W-9W = Red
10W-2000W = Green
2000W-3000W = Blue
3000W-4000W = Purple
4000W-5000W = Yellow
above 5000W = Black

change status>… and status <=…

Ah! I think I can do that! And I do see now which section you are editing. I’ll give that a go and let you know how it all shakes out. Thanks!

A note for future, I would expect that changing this file will block future updates of this Module. You will need to manually stash the file, and then pull in any new version.

An error will be seen in the update log.

Hmm. I don’t know how often these files would update, but that sounds like something I would prefer to avoid.

However, thanks to Michael’s valiant efforts to clarify how the colors are assigned, I now see that they are not as cryptic as I had thought. The default values are:

0W                     = Red
>0W thru <=1W = Green
>1W thru <=2W = Gray
>2W thru <=3W = Blue
>3W thru <=4W = Purple
>4W thru <=5W = Yellow
>5W                   = Black

What threw me originally is that Gray is represented by a very subtle gradient overlay on Black, and it was not even noticed at first. This caused me to think that values of 1-2W were also Black, so didn’t make sense. Now that I understand the default color layout, I should be able to make use of it within the Input process operations, and simply avoid using Gray so I don’t mistake it for being Black.

I thank you all for the generous help! :grin:

[Edited at the OP’s request - Moderator (RW)]

I just today realized there is a potential for problems in the way the led_render.js file is coded for the LED colors. The assigned values “overlap”, and this tripped me up in my efforts to code a process list to get desired results. I had set a value of 4 because I wanted the yellow LED (seeing that 4W-5W = Yellow in my list, above) but had never even noticed that Purple is assigned “3W-4W”, and Purple is exactly what I got (because it comes first in the code, I imagine).

I think it would be better to have the colors assigned with an increment of 1 between them, making 0-1 Red, 2-3 Green, etc. This would also solve an issue I am working around where I have my heat pump being “off”, and yet its 220V power leads are sometimes showing 0.1W on the CT feed coming from my IotaWatt. So I am having to code the process list for that input to remain showing a Red LED even if the value exceeds 0W by some fraction of a watt.

Just thought I’d mention this in case someone wants to address it in a future update of EmonPi. For now I’ll use the middle of each assigned value, such as 0.5W if I want Green. But I think using whole numbers would be easier in the long run.

[Lawrence hadn’t noticed that in the original code, the ranges don’t overlap, see below - Moderator (RW)]

I don’t think that problem existed in the original code. As I read it, the use of “greater than” for the lower bound and “less than or equal to” for the upper bound:

else if (status>3000 && status <=4000) { // Purple

ensured that this did not happen.