Skip to content

Commit

Permalink
- added energy sensors (thanks to @avanc)
Browse files Browse the repository at this point in the history
- some code cleanup
- some name corrections
  • Loading branch information
Altrec committed Feb 3, 2025
1 parent 782971d commit 6fe547a
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 37 deletions.
14 changes: 9 additions & 5 deletions custom_components/remko_mqtt/heatpump.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,16 @@ async def message_received(self, message):
self._hpstate[k] = int(self._hpstate[k], 16) > 0
if reg_id[self._id_reg[k]][1] == "sensor_el":
self._hpstate[k] = int(self._hpstate[k], 16) * 100
if reg_id[self._id_reg[k]][1] == "sensor_en":
self._hpstate[k] = int(self._hpstate[k], 16)
if reg_id[self._id_reg[k]][1] in [
"temperature",
"temperature_input",
"sensor_temp",
"sensor_temp_inp",
]:
raw=int(self._hpstate[k], 16)
self._hpstate[k] = ( -(raw & 0x8000) | (raw & 0x7fff) ) / 10
raw = int(self._hpstate[k], 16)
self._hpstate[k] = (
-(raw & 0x8000) | (raw & 0x7FFF)
) / 10
if reg_id[self._id_reg[k]][1] == "sensor_mode":
mode = f"opmode{int(json_dict[k], 16)}"
self._hpstate[k] = id_names[mode][self._langid]
Expand Down Expand Up @@ -274,7 +278,7 @@ async def send_mqtt_reg(self, register_id, value) -> None:
_LOGGER.error("No MQTT message sent due to unknown register:[%s]", register)
return

if reg_type == "temperature_input":
if reg_type == "sensor_temp_inp":
topic = self._cmd_topic
hex_str = hex(int(value * 10)).upper()
hex_str = hex_str[2:].zfill(4)
Expand Down
7 changes: 3 additions & 4 deletions custom_components/remko_mqtt/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async def async_setup_entry(

for key in reg_id:
if (
reg_id[key][FIELD_REGTYPE] == "temperature_input"
reg_id[key][FIELD_REGTYPE] == "sensor_temp_inp"
and reg_id[key][FIELD_REGNUM] in heatpump._capabilites
):
device_id = key
Expand Down Expand Up @@ -114,8 +114,8 @@ def __init__(
if (
vp_type
in [
"temperature",
"temperature_input",
"sensor_temp",
"sensor_temp_inp",
]
) or (
vp_unit
Expand All @@ -131,7 +131,6 @@ def __init__(
else:
self._unit = None
self._icon = "mdi:gauge"
# "mdi:thermometer" ,"mdi:oil-temperature", "mdi:gauge", "mdi:speedometer", "mdi:alert"
self._min = vp_min
self._max = vp_max
self._step = vp_step
Expand Down
36 changes: 23 additions & 13 deletions custom_components/remko_mqtt/remko_regs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,48 @@
reg_id = {
# reg_id: ['reg#', 'type', 'unit', 'min', 'max'],
"dhw_opmode": ["1079", "select_input", "", 0, 16],
"water_temp_req": ["1082", "temperature_input", "ºC", 20.0, 60.0],
"water_temp_req": ["1082", "sensor_temp_inp", "ºC", 20.0, 60.0],
"absence_mode": ["1893", "switch", "", "", ""],
"party_mode": ["1894", "switch", "", "", ""],
"main_mode": ["1951", "select_input", "", "", ""],
"heating_circ_mode": ["1972", "switch", "", "", ""],
"fixed_temp_req": ["1974", "temperature_input", "ºC", 20.0, 60.0],
"fixed_temp_req": ["1974", "sensor_temp_inp", "ºC", 20.0, 60.0],
"opmode": ["5001", "sensor_mode", "", "", ""],
"circulation_temp": ["5027", "temperature", "ºC", 0, 70],
"out_temp": ["5032", "temperature", "ºC", 0, 40],
"water_temp": ["5039", "temperature", "ºC", 0, 70],
"circulation_temp": ["5027", "sensor_temp", "ºC", "", ""],
"out_temp": ["5032", "sensor_temp", "ºC", "", ""],
"water_temp": ["5039", "sensor_temp", "ºC", "", ""],
"heat_gen_status": ["5051", "binary_sensor", "", "", ""],
"mixed_temp": ["5055", "temperature", "ºC", 0, 40],
"heat_water_temp_req": ["5085", "temperature_input", "ºC", 20.0, 60.0],
"heat_water_temp": ["5131", "temperature", "ºC", 0, 70],
"el_consumption": ["5320", "sensor_el", "W", 0, 6000],
"th_consumption": ["5321", "sensor_el", "W", 0, 20000],
"mixed_temp": ["5055", "sensor_temp", "ºC", "", ""],
"heat_water_temp_req": ["5085", "sensor_temp_inp", "ºC", 20.0, 60.0],
"energy_electric": ["5105", "sensor_en", "kWh", "", ""],
"energy_thermal": ["5119", "sensor_en", "kWh", "", ""],
"buff_temp": ["5131", "sensor_temp", "ºC", "", ""],
"el_consumption": ["5320", "sensor_el", "W", "", ""],
"th_consumption": ["5321", "sensor_el", "W", "", ""],
"energy_heating": ["5374", "sensor_en", "kWh", "", ""],
"energy_DHW_heating": ["5376", "sensor_en", "kWh", "", ""],
"energy_environmental": ["5600", "sensor_en", "kWh", "", ""],
"dhw_heating": ["5693", "action", "", "", ""],
"communication_status": ["communication_status", "generated_sensor", "", 0, 0],
"communication_status": ["communication_status", "generated_sensor", "", "", ""],
}

# Translation dictionary
# ['en', 'de']
id_names = {
"absence_mode": ["Absence mode", "Abwesenheitssmodus"],
"buff_temp": ["Buffer tank temp.", "Pufferspeicher Temp."],
"circulation_temp": ["Circulation temp.", "Zirkulation Temp."],
"dhw_heating": ["1x DHW heating", "1x WW aufheizen"],
"dhw_opmode": ["DHW mode", "WW Modus"],
"el_consumption": ["Electr. power", "Leistung elektrisch"],
"fixed_temp_req": ["fixed value temp.", "Festwert Temp."],
"energy_DHW_heating": ["Energy DHW heating", "Energie Warmwasser"],
"energy_electric": ["Electr. energy heatpump ", "Elektrische Energie"],
"energy_environmental": ["Environmental energy", "Umweltenergie"],
"energy_heating": ["Energy heating", "Energie Heizen"],
"energy_thermal": ["Therm. energy heatpump ", "Thermische Energie"],
"fixed_temp_req": ["Fixed value temp.", "Festwert Temp."],
"heating_circ_mode": ["Heating circuit mode", "Heizkreis Modus"],
"heat_gen_status": ["Heat generator status", "Wärmeerzeuger Status"],
"heat_water_temp": ["Heating water temp.", "Heizwasser Temp."],
"heat_water_temp_req": ["Heating water temp. req.", "Heizwasser soll"],
"main_mode": ["Room climate mode", "Raumklima Modus"],
"mixed_temp": ["Mixed temp.", "Gemischte Temperatur"],
Expand Down
1 change: 0 additions & 1 deletion custom_components/remko_mqtt/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ def __init__(
self._state = None
self._options = vp_options
self._icon = "mdi:gauge"
# "mdi:thermometer" ,"mdi:oil-temperature", "mdi:gauge", "mdi:speedometer", "mdi:alert"

self._entity_picture = None
self._available = True
Expand Down
24 changes: 10 additions & 14 deletions custom_components/remko_mqtt/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ def async_add_sensor(sensor):
if (
reg_id[key][FIELD_REGTYPE]
in [
"temperature",
"sensor",
"sensor_el",
"sensor_en",
"sensor_input",
"sensor_mode",
"sensor_temp",
]
and reg_id[key][FIELD_REGNUM] in heatpump._capabilites
):
Expand Down Expand Up @@ -98,11 +99,15 @@ def __init__(
# self._attr_native_value = state
# self._attr_native_unit_of_measurement = unit_of_measurement
if vp_type not in [
"sensor_en",
"sensor_mode",
"generated_sensor",
]:
self._attr_state_class = SensorStateClass.MEASUREMENT

if vp_type == "sensor_en":
self._attr_state_class = SensorStateClass.TOTAL_INCREASING

# set HA instance attributes directly (mostly don't use property)
self._attr_unique_id = f"{heatpump._domain}_{device_id}"
self.entity_id = f"sensor.{heatpump._domain}_{device_id}"
Expand All @@ -112,27 +117,18 @@ def __init__(
self._name = friendly_name
self._state = None
self._icon = None
if (
vp_type
in [
"temperature",
"temperature_input",
]
) or (
vp_unit
in [
"C",
]
):
if vp_type == "sensor_temp":
self._icon = "mdi:temperature-celsius"
self._unit = UnitOfTemperature.CELSIUS
elif vp_type == "sensor_en":
self._icon = "mdi:lightning-bolt"
self._unit = vp_unit
else:
if vp_unit:
self._unit = vp_unit
else:
self._unit = None
self._icon = "mdi:gauge"
# "mdi:thermometer" ,"mdi:oil-temperature", "mdi:gauge", "mdi:speedometer", "mdi:alert"
self._entity_picture = None
self._available = True

Expand Down

0 comments on commit 6fe547a

Please sign in to comment.