Haha, I very nearly had to put it on hold myself. Got slammed with loads of client work right after I committed it initially.
The amount of python I had to learn to achieve it was the easy part… Learning how to use Git properly and also getting my head around the HomeAssistant requirements was the part I struggled with! It’s well documented, but I made the mistake of trying to reference old platforms rather than specifically following the docs.
WorldTidesInfo API returns the time in seconds since the epoch.
I set the attributes to UTC because of the variety of formats I could have set it to if I displayed them as local time.
E.G, if I were to have it set to local time for my current low tide I could have:
2017-09-09T19:43+1000
07:43 PM
19:43
Given that, I figured there will always be cases where someone would rather display it in the alternate format, regardless of what I chose. So I decided the state could be set to something that was immediately human readable, and the attributes set to what’s commonly used as the standard.
If you want to display the attributes as individual sensors, the use of templates is required currently anyway, which can also display it in the desired format.
Great work. I was trying to work out how to do this with MQTT and found your contribution.
Is there any way to have the latest two tides showing? e.g. If was was low tide now, it would be great to see when the next high tide was too and vice versa. I know I can work it out but it would have a higher WAF with both displayed.
This is a complete configuration example. Fill in your API key, longitude and latitude. Please note that the worldtidesinfo sensor’s name is transformed into the entity id which in turn is required in the template sensor configuration.
sensor:
- platform: worldtidesinfo
api_key: <...>
name: My Favourite Beach
latitude: <...>
longitude: <...>
- platform: template
sensors:
tide_my_favourite_beach_next_high:
value_template: '{{ as_timestamp(states.sensor.my_favourite_beach.attributes.high_tide_time_utc) | timestamp_custom("%a %d/%m/%Y %H:%M") }}'
friendly_name: "My Favourite Beach Next High Tide"
tide_my_favourite_beach_next_low:
value_template: '{{ as_timestamp(states.sensor.my_favourite_beach.attributes.low_tide_time_utc) | timestamp_custom("%a %d/%m/%Y %H:%M") }}'
friendly_name: "My Favourite Beach Next Low Tide"
Hi, Does anyone know how I could use this to announce the next high tide 15 minutes before the high tide? I was thinking about a TTS component which would simply starte, “High tide in 15 minutes” and then have an automation which would use the condition of the time of the next high tide less 15 minutes…
sed is a standard Unix text editing/manipulation tool. It stands for Stream EDitor. Basically in the form used here it substitutes what is in the first group of / / with what is inside the second / /.
So it will search for every text matching the regular expression ^.*: and substitutes it with a zero length string.
My regular expression fu is weak, but I think the search string means look at the start of a line (^) followed by any character (.) repeated as many times as you like (*) followed by a colon (:). But don’t quote me on that - there are plenty of sed and regular expression tutorials on the web.
Have a look at my post above which shows how to create template sensors that convert the UTC timestamp, as long as you have correctly set your timezone in HA.
Please kindly check and correct for me as in the entity id. didn’t show the name given from worldtidesinfo.
in the entity id show the name from the template sensors with unknown state
Here is my configuration in sensor:
platform: worldtidesinfo
api_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxx
name: Koh Samui Tide
latitude: 9.6
longitude: 100.067
platform: template
sensors:
tide_big_buddha_beach_next_high:
value_template: '{{ as_timestamp(states.sensor.koh_samui_tide.attributes.high_tide_time_utc) | timestamp_custom("%a %d/%m/%Y %H:%M") }}'
friendly_name: "Big Buddha Beach Next High Tide"
tide_big_buddha_beach_next_low:
value_template: '{{ as_timestamp(states.sensor.koh_samui_tide.attributes.low_tide_time_utc) | timestamp_custom("%a %d/%m/%Y %H:%M") }}'
friendly_name: "Big Buddha Beach Next Low Tide"
my sensor: is in individual file so the space and dash is from the one I posted above. Sorry for my bad english, I don’t understand much. But I will try to explain.
What I don’t understand is the one in the template (value_template). you said that the state sensor name will be the name from the worldtidesinfo (koh_samui_tide)? not from the entity id from template sensor (sensor.tide_big_buddha_beach_next_high_tide)?
value_template: '{{ as_timestamp(states.sensor. koh_samui_tide.attributes.high_tide_time_utc) | timestamp_custom("%a %d/%m/%Y %H:%M") }}'
friendly_name: "Big Buddha Beach Next High Tide"
value_template: '{{ as_timestamp(states.sensor.tide_big_buddha_beach_next_hight.attributes.high_tide_time_utc) | timestamp_custom("%a %d/%m/%Y %H:%M") }}'
friendly_name: "Big Buddha Beach Next High Tide"
Regarding for the date time in red that you mention. Do I have to change anything ?