I made an improved NOAA Tides sensor for my family's summer house

I am seeing the tide showing up as NA. Not sure if it is related to the .112 update in HA or something else. A system restart brings it back.

I think it may actually be related to service issues with the NOAA API. I’m looking into ways to adjust the behavior so missing data don’t show up in the graph as flatlines.

0.0.3 improves the data retention a bit so that the tide level percentage is estimated based on old data when the NOAA API isn’t available.

2 Likes

So far, looks good. Buoy working easily. Now trying to learn how to do template math as buoy reports wind in m/s and degrees and I want knots and direction.
Getting the m/s to knots, was easy

value_template: "{{ state_attr('sensor.buoy', 'WSPD') | multiply(1.944) | float(2) }}"

It does not look easy converting degrees into N, NE, etc.
If anyone is interested, there is a discussion on:

https://stackoverflow.com/questions/7490660/converting-wind-direction-in-angles-to-text-words

Found an easier solution to get the basic eight wind directions from:

https://community.home-assistant.io/t/sensor-template-and-statements/1868/11

My buoy sensors:

  ny_harbor_water_temp:
    friendly_name: "buoy temperature"
    unit_of_measurement: 'degrees'
    value_template: "{{ state_attr('sensor.buoy', 'WTMP') }}"
  ny_harbor_wind_speed:
    friendly_name: "nyh_wind_speed"
    unit_of_measurement: 'knots'
    value_template: "{{ state_attr('sensor.buoy', 'WSPD') | multiply(1.944) | float(2) }}"
  ny_harbor_wind_direction:
    friendly_name: 'wind direction'
    unit_of_measurement: 'direction'
    value_template: >-
     {% set wind_dir = state_attr('sensor.buoy', 'WDIR') %}
     {% if wind_dir | float<=23 %}North
     {% elif wind_dir | float>338 %}North
     {% elif 23 < (wind_dir|float) <=68 %}NE
     {% elif 68 < (wind_dir|float) <=113 %}East
     {% elif 113 < (wind_dir|float) <=158 %}SE
     {% elif 158 < (wind_dir|float) <=203 %}South
     {% elif 203 < (wind_dir|float) <=248 %}SW
     {% elif 248 < (wind_dir|float) <=293 %}West
     {% elif 293 < (wind_dir|float) <=338 %}NW
     {%- endif %}

Thanks again for adding the buoy info.

Looks great. I may steal your templates. I’m surprised jinja2 lets you do all of that!

Check out this link for a better solution for the direction.

https://community.home-assistant.io/t/wind-direction/210532/4

from 
micque
Goes in the configuration.yaml. “your_wind_sensor” can be any name you choose and it will then appear as sensor.your_wind_sensor in the Tools/States UI. Sensor.wind_bearing is of course the name of the sensor from your weather station etc.

sensor:
  - platform: template
    sensors:
      your_wind_sensor:
        value_template: >
          {% set direction = ['N','NNE','NE','ENE','E','ESE','SE','SSE','S','SSW','SW','WSW','W','WNW','NW','NNW','N'] %}
          {% set degree = states('sensor.wind_bearing')|float %}
          {{ direction[((degree+11.25)/22.5)|int] }}

Thanks for this! I integrated it into my own dashboard:

image

Awesome work!

I was working on creating a wind speed compass card for Lovelace, but have had to put on hold since I am lacking time and could not figure out why the CSS is not working when INSIDE a card (it works when outside a card). Here is the link:

Installed exactly as described in the README and works great.

Any ideas how to do a next 24 hours tide chart? E.g. something like this:
https://www.tideschart.com/tides/en/Tulare-Beach-Port-Susan-United-States-tides-chart-ft.png

I would think that the code would need to be modified to pull in the additional tides data. As it is now written that data does not come into HA. On my tides near me app I go to the same chart location and the data on the first page is the same that HA gets. On the second page (tides for the week) this information is found Maybe Jacob can look to see if he can get this additional information easily?

As I understand it, the NOAA only provides real-time estimates for the next tide, low or high. 24 Hours would be 3-4 tides in the future.

Is it an estimate or a calculation? Around here, you could get tide charts for a year at any bait store. I don’t believe they are estimates but are calculations. The estimate would be how high or low based on season and moon but not taken into account storms (weather systems). Not sure what data you can pull but an app I use, tides near me, gives you all the tides for the week

It’s a “Tide Prediction” from the NOAA. I think the timing is very accurate, because it’s easy to calculate, as you mentioned. The prediction aspect is the relative water level, which is pulled into the sensor as an attribute.

https://tidesandcurrents.noaa.gov/water_level_info.html

Looking at the API again, it is possible to pull data in from further in the future.

I’m happy to make those changes, but there’s no easy way to draw a tide graph like the one Ryan asked about. I have no talent for frontend work, unfortunately.

Yes, I was going to post that predictions are available!

https://tidesandcurrents.noaa.gov/api/

However, like Jacob…I’m not familiar with frontend work. Hopefully someone with skills to create the graph can volunteer!

I don’t need to see future graphs but future tide times would be helpful.

Today on in seeing NA on 8531991 (long branch pier). My tides near me sees it correctly. Any ideas why it is failing in HA?

Any messages in the logs?

edit:

seeing a few cases of
2020-07-28 11:11:55 ERROR (SyncWorker_1) [custom_components.noaa_tides.sensor] Check NOAA Tides and Currents: ('Expecting value: line 1 column 1 (char 0)',)

in my logs. Seems like service instability from the NOAA. I’ll think about how to ruggedize the sensor against intermittent failures like this.

edit 2:
Seeing some connectionerror traces as well, confirming my suspicions. I’m adding in error handling for this as well as letting the sensor continue using data from the previous successful request instead of publishing NaN to state.

edit 3:

version 0.0.4 has some fixes for this, but i won’t be 100% certain the work until more instability from NOAA occurs. I’ll be keeping an eye out.

It started working again shortly after your reply. I’ll install version 0.0.4 and let you know if I see any errors. Sorry I did not check the log earlier.
When to the 0.0.4 and now both of my tides show NA.
In log

Logger: homeassistant.components.sensor
Source: helpers/entity_platform.py:139
Integration: Sensor (documentation, issues)
First occurred: 3:54:01 PM (3 occurrences)
Last logged: 3:54:01 PM

Setup of platform noaa_tides is taking longer than 60 seconds. Startup will proceed without waiting any longer.
The Lovelace UI configuration for this dashboard was updated, refresh to see changes?

Did another restart and one came back. Long Branch still shows NA.

the NOAA coops library makes 3 queries to the tides backend, and if all three fail, it raises an exception. I’m handling the exception now (though not in released code yet), and it seems to be behaving better, but there is still one edge case.

If you restart home-assistant and all 3 queries fail on startup, the sensor raises an exception during it’s initialization phase, and home-assistant core considers it to be kaput. This doesn’t appear to be recoverable. I’m going to mitigate this by catching the exception, leaving the sensor NULL until a subsequent update call attempts to reinitialize it.

TL;DR: there’s a way to make this less likely to happen, but since I can’t improve the NOAA’s backend there’s only so much I can do