https://github.com/vannut/statamic-weather-addon
🎏 A Statamic-Addon for the OpenWeathermap API
https://github.com/vannut/statamic-weather-addon
openweathermap openweathermap-api statamic statamic-addon statamic-v3
Last synced: 21 days ago
JSON representation
🎏 A Statamic-Addon for the OpenWeathermap API
- Host: GitHub
- URL: https://github.com/vannut/statamic-weather-addon
- Owner: vannut
- Created: 2021-02-23T08:36:00.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2025-03-30T21:57:07.000Z (11 months ago)
- Last Synced: 2025-03-30T22:28:36.825Z (11 months ago)
- Topics: openweathermap, openweathermap-api, statamic, statamic-addon, statamic-v3
- Language: PHP
- Homepage:
- Size: 42 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Weather Forecast
Display the current weather or a 7-day forecast for any lat/lon on earth.
> Attention: This version (2) is a complete rewrite of the addon. Although it does the same: display a weather forecast; the used weatherprovider is different and some of the fields are renamed. So please pay attention when upgrading.
## Visual Crossing
The weather data itself is coming from the Visual Crossing api. [It's free for the first 1,000 records a day.](https://www.visualcrossing.com/weather-data-editions)
## Installation
1. Install add on through composer: `composer require vannut/statamic-weather-addon "^2.0"`
2. [Create an account](https://www.visualcrossing.com/sign-up) at Visual Crossing.
3. After signing in go to your account, you'll find a `Key`
4. Go to your Statamic Control Panel and look for the Weather entry in the sidebar.
5. Fill out the settings-form with your api-key and create a location to fetch the forecast for.
6. Hit the fetch forecast button.
6. Or Go to the Command line and perform the first initial fetch of your specific data: `php artisan weather:fetchForecast`
## Renewing the forecast
Nothing is as changeable as the weather. Therefore this addon adds [a hourly call](https://github.com/vannut/statamic-weather-addon/blob/master/src/ServiceProvider.php#L25) to the scheduler of Statamic/Laravel.
All you have to do is make sure the scheduler is run, by means of a cron-job. Take a look at [Laravels documentation](https://laravel.com/docs/10.x/scheduling#running-the-scheduler) on this!
## Usage
This addon does not provide any styling, it _just_ caches the json response and passes the raw data through to the two tags.
You can find every field in the api-response on [the api-docs of Visual Crossing](https://www.visualcrossing.com/resources/documentation/weather-api/timeline-weather-api/).
Next to the data provided by the API, the addon adds a couple of nice additional fields:
```
{{ icon_fa }} A fontawesome icon derived fron weather.0.icon
{{ wind_compass }} Converted wind direction to N/S/SSW etc
{{ wind_bft }} Wind speed in Beaufort
{{ uvi_color }} Color representation of the UV Index
{{ uvi_percentage }} Percentage where UVI 10 = 100%;
{{ fetched_at }} Unix Epoch timestamp of the datetime when fetched from API
```
You'll have two tags to your disposal: `{{ forecast }}` and `{{ current_weather }}`
## Simple 7 day forecast
With the `{{ forecast }}` tag you will be able to display a card per day with the forecast.
It's a loop of different days in the forecast. Typically 7 or 15 days depending on the location.
Make sure you specify from which location you want the forecast:
```html
{{ forecast :locale="site" location-identifier="xyz123" }}
{{ datetimeEpoch | iso_format("dddd") }}
{{ datetimeEpoch | iso_format("D MMM Y") }}
{{ tempmax | round }}°C
/
{{ tempmin | round }}°C
{{ wind_compass }} {{ wind_bft }}Bft
{{/forecast }}
```
## Current weather
Want to display the current weather of your location? Use the `{{ current_weather }}` tag. As this is a json-collection you can get its data as following:
```html
{{ current_weather :locale="site" location-identifier="xyz123" }}
Current temperature: {{ temp }}°C
Feels like: {{ feels_like }}°C
{{ /current_weather }}
```
---