You may also want to consider using the JSON attributes property on that REST sensor. It’ll break all that stuff out into the sensor attributes if you want.
Just remember that if you can access fields on it, it’s not actually JSON, it’s an in-memory object that is constructed USING the JSON. The default “string” form is python’s native one, which is that weird, single-quoted JSON-like string. To get it to an ACTUAL JSON string, you need ‘to_json’.
Hrm…Maybe I’m wrong in that regard, but you have to be careful that the actual state doesn’t exceed 255 characters. The attributes don’t have that limitation.
Thanks guys for all the input really appreciate it. I’m sure I’ll be able to use your suggestions above to get it working.
In the interests of completeness another approach that I think is close, is to use command_line combined with an inline python script. I’ve tried two versions;
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?
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.
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.
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
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