Custom panel to display tide information

EDIT: This is what the finished custom panel for tides looks like after many trials and tribulation:

I stuck it in Secondary Panel position 5, so I duplicated the Time and Date from the Rainfall Primary Panel. It works by querying info from the the Tide Predictions - NOAA Tides & Currents page. Use that page to find the closest Tide station to you. What you need is the 7-digit station ID of that Tidal station. Then in customPanels.py, and within the ``def update_tides(self, *args):edit the line that specifies the URL in which to steal the data from hourly:

url = "https://api.tidesandcurrents.noaa.gov/api/prod/datagetter?date=today&range=48&station=8466791&product=predictions&datum=MLLW&time_zone=lst_ldt&interval=hilo&units=english&application=DataAPI_Sample&format=xml"

Substitute your own 7-digit tide station ID where mine says 8466791.
Here are the files that go into the user folder within the wfpiconsole folder, obviously, strip.the .txt extension:
customPanels.kv.txt (2.0 KB)
customPanels.py.txt (3.5 KB)

===== ORIGINAL POST AND THREAD FOLLOWS =====

I’ve literally been trying to do this for weeks with no joy; while it’s very simple to modify and display BigTemp, creating a custom panel is giving mee and my family fits, I’ve gone through hundreds of permutations of this, but It just will not work for me. As I live on the shore, I want to create a panel that shows today’s high and low tides, by accessing and parsing the API XML tide data from NOAA.
customPanels.py.txt (1.3 KB)
customPanels.kv.txt (712 Bytes)

Any insight would be much appreciated… I know the output for the panel isn’t formatted correctly, but I would love even to get to that concern. Literally weeks, and the past 2 days SOLID.

1 Like

So what errors do you get and/or what does what you cooked up look like ? Kinda hard to help with your problem description…

1 Like

While the button appears, the program will crash when button is pushed. this particuar permutation of the code generates this particular message:
traceback.txt (1.6 KB)

but this is one of hundreds of permutations I’ve tried. most with differing errors. Even though I acquired a brain injury 20 years ago, most things I can work through, but this has me stumped.

It looks like you have changed the value of on_release for the <TidesButton> in the customPanels.kv file. The BigTemperature example given looks like this:

<BigTemperatureButton>:
    PanelButton:
        text: 'BigTemp'
        on_release: app.CurrentConditions.switchPanel(self)

Have you overwritten on_release for any paticular reason? If not, the first step would be to change it back to on_release: app.CurrentConditions.switchPanel(self)

Yes, that is one of many iterations:
customPanels.kv
customPanels.kv.txt (717 Bytes)

And the .py file:
customPanels.py.txt (1.8 KB)

Generates this error:
traceback.txt (1.8 KB)

Having ChatGPT analyze it suggests:
ChatGPT.txt (604 Bytes)

This is one of the reasons I experimented with changing the on_release: in the first place. I just keep going in circles.

Look at the indentation of def update_tides(self, *args): in the third code block you shared (the one above the error message). You can see that it has the same indent level as the TidesPanel(panelTemplate): class declaration, and therefore it is not a member of the TidesPanel class (hence the error message: AttributeError: 'TidesPanel' object has no attribute 'update_tides'). Increase the indent so it aligns with the __init__ method and that should fix that particular error message.

Thank you. Many errors from cutting and pasting over and over and over. Anyways…
This is what the finished custom panel for tides looks like after many trials and tribulation:

I stuck it in Secondary Panel position 5, so I duplicated the Time and Date from the Rainfall Primary Panel. It works by querying info from the the Tide Predictions - NOAA Tides & Currents page. Use that page to find the closest Tide station to you. What you need is the 7-digit station ID of that Tidal station. Then in customPanels.py, and within the ``def update_tides(self, *args):edit the line that specifies the URL in which to steal the data from hourly:

url = "https://api.tidesandcurrents.noaa.gov/api/prod/datagetter?date=today&range=48&station=8466791&product=predictions&datum=MLLW&time_zone=lst_ldt&interval=hilo&units=english&application=DataAPI_Sample&format=xml"

Substitute your own 7-digit tide station ID where mine says 8466791.
Here are the files that go into the user folder within the wfpiconsole folder, obviously, strip.the .txt extension:
customPanels.kv.txt (2.0 KB)
customPanels.py.txt (3.5 KB)

It works by querying the NOAA API, and then creating a local file based on the API response. I tried numerous times to parse the response directly from the API, but was unable. Once the response file has been created, it is parsed and displayed. A new query and file is created hourly to keep the info current. I’m not responsible if you run aground or drown. :neutral_face:
Thank you, Peter! :smiley:

5 Likes

wow - that helps me so much in trying to do similar things. Thanks for posting !!!

Possibly dumb question - it’s been a lot of years since I parsed XML with python, but couldn’t you skip the writing/reading of the intermediate tidedata.xml file completely by just parsing the url response right away ?

You also might want to write your .xml file out to a tmpfs partition to save on SD writes. Not likely a problem for your program since you query the URL so infrequently but I thought I’d mention it.

1 Like

Yes, parsing the xml directly was what my original intention had been, and I spent many hours chasing that. The URL returns a valid XML response, but I could find no way to successfully parse it directly. So, I figured I’d buffer the response and parse that. There’s something about the returned structure of the XML that either of the two Python parsing methods (string or element,) finds incompatible.

Just for another example - here’s what I did to grab data from my Purple Air based on your great example (thanks) in case it helps any…

I added a try/except block around the url request, and also used a 59-sec query period for mine to try to not step on queries from a weewx system that already queries the PA on 5-minute boundaries.

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

Thanks again for posting a ‘complete and working’ example. Helps beyond belief.

2 Likes

I love the tide graph, I’m not near the beach but always fascinated my tides! But this is above my pay grade!

It’s really easy to implement,- just copy these two files into the User directory that’s within the wfpiconsole directory:
customPanels.kv.txt (2.0 KB)
customPanels.py.txt (3.5 KB)

After copying them there, rename each of them by stripping off the .txt file extension, so the files end with .ky & .py, respectively.

After renaming them, restart wfpiconsole so it checksfor the existence of those two files.

Once restarted, go to the (Menu) button all the way over on the bottom right.

Once in the (Menu), select (Settings), then [Secondary Panels] on the left.

Once in there, choose where you want the custom panel to appear. I choose Panel Five. Because wfpiconsole read the contents of the User directory on startup, among the potential choices will now be one called “Tides”.

once finished and backed all the way out of the menu settings, on the bottom left will be a new button labeled “Tides” - pressing that button will toggle between the primary panel “Rainfall” and the new panel “Tides”.

If you haven’t edited the customPanels.py file, the tides you will see listed are for the NOAA tide measurement station near the mouth of the Housatonic river in Connecticut where it empties into Long Island Sound.

Go to Tide Predictions - NOAA Tides & Currents and find the 7-digit id of the station nearest you or that you want displayed. In that customPanels.py file, just edit it and substitute your number for mine, save the file, then restart wfpiconsole.

That’s pretty much it!

1 Like