2015-11-18 00:14:29 +00:00
|
|
|
"""
|
|
|
|
homeassistant.components.sensor.ecobee
|
2015-11-23 16:15:19 +00:00
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Ecobee Thermostat Component
|
|
|
|
|
|
|
|
This component adds support for Ecobee3 Wireless Thermostats.
|
|
|
|
You will need to setup developer access to your thermostat,
|
|
|
|
and create and API key on the ecobee website.
|
|
|
|
|
|
|
|
The first time you run this component you will see a configuration
|
|
|
|
component card in Home Assistant. This card will contain a PIN code
|
|
|
|
that you will need to use to authorize access to your thermostat. You
|
|
|
|
can do this at https://www.ecobee.com/consumerportal/index.html
|
|
|
|
Click My Apps, Add application, Enter Pin and click Authorize.
|
|
|
|
|
|
|
|
After authorizing the application click the button in the configuration
|
|
|
|
card. Now your thermostat and sensors should shown in home-assistant.
|
|
|
|
|
|
|
|
You can use the optional hold_temp parameter to set whether or not holds
|
|
|
|
are set indefintely or until the next scheduled event.
|
|
|
|
|
|
|
|
ecobee:
|
|
|
|
api_key: asdfasdfasdfasdfasdfaasdfasdfasdfasdf
|
|
|
|
hold_temp: True
|
2015-11-18 00:14:29 +00:00
|
|
|
|
|
|
|
"""
|
2015-11-29 21:49:05 +00:00
|
|
|
import logging
|
|
|
|
|
2015-11-18 00:14:29 +00:00
|
|
|
from homeassistant.helpers.entity import Entity
|
2015-11-24 14:29:33 +00:00
|
|
|
from homeassistant.components import ecobee
|
2015-11-23 16:15:19 +00:00
|
|
|
from homeassistant.const import TEMP_FAHRENHEIT
|
2015-11-18 00:14:29 +00:00
|
|
|
|
2015-11-23 16:15:19 +00:00
|
|
|
DEPENDENCIES = ['ecobee']
|
2015-11-18 15:13:46 +00:00
|
|
|
|
2015-11-18 00:14:29 +00:00
|
|
|
SENSOR_TYPES = {
|
2015-11-23 16:15:19 +00:00
|
|
|
'temperature': ['Temperature', TEMP_FAHRENHEIT],
|
2015-11-18 00:14:29 +00:00
|
|
|
'humidity': ['Humidity', '%'],
|
2016-01-18 01:50:20 +00:00
|
|
|
'occupancy': ['Occupancy', None]
|
2015-11-18 00:14:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
ECOBEE_CONFIG_FILE = 'ecobee.conf'
|
|
|
|
|
|
|
|
|
|
|
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
|
|
|
""" Sets up the sensors. """
|
2015-11-23 16:15:19 +00:00
|
|
|
if discovery_info is None:
|
|
|
|
return
|
2015-12-02 21:22:25 +00:00
|
|
|
data = ecobee.NETWORK
|
2015-12-02 22:42:53 +00:00
|
|
|
dev = list()
|
2015-12-02 21:22:25 +00:00
|
|
|
for index in range(len(data.ecobee.thermostats)):
|
|
|
|
for sensor in data.ecobee.get_remote_sensors(index):
|
|
|
|
for item in sensor['capability']:
|
2015-12-03 13:57:28 +00:00
|
|
|
if item['type'] not in ('temperature',
|
|
|
|
'humidity', 'occupancy'):
|
|
|
|
continue
|
|
|
|
|
|
|
|
dev.append(EcobeeSensor(sensor['name'], item['type'], index))
|
2015-11-18 00:14:29 +00:00
|
|
|
|
|
|
|
add_devices(dev)
|
|
|
|
|
|
|
|
|
|
|
|
class EcobeeSensor(Entity):
|
|
|
|
""" An ecobee sensor. """
|
|
|
|
|
2015-12-02 21:22:25 +00:00
|
|
|
def __init__(self, sensor_name, sensor_type, sensor_index):
|
2015-11-18 00:14:29 +00:00
|
|
|
self._name = sensor_name + ' ' + SENSOR_TYPES[sensor_type][0]
|
|
|
|
self.sensor_name = sensor_name
|
|
|
|
self.type = sensor_type
|
2015-12-02 21:22:25 +00:00
|
|
|
self.index = sensor_index
|
2015-11-18 00:14:29 +00:00
|
|
|
self._state = None
|
|
|
|
self._unit_of_measurement = SENSOR_TYPES[sensor_type][1]
|
|
|
|
self.update()
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
return self._name.rstrip()
|
|
|
|
|
|
|
|
@property
|
|
|
|
def state(self):
|
|
|
|
""" Returns the state of the device. """
|
|
|
|
return self._state
|
|
|
|
|
|
|
|
@property
|
|
|
|
def unit_of_measurement(self):
|
|
|
|
return self._unit_of_measurement
|
|
|
|
|
|
|
|
def update(self):
|
2015-12-02 21:22:25 +00:00
|
|
|
data = ecobee.NETWORK
|
2015-12-02 22:42:53 +00:00
|
|
|
data.update()
|
2015-12-02 21:22:25 +00:00
|
|
|
for sensor in data.ecobee.get_remote_sensors(self.index):
|
|
|
|
for item in sensor['capability']:
|
2015-12-02 22:42:53 +00:00
|
|
|
if (
|
|
|
|
item['type'] == self.type and
|
|
|
|
self.type == 'temperature' and
|
|
|
|
self.sensor_name == sensor['name']):
|
|
|
|
self._state = float(item['value']) / 10
|
|
|
|
elif (
|
|
|
|
item['type'] == self.type and
|
|
|
|
self.type == 'humidity' and
|
|
|
|
self.sensor_name == sensor['name']):
|
|
|
|
self._state = item['value']
|
|
|
|
elif (
|
|
|
|
item['type'] == self.type and
|
|
|
|
self.type == 'occupancy' and
|
|
|
|
self.sensor_name == sensor['name']):
|
|
|
|
self._state = item['value']
|