jugla / worldtidesinfocustom

world tides info custom component for home assistant
MIT License
27 stars 2 forks source link

Generate a forecast/detailedForecast as attributes on the sensor.tides (or a new sensor.tides_forecast) #27

Open brodykenrick opened 6 months ago

brodykenrick commented 6 months ago

The word tides info custom component could make provide predicted/forecast tide heights at 30/60 min intervals (made available as an attribute forecast).

The matplotlib images are handy and functional but it might be more powerful to provide a forecast (as an attribute) like weather does (and other components, like PV/Solar forecasts also use).

Forecasts would allow users to both more readily create their own plots (using for example ApexCharts) and also to extract the predicted tide height at a time rather than just to be able to receive the next high and low. That would allow them to make determinations of when tide is above a certain level or below a certain level and for how long. Having forecasts would also allow users to cross-filter with weather data to easily determine the right tide and "good" weather as another forecast for other automations (like good times to go for a kayak - because the tide is right and the weather is warm and sunny).

Describe the solution you'd like

Extend the sensor.tides (or create a new sensor.tides_forecast) to include the attributes for a forecast on 30/60 mins

attribution: Data provided by WorldTides
Unit displayed: metric
vertical_reference: LAT
tidal_station_used: Port Hacking
high_tide_time_utc: 2024-03-14T13:42+0000
high_tide_time_local: 00:42
high_tide_height: 1.628
low_tide_time_utc: 2024-03-14T20:15+0000
low_tide_time_local: 07:15
low_tide_height: 0.303
time_to_next_tide: (hours) 2:41:22
tide_tendancy: Tides Up
next_tide_amplitude: 1.325
next_Coeff_resp_MWS: 102
current_height_utc: 2024-03-14T11:00+0000
current_height: 1.128
tide_amplitude: 1.292
Coeff_resp_MWS: 99.5
CreditCallUsed: 0
Data_request_time: 00:07:12 14/03/24
plot: /config/www/tides.png
station_distance: 50
station_around_nb: 5
station_around_name: ; Port Hacking; Botany Bay; Sydney (Fort Denison); Camp Cove; Ku-ring-gai Y.c.
station_around_time_zone: Australia/Sydney
current_distance_to_station: 10.44
live_location: static
source_id: null
distance_from_ref: 0
icon: mdi:chevron-triple-up
friendly_name: tides
forecast:
  - tendancy: Tides Up
    datetime: '2024-03-14T12:00:00+00:00'
    height: 1.25
  - tendancy: Tides Up
    datetime: '2024-03-14T12:30:00+00:00'
    height: 1.30
  ......
  -   - tendancy: Tides Down
    datetime: '2024-03-14T22:30:00+00:00'
    height: 0.50

The new forecast attributes added as above with at least the datetime and the predicted height for each 30 min period (or hourly). Other details could also be added like tide tendency. The forecast values could be going back 6 hours and forward 42 hours like the current implementation/defaults. it might also be nice to predict a full week ahead (using days setting in the world tides info API).

I think UTC time would be best. I think the current implementation already gets data at 30 mins intervals. However, 60 mins might more naturally match with a weather forecast and other plottable forecasts.

Describe alternatives you've considered I was going to create a sensor using the high/low tide numbers and the rule of twelfths to overcome the recent matplotlib issues but the details are already avaialble in the upstream API so it would be a nice extension of this great component to support forecasts.

jugla commented 5 months ago

Hello, Great Idea, I would add a forecast sensor.

Meanwhile, you have calendar that brings the information

brodykenrick commented 5 months ago

Great. Thanks. Let me know when you need any testing or any other input.

I can also create and share some apex charts for the plots when the feature is available.

jugla commented 4 months ago

Hello, I have added forecast sensor. For the beginning, just the height + time. Please give me feed back (v13.1.0)

brodykenrick commented 4 months ago

Awesome - Thanks @jugla !

That feature is working for my location.

state_class: measurement
attribution: Data provided by WorldTides
Unit displayed: metric
current_height_utc: 2024-05-07T12:30+0000
current_height: 1.181
forecast_duration_in_hour: 1
unit_of_measurement: m
icon: mdi:chevron-triple-down
friendly_name: tides_forecast_tide_height

Getting the tide in an hour will be very useful for my use case. If I got one hour and two then I'd be set for the case I am thinking.

A note that I think we don't want current_height used for those values but rather forecast_height (as that value is not "current").

I think a more general solution, and the kind that could be used for other forecast uses and for replicating the matlib charts, would be to use an array under forecast like this:

state_class: measurement
attribution: Data provided by WorldTides
Unit displayed: metric
unit_of_measurement: m
icon: mdi:chevron-triple-down
friendly_name: tides_forecast_tide_height
forecast:
  - datetime_utc: 2024-05-07T12:30+0000
     height: 1.181
  - datetime_utc: 2024-05-07T13:00+0000
     height: 1.107

perhaps each 30 mins for the next 6 or 12 hours?

jugla commented 4 months ago

Hello Thanks ! Agree, it is not the current height in the forecast. I have to reorganize a little the source code. I will add the forecast data in several attributes, so that it will match the description you propose. :-)