Custom panel to display tide information

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 endpoint 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 that is within the wfpiconsole folder; obviously, strip.the .txt extension:
customPanels.py.txt (7.0 KB)
customPanels.kv.txt (3.2 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 (7.0 KB)
customPanels.kv.txt (3.2 KB)

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.

2 Likes

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.

3 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

I got this panel working with relative ease. Many thanks @robert.jochim for simple destructions.

Is there anyway to show future 24hr tides? As I understand it now, it only shows the tides of the day. At 11:50PM, it only shows that current day’s tides. At Midnight, it will rollover and show the next 4 tides.

I guess I’m looking for the ability to see the next 4 tides based on current time. Not sure if this is possible or I have grossly missed a parameter. Or it’s likely that I didn’t read closely enough.

Nonetheless, it’s a cool panel addon, and I am grateful for it.

I just tried to install the tide panel on a RPI3B+ running Bullseye and v23.10.1. I do not see the tide panel after reboot. Does this still work on 23.10.1? I looked in wfpiconsole.log and I don’t see any errors.

Yes, it does. I’m running Bullseye and v23.10.1. In WeatherFlow PiConsole, under Menu > Settings > Secondary Panels, make sure you have “Tides” selected as an option for one of the six main panels. I stuck mine under Panel Five.

EDIT: But then, I’m running a Pi that was upgraded from Buster to Bullseye, so I had already had Tides selected. Then I removed Tides as a secondary panel from Panel Five, and found I could not re-select it, as I could not scroll down the list of available secondary panels, even though the Scrollbar is visible within that selection window (at least the Thumb portion of the Thumb / Track components that make up the Scrollbar). So there is an underlying issue in play. I think I’ll have to enlist help from @peter on this one…

@peter solved the mystery: Issue with modifying / adding secondary panels - #3 by peter

How does one access the wfpiconsole directory/user directory

If you have a default installation of the Raspberry Pi OS, the easiest way is to select the folders icon on the top bar. From there you get a visual directory listing just like most other OSes.
image

I know I am missing the obvious but how do I paste into the user folder

Thanks

There are many ways to accomplish this, but one way of doing it:
Stop wfpiconsole
In the User directory, rename existing customPanels.kv and customPanels.py to customPanels.kv.bak and customPanels.py.bak, respectively, so you can easily revert back.
Within the User directory’s File listing pane on the right, right-click anywhere and select New File…
As the name of the file, type in customPanels.kv
Now right click on the empty file and select Text Editor to open the empty customPanels.kv
Copy and paste the contents of the customPanels.kv.txt into the empty customPanels.kv and save your changes.
Do the same for the customPanels.py, cutting and pasting the contents of the customPanels.py.txt file and save your changes
Restart wfpiconsole