Created
March 30, 2022 16:07
-
-
Save glynhudson/7079b23563a286c2e28969da3e6cc31d to your computer and use it in GitHub Desktop.
OpenWeather Current Temperature to emoncms.org
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /usr/bin/python3 | |
import requests | |
import json | |
# Setup OpenWeather Map | |
openweather_api_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | |
lat = "xx.xxx" | |
lon = "-x.xxxx" | |
openweather_url = "https://api.openweathermap.org/data/2.5/onecall?lat=%s&lon=%s&appid=%s&units=metric&exclude=minutely,hourly,daily,alerts" % (lat, lon, openweather_api_key) | |
# Get Temperature | |
response = requests.get(openweather_url) | |
data = json.loads(response.text) | |
current = data.get('current') | |
temp = current.get('temp') | |
# Setup Emoncms | |
emoncms_apikey='xxxxxxx' | |
payload = {'csv':temp, 'apikey':emoncms_apikey} | |
url_emoncms = 'https://emoncms.org/input/post?node=ambient_temp' | |
if type(temp) == float: | |
print(temp) | |
r = requests.post(url_emoncms, params=(payload)) | |
print (r.text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment