Skip to content

Commit 56ba37a

Browse files
committed
1 parent 9b16a87 commit 56ba37a

File tree

4 files changed

+76
-1
lines changed

4 files changed

+76
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ services:
158158

159159
### MQTT Topics
160160

161-
When started, the service will connect to the LIN bus and publish any status updates acquired from there. When you send a command to modify a setting (e.g., to turn on the heating), the service will send the command to the LIN bus and publish the new status once the setting has been confirmed.
161+
When started, the service will connect to the LIN bus and publish any status updates acquired from there. When you send a command to modify a setting (e.g., to turn on the heating), the service will send the command to the LIN bus and publish the new status once the setting has been confirmed.
162+
Also on startup, the service will send auto discovery messages for home assistant, which can be used with the `truma.yaml` and `truma.ll` from https://github.com/mc0110/inetbox2mqtt/tree/4880ceb2e7c2cef8fbaaed29d5489c2c9d7603b5/doc.
162163

163164
#### MQTT topics for receiving status
164165

inetbox/haconfig/__init__.py

Whitespace-only changes.

inetbox/haconfig/haconfig.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
from inetbox.truma_service import TrumaService
2+
3+
# taken from https://github.com/mc0110/inetbox2mqtt/blob/02fe46d5580c5325a71b8abd299130c9802581ad/src/main.py:
4+
rel_no = "2.6.5"
5+
6+
# taken from https://github.com/mc0110/inetbox2mqtt/blob/6d9241d90906d3619b7ae39a729453872a695e64/src/main1.py:
7+
8+
topic_root = TrumaService.SERVICE_NAME
9+
Pub_Prefix = 'service/' + topic_root + '/control_status/'
10+
11+
# Auto-discovery-function of home-assistant (HA)
12+
HA_MODEL = 'inetbox'
13+
HA_SWV = 'V03'
14+
HA_STOPIC = 'service/' + topic_root + '/control_status/'
15+
HA_CTOPIC = 'service/' + topic_root + '/set/'
16+
17+
HA_CONFIG = {
18+
"alive": ['homeassistant/binary_sensor/' + topic_root + '/alive/config', '{"name": "' + topic_root + '_alive", "model": "' + HA_MODEL + '", "sw_version": "' + HA_SWV + '", "device_class": "running", "state_topic": "' + HA_STOPIC + 'alive"}'],
19+
"release": ['homeassistant/sensor/release/config', '{"name": "' + topic_root + '_release", "model": "' + HA_MODEL + '", "sw_version":"' + HA_SWV + '", "state_topic": "' + HA_STOPIC + 'release"}'],
20+
"current_temp_room": ['homeassistant/sensor/current_temp_room/config', '{"name": "' + topic_root + '_current_temp_room", "model": "' + HA_MODEL + '", "sw_version":"' + HA_SWV + '", "device_class": "temperature", "unit_of_measurement": "°C", "state_topic": "' + HA_STOPIC + 'current_temp_room"}'],
21+
"current_temp_water": ['homeassistant/sensor/current_temp_water/config', '{"name": "' + topic_root + '_current_temp_water", "model": "' + HA_MODEL + '", "sw_version":"' + HA_SWV + '", "device_class": "temperature", "unit_of_measurement": "°C", "state_topic": "' + HA_STOPIC + 'current_temp_water"}'],
22+
"target_temp_room": ['homeassistant/sensor/target_temp_room/config', '{"name": "' + topic_root + '_target_temp_room", "model": "' + HA_MODEL + '", "sw_version":"' + HA_SWV + '", "device_class": "temperature", "unit_of_measurement": "°C", "state_topic": "' + HA_STOPIC + 'target_temp_room"}'],
23+
"target_temp_aircon": ['homeassistant/sensor/target_temp_aircon/config', '{"name": "' + topic_root + '_target_temp_aircon", "model": "' + HA_MODEL + '", "sw_version":"' + HA_SWV + '", "device_class": "temperature", "unit_of_measurement": "°C", "state_topic": "' + HA_STOPIC + 'target_temp_aircon"}'],
24+
"target_temp_water": ['homeassistant/sensor/target_temp_water/config', '{"name": "' + topic_root + '_target_temp_water", "model": "' + HA_MODEL + '", "sw_version":"' + HA_SWV + '", "device_class": "temperature", "unit_of_measurement": "°C", "state_topic": "' + HA_STOPIC + 'target_temp_water"}'],
25+
"energy_mix": ['homeassistant/sensor/energy_mix/config', '{"name": "' + topic_root + '_energy_mix", "model": "' + HA_MODEL + '", "sw_version":"' + HA_SWV + '", "state_topic": "' + HA_STOPIC + 'energy_mix"}'],
26+
"el_power_level": ['homeassistant/sensor/el_level/config', '{"name": "' + topic_root + '_el_power_level", "model": "' + HA_MODEL + '", "sw_version":"' + HA_SWV + '", "state_topic": "' + HA_STOPIC + 'el_power_level"}'],
27+
"heating_mode": ['homeassistant/sensor/heating_mode/config', '{"name": "' + topic_root + '_heating_mode", "model": "' + HA_MODEL + '", "sw_version":"' + HA_SWV + '", "state_topic": "' + HA_STOPIC + 'heating_mode"}'],
28+
"operating_status": ['homeassistant/sensor/operating_status/config', '{"name": "' + topic_root + '_operating_status", "model": "' + HA_MODEL + '", "sw_version":"' + HA_SWV + '", "state_topic": "' + HA_STOPIC + 'operating_status"}'],
29+
"aircon_operating_mode": ['homeassistant/sensor/aircon_operating_mode/config', '{"name": "' + topic_root + '_aircon_operating_mode", "model": "' + HA_MODEL + '", "sw_version":"' + HA_SWV + '", "state_topic": "' + HA_STOPIC + 'aircon_operating_mode"}'],
30+
"aircon_vent_mode": ['homeassistant/sensor/aircon_vent_mode/config', '{"name": "' + topic_root + '_aircon_vent_mode", "model": "' + HA_MODEL + '", "sw_version":"' + HA_SWV + '", "state_topic": "' + HA_STOPIC + 'aircon_vent_mode"}'],
31+
"operating_status": ['homeassistant/sensor/operating_status/config', '{"name": "' + topic_root + '_operating_status", "model": "' + HA_MODEL + '", "sw_version":"' + HA_SWV + '", "state_topic": "' + HA_STOPIC + 'operating_status"}'],
32+
"error_code": ['homeassistant/sensor/error_code/config', '{"name": "' + topic_root + '_error_code", "model": "' + HA_MODEL + '", "sw_version":"' + HA_SWV + '", "state_topic": "' + HA_STOPIC + 'error_code"}'],
33+
"clock": ['homeassistant/sensor/clock/config', '{"name": "' + topic_root + '_clock", "model": "' + HA_MODEL + '", "sw_version":"' + HA_SWV + '", "state_topic": "' + HA_STOPIC + 'clock"}'],
34+
"set_target_temp_room": ['homeassistant/select/target_temp_room/config', '{"name": "' + topic_root + '_set_roomtemp", "model": "' + HA_MODEL + '", "sw_version":"' + HA_SWV + '", "command_topic": "' + HA_CTOPIC + 'target_temp_room", "options": ["0", "10", "15", "18", "20", "21", "22"] }'],
35+
"set_target_temp_aircon":['homeassistant/select/target_temp_aircon/config', '{"name": "' + topic_root + '_set_aircontemp", "model": "' + HA_MODEL + '", "sw_version":"' + HA_SWV + '", "command_topic": "' + HA_CTOPIC + 'target_temp_aircon", "options": ["16", "18", "20", "22", "24", "26", "28"] }'],
36+
"set_target_temp_water": ['homeassistant/select/target_temp_water/config', '{"name": "' + topic_root + '_set_warmwater", "model": "' + HA_MODEL + '", "sw_version":"' + HA_SWV + '", "command_topic": "' + HA_CTOPIC + 'target_temp_water", "options": ["0", "40", "60", "200"] }'],
37+
"set_heating_mode": ['homeassistant/select/heating_mode/config', '{"name": "' + topic_root + '_set_heating_mode", "model": "' + HA_MODEL + '", "sw_version":"' + HA_SWV + '", "command_topic": "' + HA_CTOPIC + 'heating_mode", "options": ["off", "eco", "high"] }'],
38+
"set_aircon_mode": ['homeassistant/select/aircon_mode/config', '{"name": "' + topic_root + '_set_aircon_mode", "model": "' + HA_MODEL + '", "sw_version":"' + HA_SWV + '", "command_topic": "' + HA_CTOPIC + 'aircon_operating_mode", "options": ["off", "vent", "cool", "hot", "auto"] }'],
39+
"set_vent_mode": ['homeassistant/select/vent_mode/config', '{"name": "' + topic_root + '_set_vent_mode", "model": "' + HA_MODEL + '", "sw_version":"' + HA_SWV + '", "command_topic": "' + HA_CTOPIC + 'aircon_vent_mode", "options": ["low", "mid", "high", "night", "auto"] }'],
40+
"set_energy_mix": ['homeassistant/select/energy_mix/config', '{"name": "' + topic_root + '_set_energy_mix", "model": "' + HA_MODEL + '", "sw_version":"' + HA_SWV + '", "command_topic": "' + HA_CTOPIC + 'energy_mix", "options": ["none", "gas", "electricity", "mix"] }'],
41+
"set_el_power_level": ['homeassistant/select/el_power_level/config', '{"name": "' + topic_root + '_set_el_power_level", "model": "' + HA_MODEL + '", "sw_version":"' + HA_SWV + '", "command_topic": "' + HA_CTOPIC + 'el_power_level", "options": ["0", "900", "1800"] }'],
42+
"set_reboot": ['homeassistant/select/set_reboot/config', '{"name": "' + topic_root + '_set_reboot", "model": "' + HA_MODEL + '", "sw_version":"' + HA_SWV + '", "command_topic": "' + HA_CTOPIC + 'reboot", "options": ["0", "1"] }'],
43+
"set_os_run": ['homeassistant/select/set_os_run/config', '{"name": "' + topic_root + '_set_os_run", "model": "' + HA_MODEL + '", "sw_version":"' + HA_SWV + '", "command_topic": "' + HA_CTOPIC + 'os_run", "options": ["0", "1"] }'],
44+
"ota_update": ['homeassistant/select/ota_update/config', '{"name": "' + topic_root + '_ota_update", "model": "' + HA_MODEL + '", "sw_version":"' + HA_SWV + '", "command_topic": "' + HA_CTOPIC + 'ota_update", "options": ["0", "1"] }'],
45+
}
46+
47+
def del_ha_autoconfig(c):
48+
for i in HA_CONFIG.keys():
49+
try:
50+
c.publish(HA_CONFIG[i][0], "{}", qos=1, global_=True, only_if_changed=False)
51+
except:
52+
c.log.debug("Publishing error in del_ha_autoconfig")
53+
c.log.info("del ha_autoconfig completed")
54+
55+
# HA auto discovery: define all auto config entities
56+
def set_ha_autoconfig(c):
57+
for i in HA_CONFIG.keys():
58+
try:
59+
c.publish(HA_CONFIG[i][0], HA_CONFIG[i][1], qos=1, global_=True, only_if_changed=False)
60+
except:
61+
c.log.debug("Publishing error in set_ha_autoconfig")
62+
c.publish(Pub_Prefix + "release", rel_no, retain=True, qos=1, global_=True, only_if_changed=False)
63+
c.log.info("set ha_autoconfig completed")

inetbox/truma_service.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ def __init__(self, *args, **kwargs):
5454
self.log.info(f"Opening serial device {serial_device} in exclusive mode")
5555
self.serial = Serial(serial_device, baudrate, timeout=timeout, exclusive=True)
5656
self.lin = Lin(self.inetprotocol, debug_lin)
57+
58+
def _on_connect(self, *args, **kwargs):
59+
super()._on_connect(*args, **kwargs)
60+
61+
try:
62+
self.log.info(f"Trying to send home assistant discovery messages...")
63+
from .haconfig import haconfig
64+
haconfig.del_ha_autoconfig(self)
65+
haconfig.set_ha_autoconfig(self)
66+
except ImportError:
67+
self.log.warning(f"no module `haconfig` for discovery message to home assistant loaded")
5768

5869
def _loop_step(self):
5970
assert self.LOOPS is not None

0 commit comments

Comments
 (0)