RESTful sensor json help - Australian tide predictions (BOM)

No probs but I don’t feel I deserve that solution tag. it was @lolouk44 who solved the restful sensor problem.

1 Like

I’ll mark both as the solution, yours has a complete working example for others coming here.

This was my first post on the forum and it was a really positive experience. Thanks again. To the three of you @tom_l, SteveDinn and @lolouk44

1 Like

This is awesome. I was looking for this. I changed the location and it works. I also added this sensor:

hobart_tide_dir:
  entity_id: sensor.hobart_tides
  friendly_name 'Tide Direction'
  value_template: >-
    {% if (states('sensor.hobart_tides')|from_json).next_high.time|int < (states('sensor.hobart_tides')|from_json).next_low.time|int %}
      Rising
    {% else %}
      Falling
    {% endif %}

I couldn’t find anything from the API, but if there is a way to pull the previous tide high and low values, you could calculate the current tide since the tide cycle is of a predictable duration. If not, could you save the previous value?

This worked for me. Thanks for sharing.

Interesting. I stopped using it a while ago as I had no use for it. I thought the recently implemented BoM anti-scraping measures might have stopped it working.

Sorry I may have missed it but I can not find the details on BOM to change the location, I want to get the tides for Ettalong in NSW.

Would someone please be able to point me in the right direction

Also i was having a look at tides4fishing and really like the way they display the tides, is there any way to copy this over to home assistant.

To find what the URL needs to be for your location, go to http://www.bom.gov.au/australia/tides/ and select your location, then download one of the tide chart pdfs. The filename of the pdf will end with something like VIC_TP020 - substitute this with the URL and then change the timezone city as appropriate.

Hi Guys,

Cant get this URL to work for my location to save my life…
Anyone crack it for me? Will prob be bashing my head because its something simple…

http://www.bom.gov.au/australia/tides/scripts/getNextTides.php?aac=TAS_TP003&offset=false&tz=Australia%2FHobart

Location: Camp Cove, NSW
LOCATION: NSW_TP011
TZ: Sydney

New URL: http://www.bom.gov.au/australia/tides/scripts/getNextTides.php?aac=NSW_TP011&offset=false&tz=Australia%2FSydney

But that url is invalid and cannot figure out to save my life lol

Help appreciated :wink:

I’ve been able to get this working using that location:

rest:
  - resource: "http://www.bom.gov.au/australia/tides/scripts/getNextTides.php?aac=NSW_TP011&offset=false&tz=Australia%2FSydney"
    headers:
      User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36
      Content-Type: application/json
    sensor:
      - name: "Sydney Low Tide Height"
        value_template: "{{ value_json.results.next_low.height }}"
        unit_of_measurement: "m"
      - name: "Sydney High Tide Height"
        value_template: "{{ value_json.results.next_high.height }}"
        unit_of_measurement: "m"
      - name: "Sydney Low Tide Time"
        value_template: "{{ value_json.results.next_low.time | timestamp_local }}"
      - name: "Sydney High Tide Time"
        value_template: "{{ value_json.results.next_high.time | timestamp_local }}"
1 Like

Hi Dom,

Thanks for this… Works a charm

Only issue I see is time/date format reporting the follwoing “2023-06-21T22:28:00+10:00” for sensor

Cheers
G

It should just work using your local time/date as set in HA.

The time/date just comes through from the BOM as epoch time, so you should be able to pipe that to any format you want - change timestamp_local to any custom timestamp you want. The first couple of posts in this threat should be helpful: Convert date and time template

Thanks all for this.

I consolidated a bit like this:

rest:
  - resource: http://www.bom.gov.au/australia/tides/scripts/getNextTides.php?aac=VIC_TP020&offset=false&tz=Australia%2FMelbourne
    headers:
      User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36
      Content-Type: application/json
    scan_interval: 21600 # Every six hours.
    sensor:
      - name: "Melbourne Tide Update Time"
        value_template: "{{ value_json.results.current_time | int | timestamp_custom('%I:%M %p', true) }}"
      - name: "Melbourne High Tide Time"
        value_template: "{{ value_json.results.next_high.time | int | timestamp_custom('%I:%M %p', true) }}"
      - name: "Melbourne High Tide Height"
        value_template: "{{ value_json.results.next_high.height }}"
        unit_of_measurement: "m"
      - name: "Melbourne Low Tide Time"
        value_template: "{{ value_json.results.next_low.time | int | timestamp_custom('%I:%M %p', true) }}"
      - name: "Melbourne Low Tide Height"
        value_template: "{{ value_json.results.next_low.height }}"
        unit_of_measurement: "m"

image

Edit: I might even just have one description sensor that merges them all as I think I just want some rising and bedtime announcements.

      - name: "Melbourne Tides Next Times Description"
        value_template: >
          The next low tide is {{ value_json.results.next_low.height | round(1) }} meters 
          at {{ value_json.results.next_low.time | int | timestamp_custom('%I:%M %p', true) }}. 
          The next high tide is {{ value_json.results.next_high.height | round(1) }} meters 
          at {{ value_json.results.next_high.time | int | timestamp_custom('%I:%M %p', true) }}.

I’m thinking I must be particularly thick, but how do I work out the address of the tide station? e.g. the parameters called by the php script?

I’m looking at Brisbane or Serpentine Creek, which by using Inspect in the brower, I come up with QLD_TP104 for Serpentine Creek, and QLD_TP003 for Brisbane Bar, but when I put them in the address with the script, both just redirect to the BOM home page, yet if I use the Melbourne and Hobart examples earlier in the thread, both work

I’m trying with the two URL’s below, both of which fail… no idea what I’m doing wrong on this one

http://www.bom.gov.au/australia/tides/scripts/getNextTides.php?aac=QLD_TP003&offset=false&tz=Australia%2FBrisbane

and

http://www.bom.gov.au/australia/tides/scripts/getNextTides.php?aac=QLD_TP104&offset=false&tz=Australia%2FBrisbane