Advertisement
Guest User

Untitled

a guest
May 1st, 2016
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. import ecobee
  2. from influxdb import InfluxDBClient
  3.  
  4. def logPoint(sensorName=None, sensorValue=None, sensorType=None):
  5. return {
  6. "measurement": sensorType,
  7. "tags": {
  8. "sensor": sensorName
  9. },
  10. "fields": {
  11. "value": sensorValue
  12. }
  13. }
  14.  
  15. client = InfluxDBClient(host='YOUR_IP',
  16. port=8086,
  17. database='YOURDB',
  18. username='username',
  19. password='password',
  20. verify_ssl=False)
  21.  
  22. APIKEY = "ecobee-api-key"
  23. points = []
  24. eapi = ecobee.Client(APIKEY,scope='smartRead')
  25.  
  26. thermostats = eapi.list_thermostats()
  27. for thermostat in thermostats:
  28. name = str(thermostat.name)
  29. temp = str(thermostat.current_temperature)
  30. humidity = str(thermostat.current_humidity)
  31. print("thermostat_name = " + name + ", temp = " + temp + ", humidity = " + humidity)
  32. points.append(logPoint(sensorName=name, sensorValue=float(temp), sensorType="temp"))
  33. points.append(logPoint(sensorName=name, sensorValue=float(humidity), sensorType="humidity"))
  34.  
  35. # there is only one remote sensor per thermostat. Otherwise loop over thermostat.list_sensors()
  36. sensor = thermostat.get_sensor("rs:100")
  37. name = str(sensor.name)
  38. temp = str(sensor.temperature)
  39. print("sensor_name = " + name + ", temp = " + temp)
  40. points.append(logPoint(sensorName=sensor.name, sensorValue=float(temp), sensorType="temp"))
  41.  
  42. print("points = " + str(points))
  43.  
  44. client.write_points(points)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement