From 12bba87757e804acb8d15258c202cf2176670b5f Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Mon, 1 Apr 2024 19:38:39 +0200 Subject: [PATCH] Added more elements and option to change heating mode --- custom_components/solvis_control/__init__.py | 12 ++- custom_components/solvis_control/const.py | 24 ++++-- .../solvis_control/coordinator.py | 8 +- .../solvis_control/manifest.json | 2 +- custom_components/solvis_control/sensor.py | 29 +------ custom_components/solvis_control/strings.json | 54 +++++++------ .../solvis_control/translations/de.json | 77 ++++++++++--------- .../solvis_control/translations/en.json | 53 +++++++------ 8 files changed, 139 insertions(+), 120 deletions(-) diff --git a/custom_components/solvis_control/__init__.py b/custom_components/solvis_control/__init__.py index 6d71ee7..ebbd8e4 100644 --- a/custom_components/solvis_control/__init__.py +++ b/custom_components/solvis_control/__init__.py @@ -1,7 +1,7 @@ """ Modul to integrate solvis heaters to. -Version: 0.2.0-alpha +Version: 0.3.0-beta """ """Solvis integration.""" @@ -15,7 +15,7 @@ from .const import CONF_HOST, CONF_PORT, DATA_COORDINATOR, DOMAIN from .coordinator import SolvisModbusCoordinator -PLATFORMS: [Platform] = [Platform.SENSOR] +PLATFORMS: [Platform] = [Platform.SENSOR, Platform.NUMBER, Platform.SELECT] async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: @@ -40,3 +40,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) return True + + +async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: + """Unload a config entry.""" + if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS): + hass.data[DOMAIN].pop(entry.entry_id) + + return unload_ok diff --git a/custom_components/solvis_control/const.py b/custom_components/solvis_control/const.py index b787d34..566f556 100644 --- a/custom_components/solvis_control/const.py +++ b/custom_components/solvis_control/const.py @@ -23,6 +23,8 @@ class ModbusFieldConfig: negative: bool = False entity_category: str = None enabled_by_default: bool = True + edit: bool = False + border: tuple = (0, 100) PORT = 502 @@ -137,6 +139,7 @@ class ModbusFieldConfig: unit="h", device_class="time", state_class="measurement", + entity_category="diagnostic", ), ModbusFieldConfig( # Brennerstarts name="number_gas_burner_start", @@ -146,6 +149,7 @@ class ModbusFieldConfig: state_class="measurement", negative=True, multiplier=1, + entity_category="diagnostic", ), ModbusFieldConfig( # Ionisationsstrom name="ionisation_voltage", @@ -225,19 +229,23 @@ class ModbusFieldConfig: name="hkr1_absenktemperatur_nacht", address=2821, unit="°C", - device_class="temperatur", + device_class="temperature", state_class="measurement", register=2, multiplier=1, + edit=True, + border=(5, 75), ), ModbusFieldConfig( # HKR1 Solltemperatur Tag name="hkr1_solltemperatur_tag", address=2820, unit="°C", - device_class="temperatur", + device_class="temperature", state_class="measurement", register=2, multiplier=1, + edit=True, + border=(5, 75), ), ModbusFieldConfig( # DigIn Stoerungen name="digin_stoerungen", @@ -252,17 +260,19 @@ class ModbusFieldConfig: name="ww_solltemperatur", address=2305, unit="°C", - device_class="temperatur", + device_class="temperature", state_class="measurement", register=2, multiplier=1, + edit=True, + border=(10, 65), ), ModbusFieldConfig( # VersionSC2 name="version_sc2", address=32770, unit="", device_class=None, - state_class="measurement", + state_class=None, multiplier=1, entity_category="diagnostic", ), @@ -271,7 +281,7 @@ class ModbusFieldConfig: address=32771, unit="", device_class=None, - state_class="measurement", + state_class=None, multiplier=1, entity_category="diagnostic", ), @@ -287,8 +297,10 @@ class ModbusFieldConfig: name="raumtemperatur_hkr1", address=34304, unit="°C", - device_class="temperatur", + device_class="temperature", state_class="measurement", register=2, + edit=True, + border=(0, 40), ), ] diff --git a/custom_components/solvis_control/coordinator.py b/custom_components/solvis_control/coordinator.py index f6e0686..6e77067 100644 --- a/custom_components/solvis_control/coordinator.py +++ b/custom_components/solvis_control/coordinator.py @@ -29,7 +29,7 @@ def __init__(self, hass, conf_host, conf_port): update_interval=timedelta(seconds=30), ) self.logger.debug("Creating client") - self.modbus = ModbusClient.ModbusTcpClient(host=conf_host, port=conf_port) + self.modbus = ModbusClient.AsyncModbusTcpClient(host=conf_host, port=conf_port) async def _async_update_data(self): """Fetch data from API endpoint. @@ -41,7 +41,7 @@ async def _async_update_data(self): parsed_data: dict = {} try: - self.modbus.connect() + await self.modbus.connect() except ConnectionException: self.logger.warning("Couldn't connect to device") if self.modbus.connected: @@ -49,11 +49,11 @@ async def _async_update_data(self): self.logger.debug("Connected to Modbus for Solvis") try: if register.register == 1: - result = self.modbus.read_input_registers( + result = await self.modbus.read_input_registers( register.address, 1, 1 ) elif register.register == 2: - result = self.modbus.read_holding_registers( + result = await self.modbus.read_holding_registers( register.address, 1, 1 ) except ModbusException as error: diff --git a/custom_components/solvis_control/manifest.json b/custom_components/solvis_control/manifest.json index e5aa366..10a8697 100644 --- a/custom_components/solvis_control/manifest.json +++ b/custom_components/solvis_control/manifest.json @@ -9,5 +9,5 @@ "iot_class": "local_polling", "issue_tracker": "https://github.com/LarsK1/hass_solvis_control/issues", "requirements": ["pymodbus"], - "version": "0.2.0-alpha" + "version": "0.3.0-beta" } diff --git a/custom_components/solvis_control/sensor.py b/custom_components/solvis_control/sensor.py index afb63b1..b9f8937 100644 --- a/custom_components/solvis_control/sensor.py +++ b/custom_components/solvis_control/sensor.py @@ -46,6 +46,10 @@ async def async_setup_entry( sensors_to_add = [] for register in REGISTERS: + if register.edit: + continue + if register.address == 2818: + continue sensors_to_add.append( SolvisSensor( hass.data[DOMAIN][entry.entry_id][DATA_COORDINATOR], @@ -81,7 +85,6 @@ def __init__( self._address = address self._response_key = name - # self._attr_name = name if entitiy_category == "diagnostic": self.entity_category = EntityCategory.DIAGNOSTIC self.entity_registry_enabled_default = enabled_by_default @@ -130,27 +133,3 @@ def _handle_coordinator_update(self) -> None: self._attr_available = True self._attr_native_value = response_data self.async_write_ha_state() - - -# - platform: template -# sensors: -# ww_zirkulationsart: -# friendly_name: "WW Zirkulation Betriebsart" -# entity_id: sensor.zirkulationbetriebsart -# value_template: >- -# {% if states('sensor.zirkulationbetriebsart') == '1' %} -# Aus -# {% elif states('sensor.zirkulationbetriebsart') == '2' %} -# Puls -# {% elif states('sensor.zirkulationbetriebsart') == '3' %} -# Temp -# {% elif states('sensor.zirkulationbetriebsart') == '4' %} -# Warten -# {% else %} -# unbekannt -# {% endif %} - -# hkr1betriebsart: -# friendly_name: "Heizkreislauf Betriebsart" -# entity_id: sensor.hkr1_betriebsart -# value_template: "{%if states.sensor.hkr1_betriebsart.state == '1' %}Aus{% elif states.sensor.hkr1_betriebsart.state == '2' %}Automatik{% elif states.sensor.hkr1_betriebsart.state == '3' %}Tagbetrieb{% elif states.sensor.hkr1_betriebsart.state == '4' %}Absenkbetrieb{% elif states.sensor.hkr1_betriebsart.state == '5' %}Standby{% elif states.sensor.hkr1_betriebsart.state == '6' %}Eco{% elif states.sensor.hkr1_betriebsart.state == '7' %}Urlaub{% elif states.sensor.hkr1_betriebsart.state == '8' %}WW Vorang{% elif states.sensor.zirkulationbetriebsart.state == '9' %}Frostschutz{% elif states.sensor.zirkulationbetriebsart.state == '10' %}Pumpenschutz{% elif states.sensor.hkr1_betriebsart.state == '11' %}Estrich{% endif %}" diff --git a/custom_components/solvis_control/strings.json b/custom_components/solvis_control/strings.json index a46db5e..4d72e6d 100644 --- a/custom_components/solvis_control/strings.json +++ b/custom_components/solvis_control/strings.json @@ -45,6 +45,34 @@ } }, "entity": { + "number": { + "ww_solltemperatur": { + "name": "WW Solltemperatur" + }, + "hkr1_absenktemperatur_nacht": { + "name": "HKR1 Absenktemperatur Nacht" + }, + "hkr1_solltemperatur_tag": { + "name": "HKR1 Solltemperatur Tag" + }, + "raumtemperatur_hkr1": { + "name": "Raumtemperatur HKR1" + } + }, + "select": { + "hkr1_betriebsart": { + "name": "HKR1 Betriebsart", + "state": { + "2": "Automatik", + "3": "Tagbetrieb", + "4": "Absenkbetrieb", + "5": "Standby", + "6": "Eco", + "7": "Urlaub" + + } + } + }, "sensor": { "gas_power": { "name": "Brennerleistung" @@ -121,40 +149,20 @@ "domestic_water_flow": { "name": "Durchfluss Warmwasserzirkualation" }, - "hkr1_betriebsart": { - "name": "HKR1 Betriebsart", - "state": { - "1": "Aus", - "2": "Puls", - "3": "Temp", - "4": "Warten" - } - }, - "hkr1_absenktemperatur_nacht": { - "name": "HKR1 Absenktemperatur Nacht" - }, - "hkr1_solltemperatur_tag": { - "name": "HKR1 Solltemperatur Tag" - }, - "ww_solltemperatur": { - "name": "WW Solltemperatur" - }, "version_sc2": { "name": "Version SC2" }, "version_nbg": { "name": "Version NBG" }, - "raumtemperatur_hkr1": { - "name": "Raumtemperatur HKR1" - }, + "zirkulation_betriebsart": { "name": "Zirkulation Betriebsart", "state": { "1": "Aus", "2": "Puls", - "3": "Temp", - "4": "Warten" + "3": "Zeit", + "4": "Puls/Zeit" } }, "digin_stoerungen": { diff --git a/custom_components/solvis_control/translations/de.json b/custom_components/solvis_control/translations/de.json index 541fb7d..4d72e6d 100644 --- a/custom_components/solvis_control/translations/de.json +++ b/custom_components/solvis_control/translations/de.json @@ -45,13 +45,38 @@ } }, "entity": { + "number": { + "ww_solltemperatur": { + "name": "WW Solltemperatur" + }, + "hkr1_absenktemperatur_nacht": { + "name": "HKR1 Absenktemperatur Nacht" + }, + "hkr1_solltemperatur_tag": { + "name": "HKR1 Solltemperatur Tag" + }, + "raumtemperatur_hkr1": { + "name": "Raumtemperatur HKR1" + } + }, + "select": { + "hkr1_betriebsart": { + "name": "HKR1 Betriebsart", + "state": { + "2": "Automatik", + "3": "Tagbetrieb", + "4": "Absenkbetrieb", + "5": "Standby", + "6": "Eco", + "7": "Urlaub" + + } + } + }, "sensor": { "gas_power": { "name": "Brennerleistung" }, - "solar_water_temp": { - "name": "Wassertemperatur Solar" - }, "outdoor_air_temp": { "name": "Außentemperatur" }, @@ -100,22 +125,22 @@ "ionisation_voltage": { "name": "Ionisationsstrom" }, - "A01_Pumpe_Zirkulation": { + "a01_pumpe_zirkulation": { "name": "A01.Pumpe Zirkulation" }, - "A02_Pumpe_Warmwasser": { + "a02_pumpe_warmwasser": { "name": "A02.Pumpe Warmwasser" }, - "A03_Pumpe_HK1": { + "a03_pumpe_hk1": { "name": "A03.Pumpe HK1" }, - "A05_Pumpe_Zirkulation": { + "a05_pumpe_zirkulation": { "name": "A05.Pumpe Zirkulation" }, - "A12_Brennerstatus": { + "a12_brennerstatus": { "name": "A12.Brennerstatus" }, - "WW_Nachheizung_2322": { + "ww_nachheizung_2322": { "name": "WW Nachheizung 2322" }, "solar_water_flow": { @@ -124,43 +149,23 @@ "domestic_water_flow": { "name": "Durchfluss Warmwasserzirkualation" }, - "HKR1_Betriebsart": { - "name": "HKR1 Betriebsart", - "state": { - "1": "Aus", - "2": "Puls", - "3": "Temp", - "4": "Warten" - } - }, - "HKR1_Absenktemperatur_Nacht": { - "name": "HKR1 Absenktemperatur Nacht" - }, - "HKR1_Solltemperatur_Tag": { - "name": "HKR1 Solltemperatur Tag" - }, - "WW_Solltemperatur": { - "name": "WW Solltemperatur" - }, - "VersionSC2": { + "version_sc2": { "name": "Version SC2" }, - "VersionNBG": { + "version_nbg": { "name": "Version NBG" }, - "Raumtemperatur_HKR1": { - "name": "Raumtemperatur HKR1" - }, - "ZirkulationBetriebsart": { + + "zirkulation_betriebsart": { "name": "Zirkulation Betriebsart", "state": { "1": "Aus", "2": "Puls", - "3": "Temp", - "4": "Warten" + "3": "Zeit", + "4": "Puls/Zeit" } }, - "DigIn_Stoerungen": { + "digin_stoerungen": { "name": "Störungen", "state": { "1": "keine Störung" diff --git a/custom_components/solvis_control/translations/en.json b/custom_components/solvis_control/translations/en.json index a46db5e..2461f5d 100644 --- a/custom_components/solvis_control/translations/en.json +++ b/custom_components/solvis_control/translations/en.json @@ -45,6 +45,34 @@ } }, "entity": { + "number": { + "ww_solltemperatur": { + "name": "WW Solltemperatur" + }, + "hkr1_absenktemperatur_nacht": { + "name": "HKR1 Absenktemperatur Nacht" + }, + "hkr1_solltemperatur_tag": { + "name": "HKR1 Solltemperatur Tag" + }, + "raumtemperatur_hkr1": { + "name": "Raumtemperatur HKR1" + } + }, + "select": { + "hkr1_betriebsart": { + "name": "HKR1 Betriebsart", + "state": { + "2": "Automatik", + "3": "Tagbetrieb", + "4": "Absenkbetrieb", + "5": "Standby", + "6": "Eco", + "7": "Urlaub" + + } + } + }, "sensor": { "gas_power": { "name": "Brennerleistung" @@ -121,40 +149,19 @@ "domestic_water_flow": { "name": "Durchfluss Warmwasserzirkualation" }, - "hkr1_betriebsart": { - "name": "HKR1 Betriebsart", - "state": { - "1": "Aus", - "2": "Puls", - "3": "Temp", - "4": "Warten" - } - }, - "hkr1_absenktemperatur_nacht": { - "name": "HKR1 Absenktemperatur Nacht" - }, - "hkr1_solltemperatur_tag": { - "name": "HKR1 Solltemperatur Tag" - }, - "ww_solltemperatur": { - "name": "WW Solltemperatur" - }, "version_sc2": { "name": "Version SC2" }, "version_nbg": { "name": "Version NBG" }, - "raumtemperatur_hkr1": { - "name": "Raumtemperatur HKR1" - }, "zirkulation_betriebsart": { "name": "Zirkulation Betriebsart", "state": { "1": "Aus", "2": "Puls", - "3": "Temp", - "4": "Warten" + "3": "Zeit", + "4": "Puls/Zeit" } }, "digin_stoerungen": {