I’m trying to add support for the netamo thermostat.
Heavily based on work of Philippe Larduinat and fastcolors and ezekri I wrote this.
My netatmo.py:
"""
Support for Netatmo thermostat.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/thermostat.netatmo/
"""
import logging
import socket
from datetime import timedelta
#from homeassistant.components.thermostat import ThermostatDevice, DOMAIN
from homeassistant.components.thermostat import (
STATE_COOL, STATE_HEAT, STATE_IDLE, ThermostatDevice, DOMAIN)
from homeassistant.const import (
CONF_API_KEY, CONF_PASSWORD, CONF_USERNAME, TEMP_CELCIUS)
from homeassistant.helpers import validate_config
from homeassistant.helpers.entity import Entity
from homeassistant.util import Throttle
REQUIREMENTS = [
'https://github.com/gieljnssns/tnetatmo/archive/master.zip'
'#tnetatmo==0.1.0']
_LOGGER = logging.getLogger(__name__)
CONF_SECRET_KEY = 'secret_key'
ATTR_MODULE = 'modules'
# Return cached results if last scan was less then this time ago
# NetAtmo Data is uploaded to server every 10mn
# so this time should not be under
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=600)
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the NetAtmo Thermostat."""
if not validate_config({DOMAIN: config},
{DOMAIN: [CONF_API_KEY,
CONF_USERNAME,
CONF_PASSWORD,
CONF_SECRET_KEY]},
_LOGGER):
return None
import tnetatmo
authorization = tnetatmo.ClientAuth(config.get(CONF_API_KEY, None),
config.get(CONF_SECRET_KEY, None),
config.get(CONF_USERNAME, None),
config.get(CONF_PASSWORD, None))
if not authorization:
_LOGGER.error(
"Connection error "
"Please check your settings for NatAtmo API.")
return False
data = NetAtmoData(authorization)
dev = tnetatmo.DeviceList(authorization)
#dev = (netatmothermostat)
# try:
# # Iterate each module
# for module_name in config[ATTR_MODULE].items():
# # Test if module exist """
# if module_name not in data.get_module_names():
# _LOGGER.error('Module name: "%s" not found', module_name)
# continue
# # Only create sensor for monitored """
# # for variable in monitored_conditions:
# # if variable not in SENSOR_TYPES:
# # _LOGGER.error('Sensor type: "%s" does not exist', variable)
# # else:
# # dev.append(
# # NetAtmoSensor(data, module_name, variable))
# except KeyError:
# pass
add_devices([
NetatmoThermostat(dev)
])
class NetatmoThermostat(ThermostatDevice):
"""Representation a Netatmo thermostat."""
def __init__(self, netatmo_data):
"""Initialize the sensor."""
self._name = "NetAtmo {} {}"
self.netatmo_data = netatmo_data
self._dev = dev
# self.module_name = module_name
# self.type = sensor_type
self._state = None
# self._unit_of_measurement = SENSOR_TYPES[sensor_type][1]
self.update()
@property
def name(self):
"""Return the name of the sensor."""
return self._name
@property
def state(self):
"""Return the state of the device."""
return self._state
# pylint: disable=too-many-branches
# def update(self):
# """Get the latest data from NetAtmo API and updates the states."""
# self.netatmo_data.update()
# data = self.netatmo_data.data[self.module_name]
#
# if self.type == 'temperature':
# self._state = round(data['Temperature'], 1)
# elif self.type == 'humidity':
# self._state = data['Humidity']
# elif self.type == 'rain':
# self._state = data['Rain']
# elif self.type == 'sum_rain_1':
# self._state = data['sum_rain_1']
# elif self.type == 'sum_rain_24':
# self._state = data['sum_rain_24']
# elif self.type == 'noise':
# self._state = data['Noise']
# elif self.type == 'co2':
# self._state = data['CO2']
# elif self.type == 'pressure':
# self._state = round(data['Pressure'], 1)
@property
def unit_of_measurement(self):
"""Return the unit of measurement."""
return TEMP_CELCIUS
@property
def current_temperature(self):
"""Return the current temperature."""
return self._dev.getthermoinfo
# def __init__(self, pdp):
# """Initialize the thermostat."""
# self._pdp = pdp
# # self._name = self._pdp.moduleByName
# # self.netatmo_data = netatmo_data
# # self.module_name = module_name
# # self.type = sensor_type
# self._state = None
# # self._unit_of_measurement = SENSOR_TYPES[sensor_type][1]
# self.update()
#
# @property
# def should_poll(self):
# """Polling needed for thermostat."""
# return True
#
# def update(self):
# """Update the data from the thermostat."""
# self.netatmo_data.update()
#
# @property
# def name(self):
# """Return the name of the thermostat."""
# return self._name
#
# @property
# def device_state_attributes(self):
# """Return the device specific state attributes."""
# return {
# "fan": self._data.fan_state
# }
#
# @property
# def unit_of_measurement(self):
# """Return the unit of measurement."""
# return TEMP_CELCIUS
#
# @property
# def current_temperature(self):
# """Return the current temperature."""
# return self._data.cur_temp
#
@property
def target_temperature(self):
"""Return the temperature we try to reach."""
return self._dev.setPointTemp
#
# @property
# def operation(self):
# """Return the current state of the thermostat."""
# state = self._data.hvac_state
# if state in (1, 2):
# return STATE_IDLE
# elif state == 3:
# return STATE_HEAT
# elif state == 6:
# return STATE_COOL
#
# def set_temperature(self, temperature):
# """Set new target temperature."""
# self._data.setback_heat = temperature
#
#
class NetAtmoData(object):
"""Get the latest data from NetAtmo."""
def __init__(self, auth):
"""Initialize the data object."""
self.auth = auth
self.data = None
def get_module_names(self):
"""Return all module available on the API as a list."""
self.update()
return self.data.keys()
@Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self):
"""Call the NetAtmo API to update the data."""
import tnetatmo
dev_list = tnetatmo.DeviceList(self.auth)
self.data = dev_list.getthermoinfo(exclude=3600)
#
I can get tnetatmo installed in /deps
but I get this error while booting
16-05-04 08:19:24 ERROR (MainThread) [homeassistant.components.thermostat] Error while setting up platform netatmo
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/entity_component.py", line 94, in _setup_platform
discovery_info)
File "/usr/local/lib/python3.4/dist-packages/homeassistant/components/thermostat/netatmo.py", line 62, in setup_platform
dev = tnetatmo.DeviceList(authorization)
File "/home/pi/.homeassistant/deps/tnetatmo.py", line 122, in __init__
for m in self.devices['modules']: self.modules[m['_id']] = m
KeyError: 'modules'
This is the response in Postman:
{
"body": {
"devices": [
{
"_id": "***",
"firmware": 49,
"last_bilan": {
"y": 2016,
"m": 4
},
"last_setup": 1442917735,
"last_status_store": 1462308429,
"modules": [
{
"_id": "****",
"module_name": "Thermostaat",
"type": "NATherm1",
"firmware": 38,
"last_message": 1462308423,
"rf_status": 74,
"battery_vp": 4376,
"therm_orientation": 2,
"therm_relay_cmd": 0,
"battery_percent": 92,
"event_history": {
"boiler_not_responding_events": [
{
"K": 1452448030
}
],
"boiler_responding_events": [
{
"K": 1452448040
}
]
},
"last_therm_seen": 1462308423,
"setpoint": {
"setpoint_mode": "program"
},
"therm_program_list": [
{
"zones": [
{
"type": 0,
"id": 0,
"temp": 19
},
{
"type": 1,
"id": 1,
"temp": 17
},
{
"type": 2,
"id": 2,
"temp": 12
},
{
"type": 3,
"id": 3,
"temp": 7
},
{
"type": 5,
"id": 4,
"temp": 16
}
],
"timetable": [
{
"m_offset": 0,
"id": 1
},
{
"m_offset": 420,
"id": 0
},
{
"m_offset": 480,
"id": 4
},
{
"m_offset": 1140,
"id": 0
},
{
"m_offset": 1320,
"id": 1
},
{
"m_offset": 1860,
"id": 0
},
{
"m_offset": 1920,
"id": 4
},
{
"m_offset": 2580,
"id": 0
},
{
"m_offset": 2760,
"id": 1
},
{
"m_offset": 3300,
"id": 0
},
{
"m_offset": 3360,
"id": 4
},
{
"m_offset": 4020,
"id": 0
},
{
"m_offset": 4200,
"id": 1
},
{
"m_offset": 4740,
"id": 0
},
{
"m_offset": 4800,
"id": 4
},
{
"m_offset": 5460,
"id": 0
},
{
"m_offset": 5640,
"id": 1
},
{
"m_offset": 6180,
"id": 0
},
{
"m_offset": 6240,
"id": 4
},
{
"m_offset": 6900,
"id": 0
},
{
"m_offset": 7080,
"id": 1
},
{
"m_offset": 7620,
"id": 0
},
{
"m_offset": 8520,
"id": 1
},
{
"m_offset": 9060,
"id": 0
},
{
"m_offset": 9960,
"id": 1
}
],
"default": true,
"program_id": "56012d8acce37c2c5d6d07a3",
"name": "Default"
},
{
"zones": [
{
"type": 0,
"name": "Comfort",
"temp": 21,
"id": 0
},
{
"type": 1,
"name": "Nacht",
"temp": 18,
"id": 1
},
{
"type": 2,
"name": "Afwezig",
"temp": 14,
"id": 2
},
{
"type": 3,
"name": "Vorstvrij",
"temp": 7,
"id": 3
},
{
"type": 5,
"name": "Eco",
"temp": 16,
"id": 4
},
{
"type": 4,
"name": "Tussenin",
"temp": 19.5,
"id": 5
},
{
"type": 4,
"name": "Ochtend",
"temp": 20,
"id": 6
}
],
"timetable": [
{
"id": 1,
"m_offset": 0
},
{
"id": 6,
"m_offset": 420
},
{
"id": 4,
"m_offset": 510
},
{
"id": 5,
"m_offset": 720
},
{
"id": 4,
"m_offset": 810
},
{
"id": 0,
"m_offset": 960
},
{
"id": 1,
"m_offset": 1350
},
{
"id": 6,
"m_offset": 1860
},
{
"id": 4,
"m_offset": 1950
},
{
"id": 5,
"m_offset": 2160
},
{
"id": 4,
"m_offset": 2250
},
{
"id": 0,
"m_offset": 2400
},
{
"id": 1,
"m_offset": 2790
},
{
"id": 6,
"m_offset": 3300
},
{
"id": 4,
"m_offset": 3390
},
{
"id": 5,
"m_offset": 3600
},
{
"id": 4,
"m_offset": 3690
},
{
"id": 0,
"m_offset": 3840
},
{
"id": 1,
"m_offset": 4230
},
{
"id": 6,
"m_offset": 4740
},
{
"id": 4,
"m_offset": 4830
},
{
"id": 5,
"m_offset": 5040
},
{
"id": 4,
"m_offset": 5130
},
{
"id": 0,
"m_offset": 5280
},
{
"id": 1,
"m_offset": 5670
},
{
"id": 6,
"m_offset": 6180
},
{
"id": 4,
"m_offset": 6270
},
{
"id": 5,
"m_offset": 6480
},
{
"id": 4,
"m_offset": 6570
},
{
"id": 0,
"m_offset": 6720
},
{
"id": 1,
"m_offset": 7110
},
{
"id": 0,
"m_offset": 7620
},
{
"id": 5,
"m_offset": 7800
},
{
"id": 0,
"m_offset": 8100
},
{
"id": 1,
"m_offset": 8580
},
{
"id": 0,
"m_offset": 9060
},
{
"id": 5,
"m_offset": 9240
},
{
"id": 0,
"m_offset": 9540
},
{
"id": 1,
"m_offset": 10020
}
],
"program_id": "56012fd94bda1d9b14b0088a",
"name": "Week",
"selected": true
},
{
"timetable": [
{
"id": 1,
"m_offset": 0
},
{
"id": 0,
"m_offset": 420
},
{
"id": 4,
"m_offset": 480
},
{
"id": 0,
"m_offset": 720
},
{
"id": 4,
"m_offset": 780
},
{
"id": 0,
"m_offset": 1140
},
{
"id": 1,
"m_offset": 1320
},
{
"id": 0,
"m_offset": 1860
},
{
"id": 4,
"m_offset": 1920
},
{
"id": 0,
"m_offset": 2160
},
{
"id": 4,
"m_offset": 2220
},
{
"id": 0,
"m_offset": 2580
},
{
"id": 1,
"m_offset": 2760
},
{
"id": 0,
"m_offset": 3300
},
{
"id": 4,
"m_offset": 3360
},
{
"id": 0,
"m_offset": 3600
},
{
"id": 4,
"m_offset": 3660
},
{
"id": 0,
"m_offset": 4020
},
{
"id": 1,
"m_offset": 4200
},
{
"id": 0,
"m_offset": 4740
},
{
"id": 4,
"m_offset": 4800
},
{
"id": 0,
"m_offset": 5040
},
{
"id": 4,
"m_offset": 5100
},
{
"id": 0,
"m_offset": 5460
},
{
"id": 1,
"m_offset": 5640
},
{
"id": 0,
"m_offset": 6180
},
{
"id": 4,
"m_offset": 6240
},
{
"id": 0,
"m_offset": 6480
},
{
"id": 4,
"m_offset": 6540
},
{
"id": 0,
"m_offset": 6900
},
{
"id": 1,
"m_offset": 7080
},
{
"id": 0,
"m_offset": 7620
},
{
"id": 1,
"m_offset": 8520
},
{
"id": 0,
"m_offset": 9060
},
{
"id": 1,
"m_offset": 9960
}
],
"zones": [
{
"type": 0,
"temp": 20,
"id": 0
},
{
"type": 1,
"temp": 18,
"id": 1
},
{
"type": 2,
"temp": 13,
"id": 2
},
{
"type": 3,
"temp": 7,
"id": 3
},
{
"type": 5,
"temp": 16,
"id": 4
}
],
"name": "Week2",
"program_id": "560f760c45a1e3ed33b0a8a4"
}
],
"measured": {
"time": 1462308046,
"temperature": 21.3,
"setpoint_temp": 18
}
}
],
"place": {
"altitude": 9,
"city": "****",
"country": "BE",
"improveLocProposed": true,
"location": [
***,
****
],
"timezone": "Europe/Brussels",
"trust_location": true
},
"plug_connected_boiler": true,
"station_name": "Thuis",
"type": "NAPlug",
"udp_conn": true,
"wifi_status": 65,
"last_plug_seen": 1462308429
}
],
"user": {
"mail": "***",
"administrative": {
"reg_locale": "nl-BE",
"lang": "nl-NL",
"unit": 0,
"windunit": 0,
"pressureunit": 0,
"feel_like_algo": 0
}
}
},
"status": "ok",
"time_exec": 0.011533975601196,
"time_server": 1462309050
How do i reach ‘modules’?