GithubHelp home page GithubHelp logo

jshufro / home_assistant_noaa_tides Goto Github PK

View Code? Open in Web Editor NEW
23.0 10.0 4.0 47 KB

A fork of Home Assistant's NOAA Tides sensor with additional features.

Python 100.00%
home-assistant beaches tides tidesandcurrents lovelace-ui

home_assistant_noaa_tides's Introduction

NOAA Tides and Currents Sensor for Home-Assistant

This library is a fork of the core component which adds some additional features and migrates the backend from the now-defunct py_noaa to the superseding noaa_coops.

Installation

  1. Clone the repository.
  2. Copy the noaa_tides directory into <home assistant directory>/custom_components/
  3. Configure a sensor in configuration.yaml

Sample configuration

sensor:
  - platform: noaa_tides
    name: tides           # Useful when more than one sensor is used. Otherwise a name is generated.
    station_id: 8512354   # A station ID from https://tidesandcurrents.noaa.gov/
    type: tides           # This station will be used to measure water level
    scan_interval: 360    # Polling interval for the NOAA API

  - platform: noaa_tides
    station_id: 8510560
    type: temp            # This station will be used to measure water temperature
    name: water_temp
    scan_interval: 360

  - platform: noaa_tides
    name: buoy
    type: buoy            # This station will be used for off-shore Buoy data
    station_id: 44017     # A buoy ID from https://www.ndbc.noaa.gov/
    scan_interval: 360

Different stations support different features (products/datums), so use the station finder to select the right station for tides vs temp types.

For complex lovelace widgets, it is suggested to use the template platform.

Sample template sensor:

        next_tide:
            friendly_name: "Next tide"
            entity_id: sensor.tides
            value_template: "{{ state_attr('sensor.tides', 'next_tide_type') }} tide at {{ state_attr('sensor.tides', 'next_tide_time') }}"
            icon_template: "{% if is_state_attr('sensor.tides', 'next_tide_type', 'High') %}mdi:waves{% else %}mdi:wave{% endif %}"
        last_tide:
            friendly_name: "Last tide"
            entity_id: sensor.tides
            value_template: "{{ state_attr('sensor.tides', 'last_tide_type') }} tide at {{ state_attr('sensor.tides', 'last_tide_time') }}"
            icon_template: "{% if is_state_attr('sensor.tides', 'last_tide_type', 'High') %}mdi:waves{% else %}mdi:wave{% endif %}"
        water_level:
            friendly_name: "Water level"
            entity_id: sensor.internet_time
            value_template: "{{ state_attr('sensor.tides', 'tide_factor') }}"
            unit_of_measurement: '%'
        beach_air_temp:
            friendly_name: "Air temperature"
            entity_id: sensor.water_temp
            value_template: "{{ state_attr('sensor.water_temp', 'air_temperature') }}"

Note that the tide curve requires sensor.internet_time to be updated correctly. Use the time_date sensor platform like this:

  - platform: time_date
    display_options:
      - 'beat'

I'm also using the custom mini-graph card with the following lovelace configuration:

          - entities:
              - color: '#02ace5'
                entity: sensor.beach_air_temp
                name: Air
                show_state: true
                state_adaptive_color: true
              - color: darkblue
                entity: sensor.water_temp
                name: Water
                show_state: true
                state_adaptive_color: true
            hours_to_show: 24
            name: Air and Water Temperatures
            points_per_hour: 12
            show:
              fill: false
            type: 'custom:mini-graph-card'
            unit: °F
          - entities:
              - entity: sensor.next_tide
              - entity: sensor.last_tide
            footer:
              entities:
                - sensor.water_level
              hours_to_show: 12
              icon: 'mdi:swim'
              line_color: darkblue
              lower_bound: 0
              points_per_hour: 60
              show:
                labels: false
              type: 'custom:mini-graph-card'
              upper_bound: 100
            title: Tides
            type: entities

Which looks like this:

Lovelace Configuration

Support

For setup and other support questions, see the Home Assistant community discussion for this add-on.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

home_assistant_noaa_tides's People

Contributors

jshufro avatar rsnodgrass avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

home_assistant_noaa_tides's Issues

Failing to retrieve temperature from station

My attempt to configure a temp sensor is failing with the following error occurring in the logs.

Logger: custom_components.noaa_tides.sensor
Source: custom_components/noaa_tides/sensor.py:295
Integration: noaa_tides
First occurred: 4:11:06 PM (2 occurrences)
Last logged: 4:11:07 PM

Check NOAA Tides and Currents: ('No data was found. This product may not be offered at this station at the requested time.',)

sensor:
  - platform: noaa_tides
    name: canal_tide
    station_id: 8726520
    type: tides
    scan_interval: 360
  - platform: noaa_tides
    name: canal_temp
    station_id: 8726520
    type: temp
    scan_interval: 360

As far as I can tell, the necessary data should be available: https://tidesandcurrents.noaa.gov/inventory.html?id=8726520

Tide sensor status changing at incorrect time.

The status of my tide sensor seems to be changing ~4 hours before the actual tide change.
The configured NOAA station and my Home Assistant service are both located in the eastern time zone where the offset is currently UTC-4.
I am uncertain whether this is a configuration issue or a bug in the code.

image

sensor:
  - platform: noaa_tides
    name: canal_tide
    station_id: 8726520
    type: tides
    scan_interval: 360

New Home Assistant Requirement

No 'version' key in the manifest file for custom integration 'noaa_tides'. This will not be allowed in a future version of Home Assistant. Please report this to the maintainer of 'noaa_tides'

How do I get the water level

Core
2024.2.1
Supervisor
2024.01.1
Operating System
11.5
Frontend
20240207.1

My Yaml Code

Example configuration.yaml entry

  • platform: time_date
    display_options:
    • 'beat'

Example configuration.yaml entry

sensor:

  • platform: noaa_tides
    station_id: 9414523 # A station ID from https://tidesandcurrents.noaa.gov/
    type: tides # This station will be used to measure water level
    scan_interval: 360 # Polling interval for the NOAA API

  • platform: noaa_tides
    station_id: 9414523
    type: temp # This station will be used to measure water temperature
    name: water_temp
    scan_interval: 360

  • platform: noaa_tides
    name: buoy
    type: buoy # This station will be used for off-shore Buoy data
    station_id: 44017 # A buoy ID from https://www.ndbc.noaa.gov/
    scan_interval: 360

New Issue in Beta 2023.9

Seeing the following error in the beta:
"
This error originated from a custom integration.

Logger: py.warnings
Source: custom_components/noaa_tides/sensor.py:228
Integration: noaa_tides (documentation)
First occurred: August 30, 2023 at 10:02:46 PM (76 occurrences)
Last logged: 5:32:46 AM

/config/custom_components/noaa_tides/sensor.py:228: FutureWarning: Series.getitem treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use ser.iloc[pos] self.attr["air_temperature"] = self.data[1].air_temp[0]
"

Station name and ID returned attributes

I'm sure there has to be a better way to accomplish this than what I show below. Neither the original or your code seem to return the name and ID of the reporting station. Since you can have multiple or need different stations if water temperature not reported at your nearest station. Recording the source of the data may be useful:

    attr["station_name"] = self._station.metadata['name']
    attr["station_id"] = self._station.metadata['id']

HA type

So, it seems that HA doesn't like that you use type: tides or type: temp.
Kinda makes sense as that's what they use for defining types of cards and custom entities.
As you already use 'station_id', perhaps you could just rename 'type' to 'station_type' instead?

Issue in new beta Home Assistant 2023.6.0b0

With the new beta installed I am getting the following errors:
Platform error sensor.noaa_tides - cannot import name 'json_normalize' from 'pandas.io.json' (/usr/local/lib/python3.11/site-packages/pandas/io/json/init.py).
Maybe related to the update of python to 3.11?

home-assistant.log - Error while setting up noaa_tides platform for sensor

I recently discovered your enhanced version of noaa_tides and really enjoy the features you added. I am running home assistant 0.113.0 and noticed the following error in my home-assistant.log file:

2020-07-27 12:23:21 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up noaa_tides platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 179, in _async_setup_platform
    await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
  File "/usr/local/lib/python3.8/asyncio/tasks.py", line 483, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/noaa_tides/sensor.py", line 72, in setup_platform
    noaa_sensor.update()
  File "/config/custom_components/noaa_tides/sensor.py", line 335, in update
    _LOGGER.error("Received HTTP code %i from %s query", (r.status_code, self._station_url))
  File "/usr/local/lib/python3.8/logging/__init__.py", line 1463, in error
    self._log(ERROR, msg, args, **kwargs)
  File "/usr/local/lib/python3.8/logging/__init__.py", line 1577, in _log
    self.handle(record)
  File "/usr/local/lib/python3.8/logging/__init__.py", line 1587, in handle
    self.callHandlers(record)
  File "/usr/local/lib/python3.8/logging/__init__.py", line 1649, in callHandlers
    hdlr.handle(record)
  File "/usr/local/lib/python3.8/logging/__init__.py", line 950, in handle
    self.emit(record)
  File "/usr/src/homeassistant/homeassistant/components/system_log/__init__.py", line 180, in emit
    entry = LogEntry(
  File "/usr/src/homeassistant/homeassistant/components/system_log/__init__.py", line 97, in __init__
    self.message = deque([record.getMessage()], maxlen=5)
  File "/usr/local/lib/python3.8/logging/__init__.py", line 369, in getMessage
    msg = msg % self.args
TypeError: %i format: a number is required, not tuple

As far as I can tell, the component is working properly.

How to get NOAA Actual Tide Water Level (not just predicted levels)?

Is there a way to get the actual water level as in the attached NOAA tides view?

It looks like the Water Level I currently get is a percentage. In order to get the predicted level, I take the (((high tide - low tide) * water level) / 100) + low tide ... this gives me a smooth curve between the predicted high tide and the predicted low tide for the current predicted level. However, this does not represent the actual as measured tide level. I.E. doesn't show storm surge water levels. The NOAA Tides web site has this data but not clear how to get that actual tide level.

NOAA Tides

NOAA Tiles

I am getting the following error with 2023.3.0 and newer

Logger: homeassistant.components.sensor
Source: custom_components/noaa_tides/sensor.py:63
Integration: Sensor (documentation, issues)
First occurred: 7:08:28 PM (2 occurrences)
Last logged: 7:08:28 PM

Error while setting up noaa_tides platform for sensor
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 293, in _async_setup_platform
await asyncio.shield(task)
File "/config/custom_components/noaa_tides/sensor.py", line 63, in async_setup_platform
elif hass.config.units.is_metric:
AttributeError: 'UnitSystem' object has no attribute 'is_metric'

2021.6.1 Breaks NOAA Tides Integration

Not sure if this is an integration issue or HA problem but new HA version is complaining that 'type' in the yaml config is an invalid option.

Error msgs:
Logger: homeassistant.config
Source: config.py:443
First occurred: 1:34:24 PM (2 occurrences)
Last logged: 1:34:24 PM

Invalid config for [sensor.noaa_tides]: [type] is an invalid option for [sensor.noaa_tides]. Check: sensor.noaa_tides->type. (See /config/components/sensors/noaa_tides.yaml, line 5). Please check the docs at https://www.home-assistant.io/integrations/noaa_tides
Invalid config for [sensor.noaa_tides]: [type] is an invalid option for [sensor.noaa_tides]. Check: sensor.noaa_tides->type. (See /config/components/sensors/noaa_tides.yaml, line 11). Please check the docs at https://www.home-assistant.io/integrations/noaa_tides

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.