Purple Air AQI Solution found but can't get it to work

Any chance of getting Purple Air AQI values added to PiConsole display?

I found this post as a solution to my question of how to implement Purple Air AQI data into my console. I copied the files to the proper location, changed the file extension, Purple Air URL, etc.
The Purple Air panel does not show up in the secondary panel list when I select an unused panel such as panel 5. Any suggestions? I have the latest Console version.

The panel will show in the list of panels you can select as ‘ExamplePanel’. Are you not seeing that?

No. All I see in Secondary Panel, Panel Five (or any others), is:

None, Forecast, Sager, Temperature. Cancel

Have you tried scrolling through the list? There should be a lot more options

I did not scroll down far enough to see the “Example” option. It was an ID10T error.
Thanks for pointing that out.

No problem! Glad it was working :grin:

Except it isn’t quite working yet. When I follow the Purple Air example, I get confused as to what to put in Custompanels.py. When I put in my URL (with/json), it doesn’t work when selecting Example for Panel 5. Do I need to put in everything that the json shows? It’s not clear to me.

Unfortunately having never worked with Purple Air devices, I can’t really advise here. The custom panel functionality is designed to allow advance users the ability to create their own panels, but the code required has to be provided by the user. In the Purple Air example provided, I can see that JSON data is being requested from a local URL and the temperature is being read from the JSON structure and being displayed on the panel. To show anything else you will need to write the additional code yourself and troubleshoot why the URL is not working

Thanks Peter. I hope the OP of the Purple Air panel will respond.

This is a consistent error I get no matter what panel I try:

[INFO ] [Logger ] Record log in /home/pi/.kivy/logs/kivy_26-08-30_45.txt
[INFO ] [Kivy ] v2.3.1
[INFO ] [Kivy ] Installed at “/home/pi/wfpiconsole/venv/lib/python3.9/site-packages/kivy/init.py”
[INFO ] [Python ] v3.9.2 (default, Mar 12 2021, 04:06:34)
[GCC 10.2.1 20210110]
[INFO ] [Python ] Interpreter at “/home/pi/wfpiconsole/venv/bin/python3”
[INFO ] [Logger ] Purge log fired. Processing…
[INFO ] [Logger ] Purge finished!
[INFO ] [Config ] Verifying station details
[INFO ] [Factory ] 195 symbols loaded
[INFO ] [Image ] Providers: img_tex, img_dds, img_sdl2, img_pil (img_ffpyplayer ignored)
[INFO ] [Window ] Provider: sdl2([‘window_egl_rpi’] ignored)
[INFO ] [GL ] Using the “OpenGL ES 2” graphics system
[INFO ] [GL ] Backend used
[INFO ] [GL ] OpenGL version <b’2.1 Mesa 20.3.5’>
[INFO ] [GL ] OpenGL vendor <b’Broadcom’>
[INFO ] [GL ] OpenGL renderer <b’VC4 V3D 2.1’>
[INFO ] [GL ] OpenGL parsed version: 2, 1
[INFO ] [GL ] Shading version <b’1.20’>
[INFO ] [GL ] Texture max size <2048>
[INFO ] [GL ] Texture max units <16>
[INFO ] [Window ] auto add sdl2 input provider
[INFO ] [Window ] virtual keyboard not allowed, single mode, not docked
[INFO ] [Text ] Provider: sdl2
[INFO ] [GL ] NPOT texture support is available
Traceback (most recent call last):
File “/home/pi/wfpiconsole/main.py”, line 621, in
wfpiconsole_app.run()
File “/home/pi/wfpiconsole/venv/lib/python3.9/site-packages/kivy/app.py”, line 955, in run
self._run_prepare()
File “/home/pi/wfpiconsole/venv/lib/python3.9/site-packages/kivy/app.py”, line 925, in _run_prepare
root = self.build()
File “/home/pi/wfpiconsole/main.py”, line 195, in build
self.screen_manager.add_widget(CurrentConditions())
File “/home/pi/wfpiconsole/main.py”, line 488, in init
self.add_panels()
File “/home/pi/wfpiconsole/main.py”, line 554, in add_panels
self.ids[button_id].add_widget(eval(secondary_panel + ‘Button’)())
File “”, line 1, in
NameError: name ‘ExampleButton’ is not defined

Rather than posting multiple “it still doesn’t work” followups it usually helps more if you attach the code you’re actually running.

That said - if you look back at the thread my followup was in you’ll see my example was based on somebody else’s working example. Unfortunately I missed a couple lines in the .py.txt file in my post from (wow) 2023 that you’re referencing.

Try adding this to your python file…

class ExampleButton(RelativeLayout):
    pass

For the ‘why’ - here’s wording from Pete’s github page:

In the customPanels.py file you must create two classes per custom panel called: [panel_name]Panel and [panel_name]Button. “panel_name” can be whatever you want, but you must add the two classes that end with Panel and Button per custom panel. The classes should be empty (just add pass under the class name), unless you want to add methods to your custom panel to control its behaviour. The classes required for the “BigTemperature” panel can be used as examples.

FWIW - I used ‘ExampleButton’ for ‘panel_name’ in my example so that should explain why my two files (once you add the two lines I forgot to post in 2023) look the way they do. Give it a try.

Gave it a try. Getting an error though in wfpiconsole.log:

IndentationError: expected an indented block

I’ve tried using a tab, setting the tab to 4 spaces, tried different text editors, and used nano. No matter what I do, I stll get the same error.

My code:

#-----------------------------

user/customPanels.py

#------------------------------
from kivy.uix.relativelayout import RelativeLayout
from panels.template import panelTemplate
from kivy.properties import Clock
from kivy.properties import StringProperty

import requests
import json

#-----------------------------------

do all the grabbing the data here

#-----------------------------------
class ExamplePanel(panelTemplate):

def __init__(self,**kwargs):
    super().__init__(**kwargs)
    self.updateData()
    Clock.schedule_interval(self.updateData,59)

def updateData(self, *args):

    data = self.get_data()

    # set the kivy panel element text
    self.ids.example_label.text = data

def get_data(self):

    try:
        # API endpoint URL for a PurpleAir AQI sensor
        url = "http://192.168.0.75/json"
        response = requests.get(url).json()
        return str(response['current_temp_f']) 
    except:

class ExampleButton(RelativeLayout):
pass

Error noted in wfpiconsole.log:

[INFO ] [Logger ] Record log in /home/pi/.kivy/logs/kivy_26-08-31_14.txt
[INFO ] [Kivy ] v2.3.1
[INFO ] [Kivy ] Installed at “/home/pi/wfpiconsole/venv/lib/python3.9/site-packages/kivy/init.py”
[INFO ] [Python ] v3.9.2 (default, Mar 12 2021, 04:06:34)
[GCC 10.2.1 20210110]
[INFO ] [Python ] Interpreter at “/home/pi/wfpiconsole/venv/bin/python3”
[INFO ] [Logger ] Purge log fired. Processing…
[INFO ] [Logger ] Purge finished!
[INFO ] [Config ] Verifying station details
[INFO ] [Factory ] 195 symbols loaded
[INFO ] [Image ] Providers: img_tex, img_dds, img_sdl2, img_pil (img_ffpyplayer ignored)
[INFO ] [Window ] Provider: sdl2([‘window_egl_rpi’] ignored)
[INFO ] [GL ] Using the “OpenGL ES 2” graphics system
[INFO ] [GL ] Backend used
[INFO ] [GL ] OpenGL version <b’2.1 Mesa 20.3.5’>
[INFO ] [GL ] OpenGL vendor <b’Broadcom’>
[INFO ] [GL ] OpenGL renderer <b’VC4 V3D 2.1’>
[INFO ] [GL ] OpenGL parsed version: 2, 1
[INFO ] [GL ] Shading version <b’1.20’>
[INFO ] [GL ] Texture max size <2048>
[INFO ] [GL ] Texture max units <16>
[INFO ] [Window ] auto add sdl2 input provider
[INFO ] [Window ] virtual keyboard not allowed, single mode, not docked
[INFO ] [Text ] Provider: sdl2
Traceback (most recent call last):
File “/home/pi/wfpiconsole/main.py”, line 128, in
from lib import settings as userSettings
File “/home/pi/wfpiconsole/lib/settings.py”, line 42, in
import user.customPanels # type: ignore
File “/home/pi/wfpiconsole/user/customPanels.py”, line 39
class ExampleButton(RelativeLayout):
IndentationError: expected an indented block

Note that what I copied into this post shows

class ExampleButton(RelativeLayout):
pass

The “pass” is truly indented.

I’m stumped.

Reply and attach the actual two files if you want us to be able to take a look. The forum software mangles things.

customPanels.py.txt (1.1 KB)

customPanels.kv.txt (608 Bytes)

Your bottom except block in the .py file needs something there.

My old example had:
return “n/a”

That helps. Any chance you’d share your py and kv code since yours works?

Untested recently so I don’t really remember the details too well any more. Looking at the attachment, I was displaying the temperature the PA returned in this example.

Obviously substitute in your own ip address and whatever field(s) you want to display…

customPanels.kv.txt (608 Bytes)
customPanels.py.txt (2.5 KB)

Thanks. And yours does work and show the PA temperature when the Example panel is chosen?

I’m getting this error in the log file:
File “/home/pi/wfpiconsole/main.py”, line 605, in switchPanel
self.ids[button_data[1]].add_widget(eval(new_panel + ‘Panel’)(mode))
TypeError: init() takes 1 positional argument but 2 were given