chaunceygardiner / weewx-purple

A WeeWX plugin that support the purple-proxy service for retrieving PurpleAir sensor readings.
GNU General Public License v3.0
3 stars 1 forks source link

Color not right at threshold - reopen #10

Closed n7qnm closed 4 months ago

n7qnm commented 4 months ago
          Just checked now, and the aqi_pm2_5_color value was 7474631.111111111.  On the next loop it went back to 16776960.0  - using weewx 5.0.2 and weewx-purple 3.9.2

Originally posted by @n7qnm in https://github.com/chaunceygardiner/weewx-purple/issues/9#issuecomment-2241297978

chaunceygardiner commented 4 months ago

First, upgrade to v3.9.3. There is an installation problem in v3.9.2.

As for you specific issue, there is no aqi_pm2_5_color. Perhaps you mean pm2_5_aqi_color?

You still haven’t said where you are seeing this. In a report?

Add the following lines after line 97 in skins/purple/index.html.tmpl and install, run a report, and cut and paste here the results printed in the report once it runs.

set $color = int($current.pm2_5_aqi_color.raw)

set $blue = $color & 255

set $green = ($color >> 8) & 255

set $red = ($color >> 16) & 255

Current PM2_5$current.pm2_5
RGB$red, $green, $blue
n7qnm commented 4 months ago

OK -I’ll get 3.9.3 later tonight.

Yes, it’s pm2_5_aqi_color – I convert it to RGB and use it in reports and from the MQTT in a little LED display I built.

It only happens at the “transition” from one color to another, so far I’ve only observed it on green to yellow or from yellow back to green; so after I upgraded, it may be a day or two before I get a chance to test it again.

Thanks!

From: John Kline @.> Sent: Saturday, July 20, 2024 3:19 PM To: chaunceygardiner/weewx-purple @.> Cc: n7qnm @.>; Author @.> Subject: Re: [chaunceygardiner/weewx-purple] Color not right at threshold - reopen (Issue #10)

First, upgrade to v3.9.3. There is an installation problem in v3.9.2.

As for you specific issue, there is no aqi_pm2_5_color. Perhaps you mean pm2_5_aqi_color?

You still haven’t said where you are seeing this. In a report?

Add the following lines after line 97 in skins/purple/index.html.tmpl and install, run a report, and cut and paste here the results printed in the report once it runs.

set $color = int($current.pm2_5_aqi_color.raw)

set $blue = $color & 255

set $green = ($color >> 8) & 255

set $red = ($color >> 16) & 255

Current PM2_5

$current.pm2_5

RGB

$red, $green, $blue

— Reply to this email directly, view it on GitHub https://github.com/chaunceygardiner/weewx-purple/issues/10#issuecomment-2241315026 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AGDARKIKOO2PIJBT4YXSUVDZNLO4XAVCNFSM6AAAAABLGHXDR6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENBRGMYTKMBSGY . You are receiving this because you authored the thread. https://github.com/notifications/beacon/AGDARKN3CFO4V7PLTY4EM3DZNLO4XA5CNFSM6AAAAABLGHXDR6WGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTUFS7ANE.gif Message ID: @. @.> >

chaunceygardiner commented 4 months ago

I’m less interested in you catching it during transition and more interested in how you are getting the number you are showing. My software can’t generate it. I’ve shown you the code. For one, it is always a whole number. There must be something you are doing to average the color value in loopdata. That will work quite poorly for rgb values.

chaunceygardiner commented 4 months ago

Closing again. Don’t reopen unless you think this extension is producing the values you list above. It is clear to me that you are averaging rgb values a whole. This simply isn’t how one averages rgb values. You can do a web search to find out how to average rgb values. BTW, IMO, even that is wrong for this use case. The EPA spec does not average colors, rather, there are hard cutoffs between the colors. This extension behaves accordingly.

n7qnm commented 3 months ago

OK – haven’t had a chance to upgrade yet; but here’s the code I use in my skin - it also displays a “weird” color

    #if $current.pm2_5_aqi.has_data

       #set $rgbint = int($current.pm2_5_aqi_color.raw)

       #set $red   = $rgbint >> 16

       #set $green = ($rgbint >> 8) & 255

       #set $blue  = $rgbint & 255

       #set $rgbcolor = 'rgb(' + str($red) + ',' + str($green) + ',' + str($blue) + ')'

       <div style="text-align: center; background-color: $rgbcolor;" >

            $current.pm2_5_aqi.format(add_label=False) <br/>

       </div>

       #end if

I also use the MQTT extension to publish the loop record and do the equivalent of the above in a Python script to set the color in an LED segment.

Here’s what I think is going on –

the purpleair sensor and my other sensor, which is being fed TO weewx by MQTT, are not in exact time sync. So, during one “loop interval”, I can get multiple readings from the purpleair sensor. If I get two readings, both the AQI number and the number representing the color are getting averaged. As long as the AQI NUMBER doesn’t cross a threshold during the ENTIRE loop interval, the two color values are the same, and so the average is OK. But if the number DOES cross a threshold, then the two color numbers are different and so the average is something between.

Does that make sense?

I’m probably just going to generate the color in the skin and my LED code going forward.

Thanks!

Clay Jackson

From: @. @.> Sent: Saturday, July 20, 2024 3:48 PM To: 'chaunceygardiner/weewx-purple' @.>; 'chaunceygardiner/weewx-purple' @.> Cc: 'Author' @.***> Subject: RE: [chaunceygardiner/weewx-purple] Color not right at threshold - reopen (Issue #10)

OK -I’ll get 3.9.3 later tonight.

Yes, it’s pm2_5_aqi_color – I convert it to RGB and use it in reports and from the MQTT in a little LED display I built.

It only happens at the “transition” from one color to another, so far I’ve only observed it on green to yellow or from yellow back to green; so after I upgraded, it may be a day or two before I get a chance to test it again.

Thanks!

From: John Kline @. @.> > Sent: Saturday, July 20, 2024 3:19 PM To: chaunceygardiner/weewx-purple @. @.> > Cc: n7qnm @. @.> >; Author @. @.> > Subject: Re: [chaunceygardiner/weewx-purple] Color not right at threshold - reopen (Issue #10)

First, upgrade to v3.9.3. There is an installation problem in v3.9.2.

As for you specific issue, there is no aqi_pm2_5_color. Perhaps you mean pm2_5_aqi_color?

You still haven’t said where you are seeing this. In a report?

Add the following lines after line 97 in skins/purple/index.html.tmpl and install, run a report, and cut and paste here the results printed in the report once it runs.

set $color = int($current.pm2_5_aqi_color.raw)

set $blue = $color & 255

set $green = ($color >> 8) & 255

set $red = ($color >> 16) & 255

Current PM2_5

$current.pm2_5

RGB

$red, $green, $blue

— Reply to this email directly, view it on GitHub https://github.com/chaunceygardiner/weewx-purple/issues/10#issuecomment-2241315026 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AGDARKIKOO2PIJBT4YXSUVDZNLO4XAVCNFSM6AAAAABLGHXDR6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENBRGMYTKMBSGY . You are receiving this because you authored the thread. https://github.com/notifications/beacon/AGDARKN3CFO4V7PLTY4EM3DZNLO4XA5CNFSM6AAAAABLGHXDR6WGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTUFS7ANE.gif Message ID: @. @.> >

chaunceygardiner commented 3 months ago

Of course, they are getting averaged. That’s why I said in my previous message: “It is clear to me that you are averaging rgb values a whole.”

You cannot do that!

Rather, the right way to do this is to get the average AQI and then generate the color, as [I think] you are saying above. The javascript is in my sample report.