### API Request Example Source: https://github.com/pirate-weather/pirateweather/blob/main/docs/API.md Example of a GET request to the Pirate Weather API for forecast data. Includes parameters for API key, latitude, longitude, and units. ```http GET https://api.pirateweather.net/forecast/1234567890abcdefghijklmnopqrstuvwxyz/45.42,-74.30?&units=ca ``` -------------------------------- ### API Response Example - Currently Source: https://github.com/pirate-weather/pirateweather/blob/main/docs/API.md Example of the 'currently' section in the API response, showing current weather conditions. ```json "latitude": 45.42, "longitude": -74.3, "timezone": "America/Toronto", "offset": -5, "elevation": 77, "currently": { "time": 1762718100, "summary": "Light Snow", "icon": "snow", "nearestStormDistance": 17.88, "nearestStormBearing": 270, "precipIntensity": 0.5321, "precipProbability": 0.61, "precipIntensityError": 0.159, "precipType": "snow", "temperature": -0.88, "apparentTemperature": -6.77, "dewPoint": -3.5, "humidity": 0.82, "pressure": 1015.24, "windSpeed": 17.73, "windGust": 46.84, "windBearing": 41, "cloudCover": 0.81, "uvIndex": 0.38, "visibility": 16.09, "ozone": 311.75 } ``` -------------------------------- ### Home Assistant Integration (YAML) Source: https://context7.com/pirate-weather/pirateweather/llms.txt Configuration examples for integrating Pirate Weather with Home Assistant using YAML. ```APIDOC ## Home Assistant Integration (YAML) ### Weather Entity Configuration ```yaml weather: - platform: pirateweather api_key: YOUR_API_KEY latitude: 45.42 longitude: -75.69 mode: "hourly" # or "daily" name: "Pirate Weather" ``` ### Sensor Entity Configuration ```yaml sensor: - platform: pirateweather api_key: YOUR_API_KEY scan_interval: "00:15:00" monitored_conditions: - temperature - precip_probability - precip_type - humidity - cloud_cover - nearest_storm_distance - precip_intensity - wind_speed ``` ### Accessing Forecast Data via Template (HA 2023.9+) ```yaml - trigger: - platform: time_pattern minutes: "/30" action: - service: weather.get_forecasts data: type: daily target: entity_id: weather.pirateweather response_variable: daily sensor: - name: Pirate Weather Daily unique_id: pirateweather_daily state: "{{ daily['weather.pirateweather'].forecast[0].condition }}" attributes: forecast: "{{ daily['weather.pirateweather'].forecast }}" ``` ``` -------------------------------- ### API Response Example - Daily Data Source: https://github.com/pirate-weather/pirateweather/blob/main/docs/API.md Example of the 'daily' data array in the API response, providing daily weather summaries including sunrise, sunset, and precipitation details. ```json "daily": { "summary": "Mixed precipitation today through Wednesday and next Sunday, with high temperatures peaking at 3°C on Thursday.", "icon": "sleet", "data": [ { "time": 1762664400, "summary": "Sleet (with a chance of 6–8 cm. of snow) starting in the afternoon.", "icon": "sleet", "sunriseTime": 1762688903, "sunsetTime": 1762723986, "moonPhase": 0.65, "precipIntensity": 0.7514, "precipIntensityMax": 3.81, "precipIntensityMaxTime": 1762732800, "precipProbability": 1, "precipAccumulation": 7.5957, "precipType": "sleet", "rainIntensityMax": 1.27, "temperatureHigh": 0.04, "temperatureHighTime": 1762704000, "temperatureLow": -1.29, "temperatureLowTime": 1762732800, "apparentTemperatureHigh": -5.22, "apparentTemperatureHighTime": 1762704000, "apparentTemperatureLow": -7.92, "apparentTemperatureLowTime": 1762732800, "dewPoint": -3.96, "humidity": 0.81, "pressure": 1015.02, "windSpeed": 15.36, "windGust": 26.74, "windGustTime": 1762725600, "windBearing": 62, "cloudCover": 0.89, "uvIndex": 1.8, "uvIndexTime": 1762704000, "visibility": 9.29, "temperatureMin": -2.81, "temperatureMinTime": 1762664400, "temperatureMax": 0.04, "temperatureMaxTime": 1762704000, "apparentTemperatureMin": -7.92, "apparentTemperatureMinTime": 1762732800, "apparentTemperatureMax": -5.22, "apparentTemperatureMaxTime": 1762704000 }, ... ] } ``` -------------------------------- ### API Response Example - Hourly Data Source: https://github.com/pirate-weather/pirateweather/blob/main/docs/API.md Example of the 'hourly' data array in the API response, detailing hourly weather conditions and forecasts. ```json "hourly": { "summary": "Sleet (with a chance of 6–8 cm. of snow) until tomorrow morning and foggy tomorrow afternoon.", "icon": "sleet", "data": [ { "time": 1762714800, "summary": "Light Snow", "icon": "snow", "precipIntensity": 0.508, "precipProbability": 0.47, "precipIntensityError": 0.15, "precipAccumulation": 0.2985, "precipType": "snow", "temperature": -0.49, "apparentTemperature": -7.05, "dewPoint": -3.38, "humidity": 0.81, "pressure": 1015.9, "windSpeed": 21.6, "windGust": 35.28, "windBearing": 50, "cloudCover": 0.93, "uvIndex": 0.52, "visibility": 4.05, "ozone": 313.39 }, ... ] } ``` -------------------------------- ### Using a Rest Sensor for Dynamic Location with Pirate Weather Source: https://github.com/pirate-weather/pirateweather/blob/main/docs/ha.md This example demonstrates how to create a weather template using a rest sensor to achieve dynamic location with the Pirate Weather integration. ```yaml ``` -------------------------------- ### API Response Example - Alerts Source: https://github.com/pirate-weather/pirateweather/blob/main/docs/API.md Example of the 'alerts' array in the API response, containing weather alerts with titles, regions, severity, and timestamps. ```json "alerts": [ { "title": "avertissement de neige en vigueur", "regions": [ "secteur de Soulanges" ], "severity": "Moderate", "time": 1762704172, "expires": 1762761772, ``` -------------------------------- ### API Response Example - Minutely Data Source: https://github.com/pirate-weather/pirateweather/blob/main/docs/API.md Example of the 'minutely' data array in the API response, providing minute-by-minute precipitation forecasts. ```json "minutely": { "summary": "Flurries for the hour.", "icon": "snow", "data": [ { "time": 1762718100, "precipIntensity": 0.5321, "precipProbability": 0.61, "precipIntensityError": 0.159, "precipType": "snow" }, ... ] } ``` -------------------------------- ### API Response Example - Day/Night Data Source: https://github.com/pirate-weather/pirateweather/blob/main/docs/API.md Example of the 'day_night' data array in the API response, providing specific weather details for day and night periods. ```json "day_night": { "data": [ { "time": 1762678800, "summary": "Snow (1–3 cm.) in the afternoon.", "icon": "snow", "precipIntensity": 0.2345, "precipIntensityMax": 1.778, "precipProbability": 0.81, "precipAccumulation": 1.8828, "precipType": "snow", "temperature": 0.04, "apparentTemperature": -5.22, "dewPoint": -4.69, "humidity": 0.76, "pressure": 1016.93, "windSpeed": 16.62, "windGust": 28.36, "windBearing": 56, "cloudCover": 0.87, "uvIndex": 0.53, "visibility": 10.96, "ozone": 314.77, "smoke": 0, }, ... ] } ``` -------------------------------- ### Full Parameter Forecast Request Source: https://context7.com/pirate-weather/pirateweather/llms.txt Combine all optional query parameters for a detailed forecast. This example requests extended hourly data, version-2 fields, French summaries, and excludes the alerts block. ```bash curl "https://api.pirateweather.net/forecast/YOUR_API_KEY/48.8566,2.3522?\ units=si\ &extend=hourly\ &version=2\ &lang=fr\ &icon=pirate\ &exclude=alerts,minutely\ &extraVars=stationPressure\ &include=day_night_forecast" ``` -------------------------------- ### Time Machine API Response Example Source: https://github.com/pirate-weather/pirateweather/blob/main/docs/API.md This example shows the JSON response structure for a Time Machine request, including details for currently, hourly, daily weather data, and flags indicating data sources and units used. ```http GET https://timemachine.pirateweather.net/forecast/1234567890abcdefghijklmnopqrstuvwxyz/45.42,-74.30,1654056000?&units=ca { "latitude": 45.42, "longitude": -74.3, "timezone": "America/Toronto", "offset": -4.0, "currently": { "time": 1654056000, "summary": "Overcast", "icon": "cloudy", "precipIntensity": 0, "precipType": "none", "temperature": 15.2, "apparentTemperature": 11.61, "dewPoint": 7.57, "pressure": 1016.18, "windSpeed": 15.23, "windGust": 24.4, "windBearing": 72, "cloudCover": 1 }, "hourly": { "data": [ { "time": 1654056000, "summary": "Overcast", "icon": "cloudy", "precipIntensity": 0, "precipAccumulation": 0, "precipType": "none", "temperature": 15.2, "apparentTemperature": 11.61, "dewPoint": 7.57, "pressure": 1016.18, "windSpeed": 15.23, "windGust": 24.4, "windBearing": 72, "cloudCover": 1 }, ... ] }, "daily": { "data": [ { "time": 1654056000, "summary": "Rain throughout the day.", "icon": "rain", "sunriseTime": 1654074749, "sunsetTime": 1654130288, "moonPhase": 0.06, "precipIntensity": 0.3127, "precipIntensityMax": 2.9816, "precipIntensityMaxTime": 1654088400, "precipAccumulation": 0.7526, "precipType": "rain", "rainIntensityMax": 2.9816, "temperatureHigh": 16.37, "temperatureHighTime": 1654102800, "temperatureLow": 12.39, "temperatureLowTime": 1654092000, "apparentTemperatureHigh": 16.27, "apparentTemperatureHighTime": 1654102800, "apparentTemperatureLow": 8.47, "apparentTemperatureLowTime": 1654077600, "dewPoint": 9.87, "pressure": 1012.11, "windSpeed": 15.03, "windGust": 30.69, "windGustTime": 1654102800, "windBearing": 72, "cloudCover": 0.98, "temperatureMin": 12.39, "temperatureMinTime": 1654092000, "temperatureMax": 16.37, "temperatureMaxTime": 1654102800, "apparentTemperatureMin": 8.47, "apparentTemperatureMinTime": 1654077600, "apparentTemperatureMax": 16.27, "apparentTemperatureMaxTime": 1654102800 } ] }, "flags": { "sources": [ "ETOPO1", "era5" ], "sourceTimes": {}, "nearest-station": 0, "units": "ca", "version": "V2.9.3" } } ``` -------------------------------- ### Fetch Minutely Precipitation Data Source: https://context7.com/pirate-weather/pirateweather/llms.txt Use this to get 60 per-minute precipitation data points. This block is only available for live forecast requests and requires HRRR model coverage. ```bash curl "https://api.pirateweather.net/forecast/YOUR_API_KEY/45.42,-74.30?units=ca&exclude=currently,hourly,daily,alerts" # Response: # { # "minutely": { # "summary": "Flurries for the hour.", # "icon": "snow", # "data": [ # { # "time": 1762718100, # "precipIntensity": 0.5321, # "precipProbability": 0.61, # "precipIntensityError": 0.159, # "precipType": "snow" # }, # { "time": 1762718160, "precipIntensity": 0.48, ... }, # ... // 60 entries total, one per minute # ] # } # } ``` -------------------------------- ### Home Assistant Sensor Entities Configuration Source: https://context7.com/pirate-weather/pirateweather/llms.txt YAML configuration for creating Pirate Weather sensor entities in Home Assistant. This example shows how to monitor various weather conditions like temperature, precipitation, and wind speed. ```yaml # sensor entity with monitored conditions sensor: - platform: pirateweather api_key: YOUR_API_KEY scan_interval: "00:15:00" monitored_conditions: - temperature - precip_probability - precip_type - humidity - cloud_cover - nearest_storm_distance - precip_intensity - wind_speed ``` -------------------------------- ### Currently Block - Present Conditions Source: https://context7.com/pirate-weather/pirateweather/llms.txt Fetch current weather conditions for a specific location. This example excludes other data blocks to focus on the `currently` data. ```bash curl "https://api.pirateweather.net/forecast/YOUR_API_KEY/45.42,-74.30?units=ca&exclude=minutely,hourly,daily,alerts" ``` -------------------------------- ### Custom Kong Dockerfile Source: https://github.com/pirate-weather/pirateweather/blob/main/docs/Blog/KongGatewayInfrastructure.md Builds a custom Kong OSS image by installing a modified 'Request Transformer' plugin. This ensures the plugin runs before authentication to extract API keys from URL parameters. ```docker FROM kong:3.2-ubuntu USER root COPY kong-plugin-request-transformer_1251-0.4-1.all.rock /tmp/kong-plugin-request-transformer_1251-0.4-1.all.rock WORKDIR /tmp RUN luarocks install kong-plugin-request-transformer_1251-0.4-1.all.rock USER kong ``` -------------------------------- ### Fetch Alternating Day/Night 7-Day Forecast Source: https://context7.com/pirate-weather/pirateweather/llms.txt Enable the `day_night` block with `include=day_night_forecast` to get 16 entries alternating between daytime (04:00–16:59) and night-time (17:00–03:59) segments. ```bash curl "https://api.pirateweather.net/forecast/YOUR_API_KEY/45.42,-74.30?units=ca&include=day_night_forecast&exclude=minutely,alerts" # Response day_night.data entries alternate: [day0, night0, day1, night1, ...] # { # "time": 1762678800, # "summary": "Snow (1–3 cm.) in the afternoon.", # "icon": "snow", # "precipIntensity": 0.2345, # "precipIntensityMax": 1.778, # "precipProbability": 0.81, # "precipAccumulation": 1.8828, # "precipType": "snow", # "temperature": 0.04, # "windSpeed": 16.62, # "cloudCover": 0.87, # "smoke": 0 # version>1 only; -999 outside US/Canada # } ``` -------------------------------- ### Handle API Error Codes with cURL Source: https://context7.com/pirate-weather/pirateweather/llms.txt Examples of cURL commands to trigger and observe common API error responses, such as invalid location, unauthorized access, not found, and rate limiting. ```bash # 400 Bad Request — invalid lat/lon or future time curl "https://api.pirateweather.net/forecast/YOUR_API_KEY/999,999" # {"error": "The given location is invalid"} # 401 Unauthorized — missing or invalid API key, or not subscribed curl "https://api.pirateweather.net/forecast/INVALID_KEY/45.42,-75.69" # 404 Not Found — malformed route, missing lat/lon curl "https://api.pirateweather.net/forecast/YOUR_API_KEY/" # 429 Too Many Requests — monthly quota exhausted # Ratelimit-Remaining header will be 0 # 500 Internal Server Error — retry the request; report persistent issues on GitHub ``` -------------------------------- ### Initialize Swagger UI for API Documentation Source: https://github.com/pirate-weather/pirateweather/blob/main/docs/Specification.md This JavaScript code initializes the Swagger UI interface, which provides interactive documentation for the OpenAPI specification. It loads the specification from a remote URL and enables the 'Try it out' feature. ```javascript window.onload = function() { const ui = SwaggerUIBundle({ url: "https://raw.githubusercontent.com/Pirate-Weather/pirateweather/main/PW_OpenAPI.yaml", dom_id: "#swagger-ui", presets: [SwaggerUIBundle.presets.apis], layout: "BaseLayout", tryItOutEnabled: true }); window.ui = ui; }; ``` -------------------------------- ### Fetch Hourly Forecast Data (48h or 168h) Source: https://context7.com/pirate-weather/pirateweather/llms.txt Retrieve hourly forecast data for the next 48 hours by default. Add `extend=hourly` to expand the forecast to 168 hours (7 days). ```bash # Standard 48-hour hourly forecast curl "https://api.pirateweather.net/forecast/YOUR_API_KEY/45.42,-74.30?units=ca&exclude=currently,minutely,daily,alerts" # Extended 168-hour hourly forecast curl "https://api.pirateweather.net/forecast/YOUR_API_KEY/45.42,-74.30?units=ca&extend=hourly&exclude=currently,minutely,daily,alerts" # Each hourly data point includes: # { # "time": 1762714800, # "summary": "Light Snow", # "icon": "snow", # "precipIntensity": 0.508, # mm/h # "precipProbability": 0.47, # "precipIntensityError": 0.15, # "precipAccumulation": 0.2985, # cm total for this hour # "precipType": "snow", # "temperature": -0.49, # "apparentTemperature": -7.05, # "dewPoint": -3.38, # "humidity": 0.81, # "pressure": 1015.9, # "windSpeed": 21.6, # "windGust": 35.28, # "windBearing": 50, # "cloudCover": 0.93, # "uvIndex": 0.52, # "visibility": 4.05, # "ozone": 313.39 # } ``` -------------------------------- ### Error Codes Source: https://context7.com/pirate-weather/pirateweather/llms.txt Details on various error codes returned by the API, with examples. ```APIDOC ## Error Codes - **400 Bad Request**: Invalid latitude/longitude or future time. ```bash curl "https://api.pirateweather.net/forecast/YOUR_API_KEY/999,999" # Expected response: {"error": "The given location is invalid"} ``` - **401 Unauthorized**: Missing or invalid API key, or not subscribed. ```bash curl "https://api.pirateweather.net/forecast/INVALID_KEY/45.42,-75.69" ``` - **404 Not Found**: Malformed route or missing latitude/longitude. ```bash curl "https://api.pirateweather.net/forecast/YOUR_API_KEY/" ``` - **429 Too Many Requests**: Monthly quota exhausted. The `Ratelimit-Remaining` header will be 0. - **500 Internal Server Error**: Indicates a server-side issue. Retry the request and report persistent issues. ``` -------------------------------- ### API Key via Header Source: https://context7.com/pirate-weather/pirateweather/llms.txt Demonstrates how to pass the API key using the `apikey` header instead of in the URL path. ```APIDOC ## GET /forecast/{apiKey}/{latitude},{longitude} ### Description Authenticates the request by providing the API key in the `apikey` header. ### Method GET ### Endpoint https://api.pirateweather.net/forecast/placeholder/45.42,-75.69 ### Headers - **apikey**: YOUR_API_KEY ### Request Example ```bash curl -H "apikey: YOUR_API_KEY" \ "https://api.pirateweather.net/forecast/placeholder/45.42,-75.69?units=ca" ``` ``` -------------------------------- ### Get Forecast Data Source: https://github.com/pirate-weather/pirateweather/blob/main/docs/API.md Retrieve current and forecasted weather data for a specific location. The API key, latitude, and longitude are required parameters. ```APIDOC ## GET /forecast/{apiKey}/{latitude},{longitude} ### Description Retrieves detailed weather forecast data including currently, minutely, hourly, daily, and alerts for a specified geographic location. ### Method GET ### Endpoint https://api.pirateweather.net/forecast/{apiKey}/{latitude},{longitude} ### Parameters #### Path Parameters - **apiKey** (string) - Required - Your unique API key. - **latitude** (number) - Required - The latitude of the location. - **longitude** (number) - Required - The longitude of the location. #### Query Parameters - **units** (string) - Optional - Units for the forecast data (e.g., 'ca', 'us', 'uk2', 'si'). Defaults to 'us'. ### Request Example ``` GET https://api.pirateweather.net/forecast/1234567890abcdefghijklmnopqrstuvwxyz/45.42,-74.30?&units=ca ``` ### Response #### Success Response (200) - **latitude** (number) - The latitude of the location. - **longitude** (number) - The longitude of the location. - **timezone** (string) - The timezone of the location. - **offset** (number) - The timezone offset from UTC. - **elevation** (number) - The elevation of the location in meters. - **currently** (object) - Current weather conditions. - **minutely** (object) - Minute-by-minute forecast for the next hour. - **hourly** (object) - Hourly forecast for the next two days. - **daily** (object) - Daily forecast for the next seven days. - **alerts** (array) - Any weather alerts for the location. #### Response Example ```json { "latitude": 45.42, "longitude": -74.3, "timezone": "America/Toronto", "offset": -5, "elevation": 77, "currently": { "time": 1762718100, "summary": "Light Snow", "icon": "snow", "nearestStormDistance": 17.88, "nearestStormBearing": 270, "precipIntensity": 0.5321, "precipProbability": 0.61, "precipIntensityError": 0.159, "precipType": "snow", "temperature": -0.88, "apparentTemperature": -6.77, "dewPoint": -3.5, "humidity": 0.82, "pressure": 1015.24, "windSpeed": 17.73, "windGust": 46.84, "windBearing": 41, "cloudCover": 0.81, "uvIndex": 0.38, "visibility": 16.09, "ozone": 311.75 }, "minutely": { "summary": "Flurries for the hour.", "icon": "snow", "data": [ { "time": 1762718100, "precipIntensity": 0.5321, "precipProbability": 0.61, "precipIntensityError": 0.159, "precipType": "snow" }, ... ] }, "hourly": { "summary": "Sleet (with a chance of 6–8 cm. of snow) until tomorrow morning and foggy tomorrow afternoon.", "icon": "sleet", "data": [ { "time": 1762714800, "summary": "Light Snow", "icon": "snow", "precipIntensity": 0.508, "precipProbability": 0.47, "precipIntensityError": 0.15, "precipAccumulation": 0.2985, "precipType": "snow", "temperature": -0.49, "apparentTemperature": -7.05, "dewPoint": -3.38, "humidity": 0.81, "pressure": 1015.9, "windSpeed": 21.6, "windGust": 35.28, "windBearing": 50, "cloudCover": 0.93, "uvIndex": 0.52, "visibility": 4.05, "ozone": 313.39 }, ... ] }, "day_night": { "data": [ { "time": 1762678800, "summary": "Snow (1–3 cm.) in the afternoon.", "icon": "snow", "precipIntensity": 0.2345, "precipIntensityMax": 1.778, "precipProbability": 0.81, "precipAccumulation": 1.8828, "precipType": "snow", "temperature": 0.04, "apparentTemperature": -5.22, "dewPoint": -4.69, "humidity": 0.76, "pressure": 1016.93, "windSpeed": 16.62, "windGust": 28.36, "windBearing": 56, "cloudCover": 0.87, "uvIndex": 0.53, "visibility": 10.96, "ozone": 314.77, "smoke": 0, }, ... ] }, "daily": { "summary": "Mixed precipitation today through Wednesday and next Sunday, with high temperatures peaking at 3°C on Thursday.", "icon": "sleet", "data": [ { "time": 1762664400, "summary": "Sleet (with a chance of 6–8 cm. of snow) starting in the afternoon.", "icon": "sleet", "sunriseTime": 1762688903, "sunsetTime": 1762723986, "moonPhase": 0.65, "precipIntensity": 0.7514, "precipIntensityMax": 3.81, "precipIntensityMaxTime": 1762732800, "precipProbability": 1, "precipAccumulation": 7.5957, "precipType": "sleet", "rainIntensityMax": 1.27, "temperatureHigh": 0.04, "temperatureHighTime": 1762704000, "temperatureLow": -1.29, "temperatureLowTime": 1762732800, "apparentTemperatureHigh": -5.22, "apparentTemperatureHighTime": 1762704000, "apparentTemperatureLow": -7.92, "apparentTemperatureLowTime": 1762732800, "dewPoint": -3.96, "humidity": 0.81, "pressure": 1015.02, "windSpeed": 15.36, "windGust": 26.74, "windGustTime": 1762725600, "windBearing": 62, "cloudCover": 0.89, "uvIndex": 1.8, "uvIndexTime": 1762704000, "visibility": 9.29, "temperatureMin": -2.81, "temperatureMinTime": 1762664400, "temperatureMax": 0.04, "temperatureMaxTime": 1762704000, "apparentTemperatureMin": -7.92, "apparentTemperatureMinTime": 1762732800, "apparentTemperatureMax": -5.22, "apparentTemperatureMaxTime": 1762704000 }, ... ] } "alerts": [ { "title": "avertissement de neige en vigueur", "regions": [ "secteur de Soulanges" ], "severity": "Moderate", "time": 1762704172, "expires": 1762761772 } ] } ``` ``` -------------------------------- ### Configure Pirate Weather Integration in YAML Source: https://github.com/pirate-weather/pirateweather/blob/main/docs/ha.md Use this block in your configuration.yaml to set up the Pirate Weather integration. Ensure you replace '' with your actual API key. Optional parameters like latitude, longitude, mode, and name can be customized. ```yaml weather: - platform: pirateweather api_key: # Additional optional values: latitude: Location latitude longitude: Location longitude mode: "hourly" (default) or "daily" name: Custom name ``` ```yaml sensor: - platform: pirateweather api_key: scan_interval: '00:15:00' monitored_conditions: - temperature - precip_probability - precip_type - humidity - cloud_cover - nearest_storm_distance - precip_intensity - wind_speed ``` -------------------------------- ### Fetch Forecast Data with Flags Block Source: https://context7.com/pirate-weather/pirateweather/llms.txt Demonstrates fetching forecast data and shows the structure of the 'flags' block in the response, which details contributing data sources and API version. ```bash curl "https://api.pirateweather.net/forecast/YOUR_API_KEY/45.42,-74.30?units=ca&version=2&exclude=currently,minutely,hourly,daily,alerts" # Response: # { # "flags": { # "sources": ["ETOPO1","hrrrsubh","rtma_ru","hrrr_0-18", # "nbm","nbm_fire", # "ecmwf_ifs","hrrr_18-48","gfs","gefs"], # "sourceTimes": { # "hrrr_subh": "2025-11-09 17Z", # "rtma_ru": "2025-11-09 19:30Z", # "hrrr_0-18": "2025-11-09 17Z", # "nbm": "2025-11-09 17Z", # "nbm_fire": "2025-11-09 12Z", # "ecmwf_ifs": "2025-11-09 00Z", # "hrrr_18-48": "2025-11-09 12Z", # "gfs": "2025-11-09 12Z", # "gefs": "2025-11-09 12Z" # }, # "nearest-station": -999, # km to nearest DWD MOSMIX station; -999 = none # "units": "ca", # "version": "V2.9.3", # "processTime": 42, # ms (version>1 only) # "ingestVersion": "...", # version>1 only # "nearestCity": "Ottawa", # version>1 only # "nearestCountry": "Canada", # "nearestSubNational": "Ontario" # } # } ``` -------------------------------- ### temperatureMin Source: https://github.com/pirate-weather/pirateweather/blob/main/docs/API.md Only on `daily`. The minimum temperature calculated between 12:00 am and 11:59 pm local time. ```APIDOC ## temperatureMin ### Description **Only on `daily`**. The minimum temperature calculated between 12:00 am and 11:59 pm local time. ``` -------------------------------- ### uvIndex Source: https://github.com/pirate-weather/pirateweather/blob/main/docs/API.md The measure of UV radiation as represented as an index starting from 0. `0` to `2` is Low, `3` to `5` is Moderate, `6` and `7` is High, `8` to `10` is Very High and `11+` is considered extreme. ```APIDOC ## uvIndex ### Description The measure of UV radiation as represented as an index starting from 0. `0` to `2` is Low, `3` to `5` is Moderate, `6` and `7` is High, `8` to `10` is Very High and `11+` is considered extreme. [See this resource for more information.](https://www.who.int/news-room/questions-and-answers/item/radiation-the-ultraviolet-(uv)-index#:~:text=What%20is%20the%20UV%20index,takes%20for%20harm%20to%20occur.) ``` -------------------------------- ### Dynamic Weather Template Configuration Source: https://github.com/pirate-weather/pirateweather/blob/main/docs/ha.md Defines a template sensor for dynamic weather conditions, mapping Pirate Weather icons to Home Assistant conditions and processing forecast data. ```yaml weather: - platform: template name: "Dynamic Weather Template" unique_id: "pw_template" attribution_template: "Powered by Pirate Weather" temperature_template: "{{ state_attr('sensor.PW_Template_Currently', 'temperature') }}" temperature_unit: "°F" humidity_template: "{{ state_attr('sensor.PW_Template_Currently', 'humidity')*100 | int }}" pressure_template: "{{ state_attr('sensor.PW_Template_Currently', 'pressure') }}" pressure_unit: "hPa" wind_speed_template: "{{ state_attr('sensor.PW_Template_Currently', 'windSpeed') | int}}" wind_speed_unit: "mph" ozone_template: "{{ state_attr('sensor.PW_Template_Currently', 'ozone') }}" visibility_template: "{{ state_attr('sensor.PW_Template_Currently', 'visibility') }}" visibility_unit: "mi" precipitation_unit: "in" condition_template: >- {% if state_attr('sensor.PW_Template_Currently', 'icon') == "clear-night" %} clear-night {% elif state_attr('sensor.PW_Template_Currently', 'icon') == "clear-day" %} sunny {% elif state_attr('sensor.PW_Template_Currently', 'icon') == "cloudy" %} cloudy {% elif state_attr('sensor.PW_Template_Currently', 'icon') == "fog" %} fog {% elif state_attr('sensor.PW_Template_Currently', 'icon') == "partly-cloudy-day" %} partlycloudy {% elif state_attr('sensor.PW_Template_Currently', 'icon') == "partly-cloudy-night" %} partlycloudy {% elif state_attr('sensor.PW_Template_Currently', 'icon') == "rain" %} rainy {% elif state_attr('sensor.PW_Template_Currently', 'icon') == "snow" %} snowy {% elif state_attr('sensor.PW_Template_Currently', 'icon') == "sleet" %} snowy {% elif state_attr('sensor.PW_Template_Currently', 'icon') == "wind" %} windy {% endif %} forecast_daily_template: >- {%set return=namespace(data=[])%} {%for datapoint in state_attr('sensor.forecast_daily', 'data')%} {% set condition=datapoint.icon%} {% if datapoint.icon == "clear-day" %} {%set condition="sunny"%} {% elif datapoint.icon == "partly-cloudy-day" or datapoint.icon == "partly-cloudy-night"%} {%set condition="partlycloudy"%} {% elif datapoint.icon == "rain" %} {%set condition="rainy"%} {% elif datapoint.icon == "snow" or datapoint.icon=="sleet"%} {%set condition="snowy"%} {% elif datapoint.icon == "wind" %} {%set condition="windy"%} {% endif %} {%set returnPoint=[{'datetime':as_local(as_datetime(datapoint.time)).strftime("%Y-%m-%dT%H:%M:%S") ,'temperature':datapoint.temperatureHigh, 'templow':datapoint.temperatureLow, 'condition':condition,'precipitation':datapoint.precipAccumulation , 'wind_bearing':datapoint.windBearing, 'wind_speed':datapoint.windSpeed}]%} {% set return.data=return.data+returnPoint%} {% endfor%} {{return.data}} forecast_hourly_template: >- {%set return=namespace(data=[])%} {%for datapoint in state_attr('sensor.forecast_hourly', 'data')%} {% set condition=datapoint.icon%} {% if datapoint.icon == "clear-day" %} {%set condition="sunny"%} {% elif datapoint.icon == "partly-cloudy-day" or datapoint.icon == "partly-cloudy-night"%} {%set condition="partlycloudy"%} {% elif datapoint.icon == "rain" %} {%set condition="rainy"%} {% elif datapoint.icon == "snow" or datapoint.icon=="sleet"%} {%set condition="snowy"%} {% elif datapoint.icon == "wind" %} {%set condition="windy"%} {% endif %} {%set returnPoint=[{'datetime':as_local(as_datetime(datapoint.time)).strftime("%Y-%m-%dT%H:%M:%S") ,'temperature':datapoint.temperature,'condition':condition,'precipitation':datapoint.precipAccumulation , 'wind_bearing':datapoint.windBearing, 'wind_speed':datapoint.windSpeed}]%} {% set return.data=return.data+returnPoint%} {% endfor%} {{return.data}} ``` -------------------------------- ### Home Assistant Template for Daily Forecasts Source: https://context7.com/pirate-weather/pirateweather/llms.txt A Home Assistant template configuration to access and display daily forecast data. This requires HA version 2023.9 or later and uses a time pattern trigger to update the sensor. ```yaml # Accessing forecast data via template (required after HA 2023.9) - trigger: - platform: time_pattern minutes: "/30" action: - service: weather.get_forecasts data: type: daily target: entity_id: weather.pirateweather response_variable: daily sensor: - name: Pirate Weather Daily unique_id: pirateweather_daily state: "{{ daily['weather.pirateweather'].forecast[0].condition }}" attributes: forecast: "{{ daily['weather.pirateweather'].forecast }}" ``` -------------------------------- ### Fetch 7-Day Daily Forecast Data Source: https://context7.com/pirate-weather/pirateweather/llms.txt Obtain a 7-day day-by-day forecast. Each entry represents a calendar day, with time fields indicating midnight local time (UNIX timestamp). ```bash curl "https://api.pirateweather.net/forecast/YOUR_API_KEY/45.42,-74.30?units=ca&exclude=currently,minutely,hourly,alerts" # Each daily data point includes (abbreviated): # { # "time": 1762664400, # midnight local time (UNIX) # "summary": "Sleet starting in the afternoon.", # "icon": "sleet", # "sunriseTime": 1762688903, # "sunsetTime": 1762723986, # "moonPhase": 0.65, # 0=new, 0.25=first quarter, 0.5=full, 0.75=last quarter # "precipIntensity": 0.7514, # mm/h average # "precipIntensityMax": 3.81, # mm/h peak # "precipIntensityMaxTime": 1762732800, # "precipProbability": 1.0, # max hourly probability for the day # "precipAccumulation": 7.5957, # cm total # "precipType": "sleet", # "temperatureHigh": 0.04, # daytime high (6am–6pm) # "temperatureHighTime": 1762704000, # "temperatureLow": -1.29, # overnight low (6pm–6am) # "temperatureLowTime": 1762732800, # "temperatureMax": 0.04, # 24h max (midnight–midnight) # "temperatureMin": -2.81, # 24h min # "windGust": 26.74, # "windGustTime": 1762725600, # "uvIndex": 1.8, # "uvIndexTime": 1762704000, # "moonPhase": 0.65 # } ``` -------------------------------- ### API Key via Header Source: https://context7.com/pirate-weather/pirateweather/llms.txt Pass the API key as a request header instead of in the URL path. Use any placeholder in the URL path when using the header method. ```bash curl -H "apikey: YOUR_API_KEY" \ "https://api.pirateweather.net/forecast/placeholder/45.42,-75.69?units=ca" ``` -------------------------------- ### Basic Forecast Request Source: https://context7.com/pirate-weather/pirateweather/llms.txt Retrieve a full forecast for a latitude/longitude using default Imperial units. Units can be switched using the `units` parameter. ```bash curl "https://api.pirateweather.net/forecast/YOUR_API_KEY/45.42,-75.69?units=ca" ```