Adding support for Netatmo Thermostat

Did you replace it before the restart of HA?
Replace it again.

@gieljnssns
now this

16-11-26 23:32:25 homeassistant.bootstrap: Error during setup of component netatmo
Traceback (most recent call last):
File “C:\Users\admin\AppData\Local\Programs\Python\Python35\lib\site-packages\homeassistant\bootstrap.py”, line 150, in _async_setup_component
None, component.setup, hass, config)
File “C:\Users\admin\AppData\Local\Programs\Python\Python35\lib\asyncio\futures.py”, line 361, in iter
yield self # This tells Task to wait for completion.
File “C:\Users\admin\AppData\Local\Programs\Python\Python35\lib\asyncio\tasks.py”, line 296, in _wakeup
future.result()
File “C:\Users\admin\AppData\Local\Programs\Python\Python35\lib\asyncio\futures.py”, line 274, in result
raise self._exception
File “C:\Users\admin\AppData\Local\Programs\Python\Python35\lib\concurrent\futures\thread.py”, line 55, in run
result = self.fn(*self.args, **self.kwargs)
File “C:\Users\admin\AppData\Local\Programs\Python\Python35\lib\site-packages\homeassistant\components\netatmo.py”, line 47, in setup
import lnetatmo
File “C:\Users\admin\AppData\Roaming.homeassistant\deps\lnetatmo.py”, line 17, in
from smart_home.Thermostat import ThermostatData
File “C:\Users\admin\AppData\Roaming.homeassistant\deps\smart_home\Thermostat.py”, line 5

^
SyntaxError: invalid syntax
16-11-26 23:32:25 homeassistant.bootstrap: Component netatmo failed to setup
16-11-26 23:32:25 homeassistant.bootstrap: Unable to prepare setup for platform climate.netatmo because dependency netatmo could not be initialized
16-11-26 23:32:29 homeassistant.bootstrap: Error during setup of component netatmo
Traceback (most recent call last):
File “C:\Users\admin\AppData\Local\Programs\Python\Python35\lib\site-packages\homeassistant\bootstrap.py”, line 150, in _async_setup_component
None, component.setup, hass, config)
File “C:\Users\admin\AppData\Local\Programs\Python\Python35\lib\asyncio\futures.py”, line 361, in iter
yield self # This tells Task to wait for completion.
File “C:\Users\admin\AppData\Local\Programs\Python\Python35\lib\asyncio\tasks.py”, line 296, in _wakeup
future.result()
File “C:\Users\admin\AppData\Local\Programs\Python\Python35\lib\asyncio\futures.py”, line 274, in result
raise self._exception
File “C:\Users\admin\AppData\Local\Programs\Python\Python35\lib\concurrent\futures\thread.py”, line 55, in run
result = self.fn(*self.args, **self.kwargs)
File “C:\Users\admin\AppData\Local\Programs\Python\Python35\lib\site-packages\homeassistant\components\netatmo.py”, line 47, in setup
import lnetatmo
File “C:\Users\admin\AppData\Roaming.homeassistant\deps\lnetatmo.py”, line 17, in
from smart_home.Thermostat import ThermostatData
File “C:\Users\admin\AppData\Roaming.homeassistant\deps\smart_home\Thermostat.py”, line 5

^
SyntaxError: invalid syntax
16-11-26 23:32:29 homeassistant.bootstrap: Component netatmo failed to setup
16-11-26 23:32:29 homeassistant.bootstrap: Unable to prepare setup for platform sensor.netatmo because dependency netatmo could not be initialized
16-11-26 23:32:33 homeassistant.bootstrap: Error during setup of component netatmo
Traceback (most recent call last):
File “C:\Users\admin\AppData\Local\Programs\Python\Python35\lib\site-packages\homeassistant\bootstrap.py”, line 150, in _async_setup_component
None, component.setup, hass, config)
File “C:\Users\admin\AppData\Local\Programs\Python\Python35\lib\asyncio\futures.py”, line 361, in iter
yield self # This tells Task to wait for completion.
File “C:\Users\admin\AppData\Local\Programs\Python\Python35\lib\asyncio\tasks.py”, line 296, in _wakeup
future.result()
File “C:\Users\admin\AppData\Local\Programs\Python\Python35\lib\asyncio\futures.py”, line 274, in result
raise self._exception
File “C:\Users\admin\AppData\Local\Programs\Python\Python35\lib\concurrent\futures\thread.py”, line 55, in run
result = self.fn(*self.args, **self.kwargs)
File “C:\Users\admin\AppData\Local\Programs\Python\Python35\lib\site-packages\homeassistant\components\netatmo.py”, line 47, in setup
import lnetatmo
File “C:\Users\admin\AppData\Roaming.homeassistant\deps\lnetatmo.py”, line 17, in
from smart_home.Thermostat import ThermostatData
File “C:\Users\admin\AppData\Roaming.homeassistant\deps\smart_home\Thermostat.py”, line 5

^
SyntaxError: invalid syntax

@gieljnssns
Hi, any chance to fix it? I would even just get back my netatmo weather, that also disappeared

Can you post the first 10 lines from your thermostat.py file.

@gieljnssns
Is this enough? I can post all of it, or send it privately, tell me if there is sensitive data that needed to be hiddden

<!DOCTYPE html>6528">

the file is here

C:\Users\admin\AppData\Roaming.homeassistant\deps\smart_home\Thermostat.py

p.s. a new Raspberry Pi is coming tomorrow. I will make the transition and transfer HA from Windows 10 to the Pi, in the week

the first lines should look look like this

"""
coding=utf-8
"""
import time

from . import NoDevice, postRequest, _BASE_URL

_SETTEMP_REQ = _BASE_URL + "api/setthermpoint"
_GETTHERMOSTATDATA_REQ = _BASE_URL + "api/getthermostatsdata"


class ThermostatData:
    """
    List the Thermostat devices (relays and thermostat modules)

    Args:
        authData (ClientAuth):
                Authentication information with a working access Token
    """

before everything else?

I put it before anything else.

Here the error log

this is my whole Thermostat.py file

"""
coding=utf-8
"""
import time

from . import NoDevice, postRequest, _BASE_URL

_SETTEMP_REQ = _BASE_URL + "api/setthermpoint"
_GETTHERMOSTATDATA_REQ = _BASE_URL + "api/getthermostatsdata"


class ThermostatData:
    """
    List the Thermostat devices (relays and thermostat modules)

    Args:
        authData (ClientAuth):
                Authentication information with a working access Token
    """
    def __init__(self, authData):
        self.getAuthToken = authData.accessToken
        postParams = {
                "access_token": self.getAuthToken
                }
        resp = postRequest(_GETTHERMOSTATDATA_REQ, postParams)

        self.rawData = resp['body']
        # self.devList = self.rawData['devices']
        # if not self.devList : raise NoDevice("No thermostat available")
        # self.devId = self.devList[0]['_id']
        # self.modList = self.devList[0]['modules']
        # self.modId = self.modList[0]['_id']
        # self.temp = self.modList[0]['measured']['temperature']
        # self.setpoint_temp = self.modList[0]['measured']['setpoint_temp']
        # self.setpoint_mode = self.modList[0]['setpoint']['setpoint_mode']
        # self.relay_cmd = int(self.modList[0]['therm_relay_cmd'])
        self.devices = {d['_id']: d for d in self.rawData['devices']}
        if not self.devices:
            raise NoDevice("No thermostat available")
        self.modules = dict()
        self.therm_program_list = dict()
        self.zones = dict()
        self.timetable = dict()
        for i in range(len(self.rawData['devices'])):
            nameDevice = self.rawData['devices'][i]['station_name']
            if nameDevice not in self.modules:
                self.modules[nameDevice] = dict()
            for m in self.rawData['devices'][i]['modules']:
                self.modules[nameDevice][m['_id']] = m
            for p in self.rawData['devices'][i]['modules'][
                    0]['therm_program_list']:
                self.therm_program_list[p['program_id']] = p
            for z in self.rawData['devices'][i]['modules'][
                    0]['therm_program_list'][0]['zones']:
                self.zones[z['id']] = z
            for o in self.rawData['devices'][i]['modules'][
                    0]['therm_program_list'][0]['timetable']:
                self.timetable[o['m_offset']] = o
        self.default_device = list(self.devices.values())[0]['station_name']

        self.default_module = list(
            self.modules[self.default_device].values())[0]
        # print('nog is')
        # print(self.devices)
        # print(self.modList)

    def deviceById(self, did):
        # print('deviceById')
        return None if did not in self.devices else self.devices[did]

    def deviceByName(self, device=None):
        # print('deviceByName')
        if not device:
            device = self.default_device
        for key, value in self.devices.items():
            if value['station_name'] == device:
                return self.devices[key]

    def moduleById(self, mid):
        # print('moduleById')
        for device, mod in self.modules.items():
            if mid in self.modules[device]:
                return self.modules[device][mid]
        return None

    def moduleByName(self, module=None, device=None):
        # print('moduleByName')
        if not module and not device:
            return self.default_module
        elif device and module:
            if device not in self.modules:
                return None
            for mod_id in self.modules[device]:
                if self.modules[device][mod_id]['module_name'] == module:
                    return self.modules[device][mod_id]
        elif not device and module:
            for device, mod_ids in self.modules.items():
                for mod_id in mod_ids:
                    if self.modules[device][mod_id]['module_name'] == module:
                        return self.modules[device][mod_id]
        else:
            return list(self.modules[device].values())[0]
        return None

    def setpoints(self, module=None, device=None, mid=None):
        """
        Return the setpoint of a given module.
        """
        # print('setpoints')
        setpoint = None
        if mid:
            module_data = self.moduleById(mid)
            # print('mid')
        else:
            module_data = self.moduleByName(device=device, module=module)
            # print('iets')
        if module_data:
            setpoint = module_data['measured']['setpoint_temp']
        return setpoint

    def away(self, module=None, device=None, mid=None):
        """
        Return the setpoint of a given module.
        """
        away = None
        if mid:
            module_data = self.moduleById(mid)
        else:
            module_data = self.moduleByName(device=device, module=module)
        if module_data:
            away = module_data['setpoint']['setpoint_mode']
        return away

    def currentTemp(self, module=None, device=None, mid=None):
        """
        Return the current temperature of a given module.
        """
        # print('currentTemp')
        current_temp = None
        if mid:
            # print('id')
            module_data = self.moduleById(mid)
            # print(module_data)
        else:
            # print('anders')
            module_data = self.moduleByName(device=device, module=module)
            # print(module_data)
        if module_data:
            # print(module_data)
            current_temp = module_data['measured']['temperature']
        return current_temp

    def operation(self, module=None, device=None, mid=None):
        """
        Return the operation (therm_relay_cmd) of a given device.
        """
        # print('operation')
        if mid:
            # print('mid')
            module_data = self.moduleById(mid)
        else:
            # print('else')
            module_data = self.moduleByName(device=device, module=module)
        if module_data:
            operation = module_data['therm_relay_cmd']
        # print(module_data)
        # print(operation)
        return operation

    def setthermpoint(self, mode, temp, endTimeOffset, device_id, module_id):
        postParams = {"access_token": self.getAuthToken}
        print(device_id)
        print(module_id)
        # postParams['device_id'] = self.devId
        # postParams['module_id'] = self.modId
        postParams['device_id'] = device_id
        postParams['module_id'] = module_id
        postParams['setpoint_mode'] = mode
        if mode == "manual":
            postParams['setpoint_endtime'] = time.time() + endTimeOffset
            postParams['setpoint_temp'] = temp
        return postRequest(_SETTEMP_REQ, postParams)

Yeah, who knows what I did, I created a total different Thermostat.py …

sorry, and thanks

No problem.
Can you tell me what’s working and what’s not.
I’ll try to fix it all, but wright now I’m busy with the Netatmo Presence.

Measurements are fine. Front end is fine.

It does not change the temperature

Is the presence a good product?
Can you anticipate what will be the HA integration?

I have mine a week.
It is still learning, he thinks sometimes my dog is a human and i am an animal.
At first i will try to make binary sensors for detection; human seen, animal seen, car seen.
And ofcourse live view.
Just like the Welcome camera.

mmhh not encouraging for an expensive camera. If it can’t do detection I am sure it can’t do recognition (identify different humans, i.e. family or somebody else) .
Supposedly should do face recognition (not detection)?

Only detection, not face recognition.

strange, the “welcome” does face recognition and the “Presence” not?

Hi!

Did you ever found time to fix the multiple Netatmo thermostat issues?

It would be good that at least you put the newest code for next version of HASS: is not working perfectly (it does not allow to change the temperature from HASS) but at least it shows correctly multiple thermostats in front end

front end is perfect for multiple thermostats. Unfortunately it allow to cjhange only temperature of one (the others will not change)

I will continue with this when the Presence is finished.
I have made a pull request for it, but it isn’t merged.

It would be good that at least you put the newest code for next version of HASS: is not working perfectly (it does not allow to change the temperature from HASS) but at least it shows correctly multiple thermostats in front end

This isn’t possible because lnetatmo must be changed and it isn’t backwards compatible.