WeeWX Forecast - Tides Question

102 views
Skip to first unread message

Rory Gillies

unread,
May 26, 2023, 6:47:57 AM5/26/23
to weewx-user
Hi,

I have the forecasting extension set up and working, and now have tides for my local port working on my ephemeris page: https://www.360shetland.co.uk/weather/almanac.html

The code I am using to display the tides is:

#if len($tides) > 0
<div class="col-12 col-lg-6 mb-4">
    <div class="card">
    <div class="card-body text-center">
    </br><h2 class="h5-responsive $Extras.color-text">High Tide</h5>
    <table class="table table-striped text-left">
        <tr>
        <td><b>Date</b></td></td><td><b>Time (local)</b></td><td><b>Height</b></td>
        </tr>
        #set $tides = $forecast.xtides
        #for $tide in $tides  
        #set $height=$tide.offset.raw / 3.281
        #if $tide.hilo == 'H'
        <tr>
           <td>$tide.event_ts.format("%a %d %b")</td>
           <td>$tide.event_ts.format("%H:%M")</td>
           <td>
           #echo '%.2f' % $height
          m </td>
        </tr>
        #end if
        #end for
    </table>
    </div>
    </div>
</div>
<div class="col-12 col-lg-6 mb-4">
    <div class="card">
    <div class="card-body text-center">
    </br><h2 class="h5-responsive $Extras.color-text">Low Tide</h5>
    <table class="table table-striped text-left">
        <tr>
        <td><b>Date</b></td></td><td><b>Time (local)</b></td><td><b>Height</b></td>
        </tr>
        #set $tides = $forecast.xtides
        #for $tide in $tides  
        #set $height=$tide.offset.raw / 3.281
        #if $tide.hilo == 'L'
        <tr>
           <td>$tide.event_ts.format("%a %d %b")</td>
           <td>$tide.event_ts.format("%H:%M")</td>
           <td>
           #echo '%.2f' % $height
          m </td>
        </tr>
        #end if
        #end for

    </table>
    </div>
    </div>
</div>
#else
<div class="col-sm">
    <h5 class="h5-responsive $Extras.color-text">The tide forecast is currently unavailable.</h5>
</div>
#end if


This produces two columns of tides - one for high tide and one for low tide - for the next 12 days, however I want to only display the tides for the next seven days. I have tried various ways to do this but I can't seem to get the correct syntax and the Cheetah Generator skips processing due to errors.

Any idea what syntax I need to use to display seven days rather than 12? It must be something to do with the lines:

        #set $tides = $forecast.xtides
        #for $tide in $tides  

Thanks,

Rory

Rory Gillies

unread,
May 27, 2023, 7:53:53 AM5/27/23
to weewx-user
OK, answered my own question again but it may be useful for others. I added a counter variable to the high and low tide tables ($counter) which increments as it runs through the loop. When it reaches 28 (29 for low tide) it exits the loop creating a nicely formatted tide table for seven days.

<div class="col-12 col-lg-6 mb-4">
    <div class="card">
    <div class="card-body text-center">
    </br><h2 class="h5-responsive $Extras.color-text">High Tide</h5>
    <table class="table table-striped text-left">
        <tr>
        <td><b>Date</b></td></td><td><b>Time (local)</b></td><td><b>Height</b></td>
        </tr>
        #set $tides = $forecast.xtides
        #set $counter = 0
        #for $tide in $tides
        #set $counter = $counter + 1
        #if $counter < 28
        #set $counter = 0
        #for $tide in $tides
        #set $counter = $counter + 1
        #if $counter < 29  

        #set $height=$tide.offset.raw / 3.281
        #if $tide.hilo == 'L'
        <tr>
           <td>$tide.event_ts.format("%a %d %b")</td>
           <td>$tide.event_ts.format("%H:%M")</td>
           <td>
           #echo '%.2f' % $height
          m </td>
        </tr>
        #end if
        #end if
        #end for

    </table>
    </div>
    </div>
</div>


And the seven day tide table:

Screenshot 2023-05-27 at 12.37.46.png

weather list

unread,
May 27, 2023, 11:28:19 AM5/27/23
to weewx...@googlegroups.com
Here’s another way to display tide forecasts.

--
You received this message because you are subscribed to the Google Groups "weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/f754b727-9dea-4106-b8d2-62700e02d813n%40googlegroups.com.
<Screenshot 2023-05-27 at 12.37.46.png>

Reply all
Reply to author
Forward
0 new messages