Tide Times

I really am loving HASS. After a couple of months of playing I am starting to form a setup that I’m getting really happy with. Kudos to all the developers involved in creating a super friendly home automation platform (I’ve tried many others) and I’m fully converted!

There seems to be no limit to what is possible and, as I live near the sea, I thought it’d be cool to have a Tide Times Sensor so that I can know when the next high tide and low tide will be. I’m also hoping to create some cool automations for the future.

e.g. If it’s low tide in an hour, the temperature is above a certain amount and the sun is above the horizon send me a notification “Head to the beach!”

I’m a complete rookie with Python but I managed to cobble something together and integrate it with my setup using the Command line Sensor. It’s probably not the most elegant code but it works :slight_smile:

If there’s any interest in a sensor like this for measuring the tides I’d love to give back by helping to integrate this in as an official HASS component.

11 Likes

Comments must be at least 10 Characters so I’ll just say

Cool!!!

Wish I lived near the beach.

A great idea - you should post your code as I am sure others will try this out. I’d like to see how you did this to see if it could be adapted for river heights.

I also would like to point out that you made very good choices for your MDI icons! They really work well for what you are measuring.

I also live near the beach and this would be incredibly useful to have as part of my own set up, great work. I’d love to see this as a HASS component.

Let me join the group and say that I would really enjoy this feature as well. We live a few miles from the beach and would like to know the tide conditions before I head out.

Awesome, would you mind posting your code/scripts please? I’ve been looking to do the same thing with another app on my Pi; and i’m new to Python as well.

Thanks,

Thanks so much everyone! So glad this could possibly be helpful.

I bet there is a much more efficient way to gather this data.

Right now, my script is pulling from the UK Met Office website. It’d be great to make this an international sensor using data sources from other countries.

I wonder if there is a tide times website/feed for the world?

I’d love to hear ways to improve if you test it out. Here’s what I have so far:

2 Likes

https://www.worldtides.info/apidocs - 1000 free calls per month, plenty for tide data scraping.

Or perhaps http://www.psmsl.org/data/

In Australia I have used the WillyWeather API, free for first 5000 requests.

There is already a Wunderground component that might be usable as a sensor?

https://www.wunderground.com/weather/api/d/docs?d=data/tide

YES YES YES please!!! I have been thinking this would be awesome for a long time. I walk my dog on the beach and being able to quickly see when the low tide is would be great!

Do i only need the tides.py file? What do the tidestore.py and tidestorex.py do?

Thanks for the ideas @BarryHampants - much appreciated.

World Tides seems, at first glance, to be a great way of expanding to The Netherlands, New Zealand, Norway and the US. I wish there was a truly global tide times resource or API.

The Met Office seems to be working well for UK tide times and after running it for nearly a week all seems well.

@eximo84 tides.py runs once a day (as a cronjob you create) and it grabs the latest tide data from the Met Office website. It then stores the data as variables inside tidestore.py and tidestorex.py. Home Assistant will run tideupdate.py as a command line sensor to grab the latest tide data from either tidestore.py or tidestorex.py

You only need tides.py and tideupdate.py for it to work then tidestore.py and tidestorex.py are created automatically for you on the first run of tides.py

Thanks for your reply. I have downloaded the two files, added them into my homeassistant directory and edited the location and website address for the metoffice.

However when i attempt to execute python tides.py i get the following error:

Traceback (most recent call last):
  File "tides.py", line 1, in <module>
    import requests
ImportError: No module named requests

I tried with python3 and python3.4 and i get the following error:

  File "tides.py", line 15
    print "ERROR 0"
                  ^
SyntaxError: Missing parentheses in call to 'print'

Adding the new line to my crontab results in this also:

crontab: installing new crontab
"/tmp/crontab.e2xCTI/crontab":31: bad command
errors in crontab file, can't install.

Any ideas?

There is a free api at magicseaweed which has quite a few world locations but it would require each user to sign up for their own key. Details here http://magicseaweed.com/developer/forecast-api

I’ve never looked much further than my own backyard but it seems the global tide info services either aren’t free or don’t have an API. It’s something that seems like it should be readily available for maritime safety.

Thanks for this post, it wasn’t giving the right values and I couldn;t figure out why, so i deleted tidestore and tidestorex, ran tides.py again and now its all working sweet as a nut!! Thank you for this component its great!

It seems Requests for Python isn’t installed on your machine. Try this to get it:

pip install requests 

@BarryHampants that API looks promising. I couldn’t see tide in the docs but a surf conditions sensor would be really cool!

@daan_vb great to hear you got it working :slight_smile:

Already says i have requests installed. For reference im using pip3 as i dont have pip ?

Ok got it working. For reference I changed the following code, where ever PRINT was used I had to add () to make it work for python3.4

print "ERROR 0"

print("ERROR 0")

Also on tide update.py anywhere it had the following, it gave an invalid token for time(6,02). Not sure what that relates to but I got it working by changing that to (6,00)

if now_time >= time(0,00) and now_time <= time(6,02)

Is what I have changed ok? What does time(6,02) do?

Great catch @eximo84 - thanks for figuring this out.

I’ve pushed an update to the code so that it should work with Python 3+ thanks to you:

https://github.com/imikerussell/TideTimes/commit/6632475f6f67abf8afa2b56aa141416736aacf0b

I changed the (6,02) to (6,2) as it seems Python 3+ doesn’t like leading 0s.

This is in place to allow the 6:00am cronjob to run without changing tide data inside HASS. If you change the value to (6,00) you’ll likely get one minute of incorrect data in your HASS log entry for tides at exactly 6:00am while tide data updates for the day ahead hence 6:02am to give enough time for the cronjob to complete.

Awesome, i thought it might be the actual time but i wanst sure if it was formatting or something. Im glad its working though, i will definitely be using this in some notifications to let us know when the tide is out and the weather is nice.

Would it be possible to add a new file called “location” and then pull the variables for the locations into the main tides.py file. That way new changes that get pulled down wont wipe out my custom locations.

Also @imikerussell - your cron tab line is incorrect. You have an extra *

Should be 0 6 * * * /usr/bin/python /home/hass/TideTimes/tides.py