I think I understand that you can still get free access to the OpenWeatherMap basic weather data for free, as long as you don't go over 1000 calls per day (and you can set the limit in the account settings)?
Is that correct please as I don't want to start running up big bills. ;-(
Videos
Save this in a file ex filename.py I would suggest using VSCode.
Get you API key for free from https://openweathermap.org/api (This is not an advertisement this is a fun project) Replace the value of variable "Key" with the key that you got in double or single quotes.
Then make another file named Functions.py exactly if you really want to change the name, go to the 4th line (Including Spaces) and change the "import Functions as Geocode" to "import {name here} as Geocode"
Here have the code:
____________________________________________________________________________________________________________
filename.py
import requests
import Functions as Geocode
# File check functions
# Variables
Key = 'Your key goes here'
# Geocoding Setup
countryCode = input("Enter the country code of your country (IN for India):")
Zip = input("Enter the zip code of your city:")
City = Geocode.City(Key, countryCode, Zip)
lat = Geocode.Latitude(Key, countryCode, Zip)
lon = Geocode.Longitude(Key, countryCode, Zip)
CurrAirPol = f'http://api.openweathermap.org/data/2.5/air_pollution?lat={lat}&lon={lon}&appid={Key}'
AQI = Geocode.CurrentAirPollution(CurrAirPol)
print(AQI)End of Code here!
____________________________________________________________________________________________________________
Functions.py
import requests
def City(Key, countryCode, Zip):
Geocoding = f'http://api.openweathermap.org/geo/1.0/zip?zip={Zip},{countryCode}&appid={Key}'
response = requests.get(Geocoding).json()
print(f"Are you trying to access the data of {response['name']}")
return response['name']
def Latitude(Key, countryCode, Zip):
Geocoding = f'http://api.openweathermap.org/geo/1.0/zip?zip={Zip},{countryCode}&appid={Key}'
response = requests.get(Geocoding).json()
return response['lat']
def Longitude(Key, countryCode, Zip):
Geocoding = f'http://api.openweathermap.org/geo/1.0/zip?zip={Zip},{countryCode}&appid={Key}'
response = requests.get(Geocoding).json()
return response['lon']
def CurrentAirPollution(Path):
response = requests.get(Path).json()
AQI = response['list'][0]['main']['aqi']
CO = response['list'][0]['components']['co']
print(f'Carbon Monoxide = {CO}')
NO = response['list'][0]['components']['no']
print(f'Nitric Oxide = {NO}')
NO2 = response['list'][0]['components']['no2']
print(f'Nitrogen Dioxide = {NO2}')
O3 = response['list'][0]['components']['o3']
print(f'Trioxygen = {O3}')
SO2 = response['list'][0]['components']['so2']
print(f'Sulfur Dioxide = {SO2}')
PM = response['list'][0]['components']['pm2_5']
print(f'Dangerous: PM2.5 = {PM}')
PM10 = response['list'][0]['components']['pm10']
print(f'Dangerous: PM10, Particulate Matter = {PM10}')
NH3 = response['list'][0]['components']['nh3']
print(f'Azane = {NH3}')
if AQI >= 1 and AQI <= 3:
return f"Bad Air Quality, Air Quality = {AQI}"
elif AQI >= 4 and AQI <= 6:
return f"Moderate Air Quality, Air Quality = {AQI}"
elif AQI >= 7 and AQI <= 9:
return f"High Air Quality, Air Quality = {AQI}"
else:
return f"Very High Air Quality, Air Quality = 10"End of Code
____________________________________________________________________________________________________________
Note: This will display all of the things like how much carbon monoxide and stuff, I am not good at chemistry so I googled all of the chemical names sorry ):
Hope this helps you all beginners to getting a good idea of how much pain I felt making this CurrentAirPollution Functions cus too many errors started coming but I came up with this. Please don't be arrogant like me I suffered a lot, 2 hours of work );
Send help
Regards.
I found a decent free tier API that gives some hourly forecast data (openWeatherMap.com). It's pretty decent, but I started looking at their pricing for paid plans, and like, holy FUCK the "developer" plan is $180 per month! for a weather api? with limited endpoints? Why would anyone pay that much?
What's your favorite free weather API?
EDIT: I ended up going with weatherapi.com. Their endpoints are much more detailed than other options and offer 3 days of hour-by-hour forecast data on free tier, which is best in class.
Hi all, I'd like to create something similar weather table using api on my website.
https://www.romatoday.it/meteo/
Anyone knows a good free API source? Thanks.
Updated: 10/23/2022
OWM's One Call API requires a separate subscription. You will need to subscribe to "One Call by Call" plan, which includes 1,000 API calls per day for free. The watchface will call the API every 30 minutes, or 5 minutes when you moved at least 1km. So at most the watchface will make 288 calls per day, far less than 1,000 limit. Just make sure you don't share your OWM API key with others.
Updated: 8/2/2022
Now you can set the OWM api key in the setting file now. Check this post:Setting file generator (Add OWM API key to your app) : watchfacebuilder (reddit.com)
Updates about PIN -> OWM Key
When watch face app use any of owm data fielda, or owm location name, and if no OWM key was found by app, a PIN window will show up like this:
Make sure the last two lines are all Yes (gps and internet), and I added a count down timer on the face, you then head to Send API Key to Device – Garmin Watchface Online Builder (watchfacebuilder.com) page, and enter the PIN/Key there, and click "Submit"
Wait and check if the key was successfully imported to app. If so, it does, your watch face design should be visible now. But the weather data will take another 5 minutes to arrive.
Add the "Debug Output" on your watch face design. When everything is ok (has GPS location, and with valid OWM key), the "Debug Output" will show nothing. But if there is anything wrong, it will output the error message.
Here is the list of error messages:
no gps
invalid key
no data
over quota
"no gps" means watch face can't get your current location. Please start an outdoor activity and get a lock for GPS, then go back to your watch face to check.
"invalid key" means your entered OWM key is invalid. check if there are any typos.
"no data" means with your owm key and your current gps location, no data is returned from OneCall API. This happened to me a few times. I don't know why, and 30 minutes later it works again.
"over quota" means your API key was used too many time, and it's over quota (1000 calls per day and 60 calls per minutes).
===========
Because sideloaded watch face app does not have access to IQ store, so it doesn't have setting menu. In order to enter your own open weather map API key to your design, here are the steps:
When watchface app is launched without OWM key, the watch face will show a 4 digit PIN. Underneath the PIN, make sure it shows Yes, which indicates the watch has internet connection.
On your computer, go to garmin.watchfacebuilder.com, click "Send API Key" from left, or bookmark this url: Send API Key to Device – Garmin Watchface Online Builder (watchfacebuilder.com)
Select "Open Weather Map", enter 4 digits PIN, and the 32 character length of API key from OWM. (PIN on your device changes every 5 minutes, so make sure the PIN matches)
Click "Submit", then wait.
It will take at least 5 minutes for API key to be save on your device. After the key got pulled to your device, it will take another 5 minutes for weather data shown on your device.
Please add "Debug output" field on your watch to check if all required data are sent over to internet in order to get weather data from open weather map. The required data are:
Valid OWM Key
Valid GPS location
Please use this demo design to check your OWM API key.
OWM API Key Check
When this watch face starts, it will show 4 digits PIN in the middle, and yes or no on the bottom. Make sure it's "Yes".
Go to garmin.watchfacebuilder.com, click "Send API Key", enter your PIN as well as OWM API key, click "Submit".
It will take about 5 minutes, and the PIN screen should go to black screen. Waiting 5 more minute, and your location name should show up on the top, the middle will show your owm API key, lat/lng postion, and the bottom will show the weather condition icon.
During the entire above process, your watch should connect to your phone, and your phone should have internet access.
I'm having trouble with APIs working anyone know what I did wrong?
api.openweathermap.org/data/2.5/weather?zip=15234,us&APPID="my api here"
I obtained an API after registering.
OPENWEATHERMAP API V2.5 DEPRECATION
OpenWeatherMap API V2.5 will be closed in June 2024. After this date, you will need to use API V3.0.
To continue using the service:
Visit the OpenWeatherMap website and activate the One Call subscription.
During activation, you will be prompted for a credit card, but you will not be charged unless you exceed the free tier limits.
Configure your OWM integration to select mode v3.0.
Note: Subscription activation may take up to 2 hours.
I'm wary of linking a credit card to yet another service with the intent of maintaining free service requirements. Curious if others share this sentiment and which weather services people use in the USA? I have quite a few scripts and automations using weather data that will require manual migration.
I tried OpenWeatherMap but I need to put a credit card in and I don't have that right now. I also tried weatherstack but the info it gave me was wrong. Meteo wants a free trial.
Are there alternative weather API that are free and accurate without having put credit details in?
With open weather API going to a freemium service, I'm not having a subscription for weather and potentially being charged with a credit card on file because my home assistant wanted to know a basic forecast...
Any other good free weather integrations for HA?
GitHub told me it was exposed and notified me. I looked it up and it's mostly just weather detection. Is it a problem?
Any fan favorites for both current and historical weather data?
I tried to run a short program from the book Automate The Boring Stuff With Python, and, my result doesn't match the result predicted by the book. Here's the code:
import requests,json,sys
APPID ='7b26c92417fd3678d52eac12dc870222'
if len(sys.argv) < 2:
print('Usage: getOpenWeather.py city_name, 2-letter_country_code')
sys.exit()
location = ''.join(sys.argv[1:])
#Download the JSON data from OpenWeatherMap.org's API.
url = f'https://api.openweathermap.org/data/2.5/forecast/daily?q={location}&cnt=3&APPID={APPID}'
response = requests.get(url)
response.raise_for_status()
#Uncomment to see the raw JSON text:
#print(response.text)
#Load JSON data into a Python variable.
weatherData = json.loads(response.text)
#Print weather descriptions
w = weatherData['list']
print('Current weather in %s:'%(location))
print(w[0]['weather'][0]['main'],'-',w[0]['weather'][0]['description'])
print()
print('Tomorrow:')
print(w[1]['weather'][0]['main'],'-',w[1]['weather'][0]['description'])
print()
print('Day after tomorrow:')
print(w[2]['weather'][0]['main'],'-',w[2]['weather'][0]['description'])The response I got was:
Traceback (most recent call last):
File "C:\Users\Vesna\PycharmProjects\getOpenWeather.py", line 13, in <module>
response.raise_for_status()
File "C:\Users\Vesna\AppData\Roaming\Python\Python39\site-packages\requests\models.py", line 943, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://api.openweathermap.org/data/2.5/forecast/daily?q=Belgrade,Serbia&cnt=3&APPID=7b26c92417fd3678d52eac12dc870222Then I commented out the raise_for_status function, and added a print statement regarding the response object from the API call ( just uncommented it ), and got this instead:
{"cod":401, "message": "Invalid API key. Please see http://openweathermap.org/faq#error401 for more info."}
Traceback (most recent call last):
File "C:\Users\Vesna\PycharmProjects\getOpenWeather.py", line 22, in <module>
w = weatherData['list']
KeyError: 'list'Both messages allude to the same perceived root cause: lack of valid API key. However, this is just not the case. According to the website I used ( open weather ), a few things could cause the given error ( 401 ): invalid API key, not enough time spent after generating your first key, and trying to access premium services. I did get a valid API key, and even generated another one just to test it out ( with no different result ), I waited hours after my first attempt, so the possibility of my key not yet having finished the process of authorization is minimal, and I've checked multiple time which API services I requested, and they were the free ones ( current weather ) ONLY.
I have no idea what could be causing this error, and would immensely appreciate it if anyone helped me out with this, if they spot or know something I don't.