Hello all
I own a heatpump supporting network (Luxtronik controller) and I’d like to add a component to HASS which can provide information from the heatpump and even do some settings.
Now I’m totally new to HASS development (and even python) so I’m struggling at quite some places.
Here’s what I want to achieve:
- Having a set of sensors that show various information (like outside temperature, water temperature, time to next defrosting)
- Having some input (selects and numbers) to set some values in the heatpump
I want to start with the first one, so only showing sensor values and postpone the setting of values to later.
I already have python code ready to read/set the values by reading using a socket or a websocket. I will encapsulate this in it’s own component when the rest is working.
But now I am struggling already at the very beginning: Do I write a Component or a Platform? I don’t really get the difference between them. I suspect I should write a Platform which has multiple sensors (one for each value). Is this correct?
Also I would like to refresh the value with a certain intervall. Do I use something like async_track_time_interval
with a method which calls async_device_update
and async_schedule_update_ha_state
on all my devices?
I would really appreciate your help and guidance as I have plenty of ideas for more components/plattforms for HASS I’d like to contribute
Here’s some code I already hacked together too just get some random values in HASS but which is using a component and not a platform.
""" Support for Luxtronik Heatpump Control (like in Alpha Innotec or Novelan heatpumps) """
import asyncio
import logging
from datetime import timedelta
import xml.etree.ElementTree as ET
import websockets
from homeassistant.const import (STATE_OK, STATE_UNKNOWN)
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.event import async_track_time_interval
REQUIREMENTS = ['websockets==4.0.1']
DOMAIN = 'luxtronik'
ENTITY_ID = 'lux.lux'
_LOGGER = logging.getLogger(__name__)
@asyncio.coroutine
def async_setup(hass, config):
_LOGGER.warn("Setting up Luxtronik")
lux = Luxtronik(hass)
def hub_refresh(event_time):
lux.async_device_update()
lux.async_schedule_update_ha_state()
interval = timedelta(seconds=300)
async_track_time_interval(hass, hub_refresh, interval)
return True
class Luxtronik(Entity):
entity_id = ENTITY_ID
def __init__(self, hass):
self.hass = hass
self._state = STATE_UNKNOWN
@property
def name(self):
return "Luxtronik"
@property
def state(self):
return self._state
@property
def state_attributes(self):
from random import randint
return {
'temp1': randint(0, 9),
'temp2': randint(0, 9)
}
@asyncio.coroutine
def async_update(self):
self._state = STATE_OK