Created
May 1, 2016 20:46
-
-
Save jdrews/37f374a6e196cfdc81aa27196534c4cf to your computer and use it in GitHub Desktop.
Grab temp and humidity from forecast.io and store in influxdb. Poll trigger via cron
This file contains 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
import forecastio | |
from influxdb import InfluxDBClient | |
client = InfluxDBClient(host='YOUR_IP', | |
port=8086, | |
database='YOURDB', | |
username='username', | |
password='password', | |
verify_ssl=False) | |
api_key = "forecast.io api-key" | |
lat = -80.253391 | |
lng = -59.897461 | |
forecast = forecastio.load_forecast(api_key, lat, lng) | |
current = forecast.currently() | |
temp = float(current.temperature) | |
humidity = float(current.humidity * 100) | |
points = [] | |
point = { | |
"measurement": 'temp', | |
"tags": { | |
"sensor": "Outside-forecastio" | |
}, | |
"fields": { | |
"value": temp | |
} | |
} | |
points.append(point) | |
point = { | |
"measurement": 'humidity', | |
"tags": { | |
"sensor": "Outside-forecastio" | |
}, | |
"fields": { | |
"value": humidity | |
} | |
} | |
points.append(point) | |
client.write_points(points) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment