I switched my home automation system from OpenHAB to Home-Assistant and am very happy with the decision so far.

Of course, I also had to change the integration of my heat pump. Therefore I developed my own module for Home-Assistant.

Result

The result looks like this:

Lovelace

Lovelace iDM heatpump I also visualized the values in Grafana which looks like this:

Heatpump in Home-Assistant Lovelace

Heatpump in Home-Assistant Lovelace

Grafana

Grafana visualization of heatpump data

Visualization in Grafana

Visualization in Grafana

Implementation

Python custom sensor

/custom_components/sensor/idm_heating.py

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
"""
Support for reading IDM Terra data through IDM API
Author: Thomas Beyer (solarisproject.de)
Based on: https://github.com/cyberjunky/home-assistant-custom-components/blob/master/sensor/toon_smartmeter.py

configuration.yaml

sensor:
  - platform: idm_heating
    username: user
    password: password
    scan_interval: 300
    resources:
      - mode
      - circuit_mode
      - errors
      - heat_quantity
      - outside_temp
      - forerun_temp_actual
      - forerun_temp_target
      - room_temp_target
      - return_flow_temp
      - hygienic_temp
      - water_temp
"""
import logging
from datetime import timedelta
import hashlib
import requests
import voluptuous as vol

from homeassistant.components.sensor import PLATFORM_SCHEMA
import homeassistant.helpers.config_validation as cv
from homeassistant.const import (
    CONF_USERNAME, CONF_PASSWORD, CONF_SCAN_INTERVAL, CONF_RESOURCES)
from homeassistant.util import Throttle
from homeassistant.helpers.entity import Entity

_LOGGER = logging.getLogger(__name__)

MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=300)

SENSOR_PREFIX = 'Heating '

SENSOR_TYPES = {
    'mode': ['mode', '', 'mdi:settings'],
    'circuit_mode': ['circuit mode', '', 'mdi:settings'],
    'errors': ['errors', '#', 'mdi:alert-circle'],
    'heat_quantity': ['heat quantity', 'kWh', 'mdi:radiator'],
    'outside_temp': ['outside temp.', '°C', 'mdi:thermometer'],
    'forerun_temp_actual': ['forerun temp. (actual)', '°C', 'mdi:temperature-celsius'],
    'forerun_temp_target': ['forerun temp. (target)', '°C', 'mdi:temperature-celsius'],
    'room_temp_target': ['room temp. (target)', '°C', 'mdi:thermometer'],
    'return_flow_temp': ['return flow temp.', '°C', 'mdi:temperature-celsius'],
    'hygienic_temp': ['hygienic temp.', '°C', 'mdi:temperature-celsius'],
    'water_temp': ['water temp.', '°C', 'mdi:temperature-celsius'],
}

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Required(CONF_USERNAME): cv.string,
    vol.Required(CONF_PASSWORD): cv.string,
    vol.Required(CONF_RESOURCES, default=[]):
        vol.All(cv.ensure_list, [vol.In(SENSOR_TYPES)]),
})

modeDictionary = {"icon_12": "Aus",
                  "icon_auto": "Automatik",
                  "icon_3": "Warmwasser oder Einmalige WW Ladung"}

circuitModeDictionary = {"icon_12": "Aus",
                         "icon_24": "Zeitprogramm",
                         "icon_21": "Normal",
                         "icon_11": "Eco",
                         "icon_5":  "manuell Heizen",
                         "icon_1":  "manuell Kühlen"}

idmHost = "https://www.myidm.at"
pathLogin = "/api/user/login"
pathInstallations = "/api/installation/values"
headers = {'User-Agent': 'IDM App (Android)'}


def setup_platform(hass, config, add_entities, discovery_info=None):
    _LOGGER.debug("Setup IDM Terra sensors")

    username = config.get(CONF_USERNAME)
    password = config.get(CONF_PASSWORD)
    passwordHashed = hashlib.sha1(password.encode()).hexdigest()
    scanInterval = config.get(CONF_SCAN_INTERVAL)

    try:
        data = IdmData(username, passwordHashed)
    except requests.exceptions.HTTPError as error:
        _LOGGER.error(error)
        return False

    entities = []

    for resource in config[CONF_RESOURCES]:
        sensor_type = resource.lower()

        if sensor_type not in SENSOR_TYPES:
            SENSOR_TYPES[sensor_type] = [
                sensor_type.title(), '', 'mdi:flash']

        entities.append(IdmHeatingSensor(data, sensor_type))

    add_entities(entities)


# pylint: disable=abstract-method
class IdmData(object):

    def __init__(self, username, password):
        self._username = username
        self._password = password
        self.data = None

    @Throttle(MIN_TIME_BETWEEN_UPDATES)
    def update(self):
        _LOGGER.debug("Updating IDM Terra sensors with remote API")
        try:
            payload = {'username':  self._username, 'password': self._password}
            j = requests.post(idmHost + pathLogin,
                              headers=headers, data=payload, timeout=10).json()
            token = j["token"]
            installation = j["installations"][0]["id"]
            #_LOGGER.debug("Login Data = %s", j)
            #_LOGGER.debug("Token = %s", token)
            #_LOGGER.debug("Installation = %s", installation)

            payload = {'installation': installation, 'token': token}
            self.data = requests.post(
                idmHost + pathInstallations, headers=headers, data=payload, timeout=10).json()
            #_LOGGER.debug("Installation Data = %s", self.data)

        except requests.exceptions.RequestException as exc:
            _LOGGER.error("Error occurred while fetching data: %r", exc)
            self.data = None
            return False


class IdmHeatingSensor(Entity):

    def __init__(self, data, sensor_type):
        self.data = data
        self.type = sensor_type
        self._name = SENSOR_PREFIX + SENSOR_TYPES[self.type][0]
        self._unit = SENSOR_TYPES[self.type][1]
        self._icon = SENSOR_TYPES[self.type][2]
        self._state = None

    @property
    def name(self):
        return self._name

    @property
    def icon(self):
        return self._icon

    @property
    def state(self):
        return self._state

    @property
    def unit_of_measurement(self):
        return self._unit

    def update(self):
        self.data.update()
        heatingData = self.data.data

        try:
            if self.type == 'mode':
                for key, value in modeDictionary.items():
                    heatingData["mode"] = heatingData["mode"].replace(key, value)
                self._state = heatingData["mode"]

            elif self.type == 'circuit_mode':
                for key, value in circuitModeDictionary.items():
                    heatingData["circuits"][0]["mode"] = heatingData["circuits"][0]["mode"].replace(key, value)
                self._state = heatingData["circuits"][0]["mode"]

            elif self.type == 'errors':
                self._state = int(heatingData["error"])

            elif self.type == 'heat_quantity':
                self._state = float(heatingData["sum_heat"].rstrip(" kWh"))

            elif self.type == 'outside_temp':
                self._state = float(heatingData["temp_outside"].rstrip(" °C"))

            elif self.type == 'forerun_temp_actual':
                self._state = float(heatingData["circuits"][0]["temp_forerun_actual"].rstrip(" °C"))

            elif self.type == 'forerun_temp_target':
                self._state = float(heatingData["circuits"][0]["temp_forerun"].rstrip(" °C"))

            elif self.type == 'room_temp_target':
                self._state = float(heatingData["circuits"][0]["temp_room_value"])

            elif self.type == 'return_flow_temp':
                self._state = float(heatingData["temp_heat"].rstrip(" °C"))

            elif self.type == 'hygienic_temp':
                self._state = float(heatingData["temp_hygienic"].rstrip(" °C"))

            elif self.type == 'water_temp':
                self._state = float(heatingData["temp_water"].rstrip(" °C"))
        except ValueError:
            self._state = None

Home-Assistant Configuration

configuration.yaml

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
- platform: idm_heating
  username: !secret heating_user
  password: !secret heating_password
  scan_interval: 300
  resources:
    - mode
    - circuit_mode
    - errors
    - heat_quantity
    - outside_temp
    - forerun_temp_actual
    - forerun_temp_target
    - room_temp_target
    - return_flow_temp
    - hygienic_temp
    - water_temp