Skip to content

Commit

Permalink
Added more elements and option to change heating mode
Browse files Browse the repository at this point in the history
  • Loading branch information
LarsK1 committed Apr 1, 2024
1 parent 9fe928c commit 12bba87
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 120 deletions.
12 changes: 10 additions & 2 deletions custom_components/solvis_control/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Modul to integrate solvis heaters to.
Version: 0.2.0-alpha
Version: 0.3.0-beta
"""

"""Solvis integration."""
Expand All @@ -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:
Expand All @@ -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
24 changes: 18 additions & 6 deletions custom_components/solvis_control/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -137,6 +139,7 @@ class ModbusFieldConfig:
unit="h",
device_class="time",
state_class="measurement",
entity_category="diagnostic",
),
ModbusFieldConfig( # Brennerstarts
name="number_gas_burner_start",
Expand All @@ -146,6 +149,7 @@ class ModbusFieldConfig:
state_class="measurement",
negative=True,
multiplier=1,
entity_category="diagnostic",
),
ModbusFieldConfig( # Ionisationsstrom
name="ionisation_voltage",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
),
Expand All @@ -271,7 +281,7 @@ class ModbusFieldConfig:
address=32771,
unit="",
device_class=None,
state_class="measurement",
state_class=None,
multiplier=1,
entity_category="diagnostic",
),
Expand All @@ -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),
),
]
8 changes: 4 additions & 4 deletions custom_components/solvis_control/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -41,19 +41,19 @@ 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:
for register in REGISTERS:
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:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/solvis_control/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
29 changes: 4 additions & 25 deletions custom_components/solvis_control/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 %}"
54 changes: 31 additions & 23 deletions custom_components/solvis_control/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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": {
Expand Down
Loading

0 comments on commit 12bba87

Please sign in to comment.