Skip to content

Instantly share code, notes, and snippets.

@glynhudson
Created March 30, 2022 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glynhudson/7079b23563a286c2e28969da3e6cc31d to your computer and use it in GitHub Desktop.
Save glynhudson/7079b23563a286c2e28969da3e6cc31d to your computer and use it in GitHub Desktop.
OpenWeather Current Temperature to emoncms.org
# /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