fmartinou / tydom2mqtt

Deltadore Tydom to MQTT Bridge
https://fmartinou.github.io/tydom2mqtt/
MIT License
86 stars 49 forks source link

HVAC missing cool mode #73

Open cmasci31 opened 1 year ago

cmasci31 commented 1 year ago

Hi, i've a hvac (heating, ventilation and air-conditioning system) which works with 3 modes : off, cool, heat. Unfortunatly the tydom2mqtt only reports off/heat modes, cool mode is missing : { "entity_id": "climate.bed_room", "subscriptions": [ { "topic": "climate/tydom/0_0/temperature", "messages": [] }, { "topic": "climate/tydom/0_0/setpoint", "messages": [] }, { "topic": "climate/tydom/0_0/hvacMode", "messages": [] }, { "topic": "climate/tydom/0_0/thermicLevel", "messages": [] } ], "discovery_data": { "topic": "homeassistant/climate/tydom/0_0/config", "payload": { "name": "Bed Room", "temperature_command_topic": "climate/tydom/0_0/set_setpoint", "temperature_state_topic": "climate/tydom/0_0/setpoint", "current_temperature_topic": "climate/tydom/0_0/temperature", "modes": [ "off", "heat" ], "mode_state_topic": "climate/tydom/0_0/hvacMode", "mode_command_topic": "climate/tydom/0_0/set_hvacMode", "preset_modes": [ "STOP", "ANTI_FROST", "ECO", "COMFORT", "AUTO" ], "preset_mode_state_topic": "climate/tydom/0_0/thermicLevel", "preset_mode_command_topic": "climate/tydom/0_0/set_thermicLevel", "unique_id": "0_0", "platform": "mqtt" } }, "transmitted": [] },

gryzzor commented 1 year ago

hi, there is my onw boiler.py file, just modified to integrate the "authorization" label. Now i have Heat, cold, and stop commands.

import json
import logging

logger = logging.getLogger(__name__)
climate_config_topic = "homeassistant/climate/tydom/{id}/config"
sensor_config_topic = "homeassistant/sensor/tydom/{id}/config"
climate_json_attributes_topic = "climate/tydom/{id}/state"

temperature_command_topic = "climate/tydom/{id}/set_setpoint"
temperature_state_topic = "climate/tydom/{id}/setpoint"
current_temperature_topic = "climate/tydom/{id}/temperature"
mode_state_topic = "climate/tydom/{id}/hvacMode"
mode_command_topic = "climate/tydom/{id}/set_hvacMode"
preset_mode_state_topic = "climate/tydom/{id}/authorization"
preset_mode_command_topic = "climate/tydom/{id}/set_authorization"
out_temperature_state_topic = "sensor/tydom/{id}/temperature"

#temperature = current_temperature_topic
#setpoint= temperature_command_topic
# temperature_unit=C
# "modes": ["STOP", "ANTI-FROST","ECO", "COMFORT"],
#####################################
# setpoint (seulement si thermostat)
# temperature (intérieure, seulement si thermostat)
# anticipCoeff 30 (seulement si thermostat)

# thermicLevel STOP ECO ...
# auhorisation HEATING
# hvacMode NORMAL None (si off)
#timeDelay : 0
#tempoOn : False
# antifrost True False
# openingdetected False
# presenceDetected False
# absence False
# LoadSheddingOn False

# outTemperature float
##################################

# climate_json_attributes_topic = "climate/tydom/{id}/state"
# State topic can be the same as the original device attributes topic !

class Boiler:

    def __init__(self, tydom_attributes, tydom_client=None, mqtt=None):

        self.config_topic = None
        self.topic_to_func = None
        self.config = None
        self.device = None
        self.attributes = tydom_attributes
        self.device_id = self.attributes['device_id']
        self.endpoint_id = self.attributes['endpoint_id']
        self.id = self.attributes['id']
        self.name = self.attributes['name']
        self.mqtt = mqtt
        self.tydom_client = tydom_client

    async def setup(self):
        self.config = {}
        self.device = {
            'manufacturer': 'Delta Dore',
            'name': self.name,
            'identifiers': self.id}

        # Check if device is an outer temperature sensor
        if 'outTemperature' in self.attributes:
            self.config['name'] = 'Out Temperature'
            self.device['model'] = 'Sensor'
            self.config['device_class'] = 'temperature'
            self.config['unit_of_measurement'] = 'C'
            self.config_topic = sensor_config_topic.format(id=self.id)
            self.config['state_topic'] = out_temperature_state_topic.format(
                id=self.id)
            self.topic_to_func = {}

        # Check if device is a heater with thermostat sensor
        else:
            self.config['name'] = self.name
            self.device['model'] = 'Climate'
            self.config_topic = climate_config_topic.format(id=self.id)
            self.config['temperature_command_topic'] = temperature_command_topic.format(
                id=self.id)
            self.config['temperature_state_topic'] = temperature_state_topic.format(
                id=self.id)
            self.config['current_temperature_topic'] = current_temperature_topic.format(
                id=self.id)
            self.config['modes'] = ["off", "heat", "cool"]
            self.config['mode_state_topic'] = mode_state_topic.format(
                id=self.id)
            self.config['mode_command_topic'] = mode_command_topic.format(
                id=self.id)
            self.config['preset_modes'] = [
                "STOP", "HEATING", "COOLING"]
            self.config['preset_mode_state_topic'] = preset_mode_state_topic.format(
                id=self.id)
            self.config['preset_mode_command_topic'] = preset_mode_command_topic.format(
                id=self.id)

        self.config['unique_id'] = self.id

        if self.mqtt is not None:
            self.mqtt.mqtt_client.publish(
                self.config_topic, json.dumps(
                    self.config), qos=0, retain=True)

    async def update(self):
        await self.setup()

        if self.mqtt is not None:
            if 'temperature' in self.attributes:
                self.mqtt.mqtt_client.publish(
                    self.config['current_temperature_topic'],
                    '0' if self.attributes['temperature'] == 'None' else self.attributes['temperature'],
                    qos=0, retain=True)
            if 'setpoint' in self.attributes:
                self.mqtt.mqtt_client.publish(
                    self.config['temperature_state_topic'],
                    '10' if self.attributes['setpoint'] == 'None' else self.attributes['setpoint'],
                    qos=0, retain=True)
            if 'authorization' in self.attributes:
                self.mqtt.mqtt_client.publish(
                    self.config['mode_state_topic'],
                    "heat" if self.attributes['authorization'] == "HEATING" else
            "cool" if self.attributes['authorization'] == "COOLING" else
            "off",
                    qos=0, retain=True)
                self.mqtt.mqtt_client.publish(
                    self.config['preset_mode_state_topic'],
                    self.attributes['authorization'],
                    qos=0, retain=True)
            if 'outTemperature' in self.attributes:
                self.mqtt.mqtt_client.publish(
                    self.config['state_topic'],
                    self.attributes['outTemperature'],
                    qos=0, retain=True)

    @staticmethod
    async def put_temperature(tydom_client, device_id, boiler_id, set_setpoint):
        logger.info("%s %s %s", boiler_id, 'set_setpoint', set_setpoint)
        if not (set_setpoint == ''):
            await tydom_client.put_devices_data(device_id, boiler_id, 'setpoint', set_setpoint)

    @staticmethod
    async def put_hvac_mode(tydom_client, device_id, boiler_id, set_hvac_mode):
        logger.info("%s %s %s", boiler_id, 'set_hvacMode', set_hvac_mode)
        if set_hvac_mode == 'heat':
            await tydom_client.put_devices_data(device_id, boiler_id, 'authorization', 'HEATING')
        if set_hvac_mode == 'cool':
            await tydom_client.put_devices_data(device_id, boiler_id, 'authorization', 'COOLING')
        else:
            await tydom_client.put_devices_data(device_id, boiler_id, 'setpoint', '00')
            await tydom_client.put_devices_data(device_id, boiler_id, 'thermicLevel', '00')
            await tydom_client.put_devices_data(device_id, boiler_id, 'authorization', 'STOP')           
        #   await tydom_client.put_devices_data(device_id, boiler_id, 'setpoint', '10')

    @staticmethod
    async def put_thermic_level(tydom_client, device_id, boiler_id, set_thermic_level):
        if not (set_thermic_level == ''):
            logger.info("Set thermic level (device=%s, level=%s)", device_id, set_thermic_level)
            await tydom_client.put_devices_data(device_id, boiler_id, 'thermicLevel', set_thermic_level)
cmasci31 commented 1 year ago

thx it works! do you know how to tell an hvac apart from a boiler from a tydom point of view? (asking @fmartinou too ;) ) the idea would be to add your file as an hvac.py new module to keep the compatibility with the two equipments...

makinapower commented 1 year ago

@fmartinou thank you for this superb tydom integration for home assistant, and thanks @gryzzor for the solution. I agree with cmasci31, it would be great to have hvac managment as well as boiler.

gryzzor commented 11 months ago

I'm sorry but i'm not have much time for this. But the holidays approach and i think i could have time to see the code and apport the modifications. We need to make changes to the code, especially on the precise detection of devices. I also have NOUS brand electrical outlets that are not detected. I'll see what I can do. But again as soon as I have time.

Bonjour, Je n'ai pas trop le temps en ce moment, mais les vaccances approchent et je pense que j'aurais du temps pour étudier le code. Il faudra par contre modifier la détection des appareils pour savoir exactement qu'elle est sa fonction. D'autre part j'ai des prises NOUS qui ne sont pas prises en compte par le plugin. Je vais regarder cela mais dés que j'ai le temps. A bientôt !!

makinapower commented 6 months ago

I'm sorry but i'm not have much time for this. But the holidays approach and i think i could have time to see the code and apport the modifications. We need to make changes to the code, especially on the precise detection of devices. I also have NOUS brand electrical outlets that are not detected. I'll see what I can do. But again as soon as I have time.

Bonjour, Je n'ai pas trop le temps en ce moment, mais les vaccances approchent et je pense que j'aurais du temps pour étudier le code. Il faudra par contre modifier la détection des appareils pour savoir exactement qu'elle est sa fonction. D'autre part j'ai des prises NOUS qui ne sont pas prises en compte par le plugin. Je vais regarder cela mais dés que j'ai le temps. A bientôt !!

Hi gryzzor, and Happy new year, any chance to have a version which take into account HVAC with cool mode ? thanks in advance :)