API

Thermostat

Record Nest API data to InfluxDB.

The thermostat API is designed to persist Nest thermostat data in an InfluxDB database.

den.thermostat.NEST_API_LOCATION = 'developer-api.nest.com'

The base location of the Nest API.

den.thermostat.STREAM_DELIMITER = ':'

The token which separates line type and line data in the Nest streaming API response.

den.thermostat.STRUCTURE_FIELD_KEYS = ['away']

InfluxDB field keys.

den.thermostat.STRUCTURE_MEASUREMENT = 'structure'

InfluxDB measurement name.

den.thermostat.STRUCTURE_TAG_KEYS = ['away', 'country_code', 'name', 'postal_code', 'structure_id', 'thermostat_id', 'time_zone']

InfluxDB tag keys.

den.thermostat.THERMOSTAT_FIELD_KEYS = ['ambient_temperature_c', 'ambient_temperature_f', 'away_temperature_high_c', 'away_temperature_high_f', 'away_temperature_low_c', 'away_temperature_low_f', 'eco_temperature_high_c', 'eco_temperature_high_f', 'eco_temperature_low_c', 'eco_temperature_low_f', 'fan_timer_duration', 'humidity', 'locked_temp_max_c', 'locked_temp_max_f', 'locked_temp_min_c', 'locked_temp_min_f', 'target_temperature_c', 'target_temperature_f', 'target_temperature_high_c', 'target_temperature_high_f', 'target_temperature_low_c', 'target_temperature_low_f']

InfluxDB field keys.

den.thermostat.THERMOSTAT_MEASUREMENT = 'thermostat'

InfluxDB measurement name.

den.thermostat.THERMOSTAT_TAG_KEYS = ['can_cool', 'can_heat', 'device_id', 'fan_timer_active', 'has_fan', 'has_leaf', 'hvac_mode', 'hvac_state', 'is_locked', 'is_online', 'is_using_emergency_heat', 'label', 'locale', 'name', 'name_long', 'previous_hvac_mode', 'software_version', 'structure_id', 'sunlight_correction_active', 'sunlight_correction_enabled', 'temperature_scale', 'time_to_target', 'time_to_target_training', 'where_id', 'where_name']

InfluxDB tag keys.

den.thermostat.TIMEOUT = (7, 601)

Nest API timeout values in seconds.

The first value is the initial connection timeout. The second is the read timeout which ensures that the streaming connection will not block forever if the network connection has been lost.

den.thermostat.record(database, port, ssl, nest_api_access_token)

Stream results from the Nest API and record them in the database.

Parameters:
  • database (str) – The name of the database.
  • port (int) – The port number the database is listening on.
  • ssl (bool) – Whether or not to use SSL to communicate with the database.
  • nest_api_access_token (str) – Nest API access token.
Return type:

None

Returns:

When the stream opened to the Nest API has been consumed.

Raises:

requests.exceptions.StreamConsumedError: if the stream has been consumed.

Raises:

requests.exceptions.ConnectionError: if the Nest API cannot be reached.

Raises:

requests.exceptions.HTTPError: if an invalid response is returned from the Nest API.

Raises:

requests.exceptions.Timeout: if the request to the Nest API takes too long to respond.

Weather

Record weather data to InfluxDB.

den.weather.FIELD_KEYS = ['apparentTemperature', 'cloudCover', 'dewPoint', 'humidity', 'nearestStormBearing', 'nearestStormDistance', 'ozone', 'precipIntensity', 'precipProbability', 'pressure', 'temperature', 'time', 'visibility', 'windBearing', 'windSpeed']

InfluxDB field keys.

den.weather.MEASUREMENT = 'weather'

InfluxDB measurement value.

den.weather.TAG_KEYS = ['icon', 'precipType']

InfluxDB tag keys.

den.weather.record(database, port, ssl, api_key, lat, lon)

Record current weather data into the database.

Note

Weather data is recorded at second precision.

Parameters:
  • database (str) – The name of the database.
  • port (int) – The port number the database is listening on.
  • ssl (bool) – Whether or not to use SSL to communicate with the database.
  • api_key (str) –
  • lat (float) – Latitude
  • lon (float) – Longitude
Return type:

None

Returns:

When the current weather data has been written to the database.

Propane

Record propane data to InfluxDB.

den.propane.FIELD_KEYS = ['capacity', 'tank', 'temperature']

InfluxDB field keys.

den.propane.MEASUREMENT = 'propane'

InfluxDB measurement value.

den.propane.PROPANE_API_LOCATION = 'data.tankutility.com'

The base location of the propane API.

den.propane.TAG_KEYS = ['name', 'address', 'status', 'orientation', 'fuelType']

InfluxDB tag keys.

den.propane.record(database, port, ssl, username, password)

Record current propane data into the database.

Note

Propane data is recorded at second precision.

Parameters:
  • database (str) – The name of the database.
  • port (int) – The port number the database is listening on.
  • ssl (bool) – Whether or not to use SSL to communicate with the database.
  • username (str) –
  • password (str) –
Return type:

None

Returns:

When the current propane data has been written to the database.