Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Climate Thermostat #3

Open
sofa17 opened this issue Dec 21, 2022 · 0 comments
Open

Climate Thermostat #3

sofa17 opened this issue Dec 21, 2022 · 0 comments

Comments

@sofa17
Copy link

sofa17 commented Dec 21, 2022

Good afternoon,
Thank you for your incredible work zaubererty.
I implemented the climate home assistant thermostat, I know it needs some adjustments, but it is working, with my salamander lasian audax 8Kw.
This entity can turn on and off;
See the state of the stove, in the modes;
You can select 4 powers of ventilation:

  • auto equal to 7;
  • low equal to 1;
  • medium equal to 3;
  • high equal to 5.
    Which I use in the combustion power.
    Also select the temperature, without having to use automations

Create file "climate.py"

`"""The 4Heat integration."""

import logging
from homeassistant.helpers.update_coordinator import CoordinatorEntity

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
ATTR_TEMPERATURE,
PRECISION_TENTHS,
PRECISION_WHOLE,
SERVICE_TURN_OFF,
SERVICE_TURN_ON,
STATE_OFF,
STATE_ON,
TEMP_CELSIUS,
CONF_MONITORED_CONDITIONS,
)
from homeassistant.core import HomeAssistant, ServiceCall
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.config_validation import ( # noqa: F401
PLATFORM_SCHEMA,
PLATFORM_SCHEMA_BASE,
make_entity_service_schema,
)
from homeassistant.helpers.entity import Entity, EntityDescription
from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.temperature import display_temp as show_temp

import voluptuous as vol
from homeassistant.components.climate import (
ClimateEntity,
ClimateEntityFeature,
ENTITY_ID_FORMAT,
)
from homeassistant.components.climate.const import (
DEFAULT_MAX_TEMP,
DEFAULT_MIN_TEMP,
ATTR_HVAC_MODE,
ATTR_FAN_MODE,
ATTR_SWING_MODE,
ATTR_CURRENT_TEMPERATURE,
ATTR_CURRENT_HUMIDITY,
FAN_AUTO,
FAN_LOW,
FAN_MEDIUM,
FAN_HIGH,
ATTR_TARGET_TEMP_HIGH,
ATTR_TARGET_TEMP_LOW,
HVACMode,
HVACAction,
)

from homeassistant.const import (
STATE_ON,
PRECISION_HALVES,
PRECISION_TENTHS,
PRECISION_WHOLE,
ATTR_TEMPERATURE,
CONF_NAME,
STATE_UNKNOWN,
STATE_UNAVAILABLE,
CONF_ICON_TEMPLATE,
CONF_ENTITY_PICTURE_TEMPLATE,
CONF_UNIQUE_ID,
)

from homeassistant.helpers.script import Script

from .const import (
MODE_NAMES, SENSOR_TYPES, DOMAIN, DATA_COORDINATOR, MODE_TYPE, ERROR_TYPE, CLIMATE_MODE, ERROR_NAMES
)
from .coordinator import FourHeatDataUpdateCoordinator

_LOGGER = logging.getLogger(name)

async def async_setup_entry(hass, entry, async_add_entities):
"""Add an FourHeat entry."""
coordinator: FourHeatDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id][
DATA_COORDINATOR
]
entities = []

try:
    entities.append(FourHeatClimate(coordinator, coordinator.climate_mode, entry.title, entry))
except:
    _LOGGER.debug(f"Error adding climate")

async_add_entities(entities)

class FourHeatClimate(CoordinatorEntity, ClimateEntity):
"""Representation of a 4Heat device."""

def __init__(self, coordinator, sensor_type, name, entry):
    """Initialize the sensor."""
    super().__init__(coordinator)
    self._sensor = "climate"
    self._name = name
    self.type = "climate"
    self.coordinator = coordinator
    self._last_value = None
    self.serial_number = coordinator.serial_number
    self.model = coordinator.model
    self.sensor_type = sensor_type
    self.entry = entry
    self.sensorIds = entry.data[CONF_MONITORED_CONDITIONS]

    self._attr_min_temp = 16
    self._attr_max_temp = 25
    self._attr_target_temperature_step = 1.0  # default optimistic state
    #self._current_operation = HVACMode.HEAT  # default optimistic state
    self._attr_fan_mode = "home"

    self._available = True
    self._unit_of_measurement = TEMP_CELSIUS
    self._attr_supported_features = 25

    self._attr_hvac_modes = [
            HVACMode.OFF,
            HVACMode.HEAT,
            HVACMode.AUTO,
        ]
    self._attr_fan_modes = [FAN_AUTO, FAN_LOW, FAN_MEDIUM, FAN_HIGH, ]
    self._attr_preset_modes = ["none", "eco", "away", "boost", "comfort", "home", "sleep", "activity", ]

    _LOGGER.debug(self.coordinator)

@property
def state(self):
    """Return the current state."""
    aux = HVACMode.HEAT
    ids=CLIMATE_MODE['State'][0]
    if f"{self.coordinator.data[ids][0]}"=="0":
        aux =  HVACMode.OFF
    elif f"{self.coordinator.data[ids][0]}"=="11":
        aux = HVACMode.AUTO
    return aux

@property
def name(self):
    """Return the name of the sensor."""
    return f"{self._name} {self._sensor}"

@property
def unique_id(self):
    """Return unique id based on device serial and variable."""
    return f"{self._name}_{self.type}"

@property
def precision(self):
    """Return the precision of the system."""
    return 1

@property
def temperature_unit(self):
    """Return the unit of measurement."""
    return self._unit_of_measurement

@property
def target_temperature_step(self):
    """Return the supported step of target temperature."""
    return 1

@property
def hvac_mode(self):
    """Return current operation ie. heat, cool, idle."""
    return self._current_operation

@property
def fan_modes(self):
    """Return current operation ie. heat, cool, idle."""
    return self._attr_fan_modes

@property
def preset_modes(self):
    """Return current operation ie. heat, cool, idle."""
    aux=[]
    for ids in MODE_NAMES:
        if ids < 30 and ids!=4:
            aux.append(MODE_NAMES[ids])
    return aux

@property
def state_attributes(self):
    aux= {}
    for sensorId in self.sensorIds:
        if len(sensorId) > 5:
            try:
                sId = sensorId[1:6]
                if SENSOR_TYPES[sId][0] == "Room temperature":
                    aux["current_temperature"]=f"{self.coordinator.data[sId][0]}"
                elif SENSOR_TYPES[sId][0] == "Room termostat":
                    aux["temperature"]=f"{self.coordinator.data[sId][0]}"
                elif SENSOR_TYPES[sId][0] == "Combustion power":
                    if f"{self.coordinator.data[sId][0]}" == "1" or f"{self.coordinator.data[sId][0]}" == "2":
                         aux["fan_mode"]="low"
                    elif f"{self.coordinator.data[sId][0]}" == "3" or f"{self.coordinator.data[sId][0]}" == "4":
                         aux["fan_mode"]="medium"
                    elif f"{self.coordinator.data[sId][0]}" == "5" or f"{self.coordinator.data[sId][0]}" == "6":
                         aux["fan_mode"]="high"
                    elif f"{self.coordinator.data[sId][0]}" == "7":
                         aux["fan_mode"]="auto"
                elif SENSOR_TYPES[sId][0] == "State":
                    aux["preset_mode"]=f"{MODE_NAMES[self.coordinator.data[sId][0]]}" 
                elif SENSOR_TYPES[sId][0] == "Exhaust temperature":
                    aux["temperatura fumos"]=f"{self.coordinator.data[sId][0]}"
                elif SENSOR_TYPES[sId][0] == "Error":
                    aux["error code"]=f"{self.coordinator.data[sId][0]}"
                    aux["error"]=f"{ERROR_NAMES[self.coordinator.data[sId][0]]}"
                elif SENSOR_TYPES[sId][0] == "UN 30026":
                    aux["fluxo de ar"]=f"{self.coordinator.data[sId][0]}"
            except:
                abc=0
    return aux

async def set_hvac_mode(self, hvac_mode):
    """Set new target hvac mode."""
    if hvac_mode == HVACMode.OFF:
        await self.coordinator.async_turn_off()
    else:
        await self.coordinator.async_turn_on()

async def async_set_temperature(self, **kwargs):
    """Set new target temperature."""
    temperature = round(kwargs[ATTR_TEMPERATURE] / self._attr_target_temperature_step)
    await self.coordinator.async_set_value(CLIMATE_MODE["Termostate"][0], temperature)

async def async_set_fan_mode(self, fan_mode):
    """Set new target fan mode."""
    aux=0
    if fan_mode == "low":
        aux=1
    elif fan_mode == "medium":
        aux=3
    elif fan_mode == "high":
        aux=5
    elif fan_mode == "auto":
        aux=7
    await self.coordinator.async_set_value(CLIMATE_MODE["Combustao"][0], aux)`

added in the file "const.py"

CLIMATE_MODE = { "State": ["30001", None, ""], "Temperature": ["30006", TEMP_CELSIUS, ""], "Termostate": ["21700", TEMP_CELSIUS, ""], "Combustao": ["20816", TEMP_CELSIUS, ""], }

added in the file "init.py", "def async_setup_entry", before the return True

hass.async_create_task( hass.config_entries.async_forward_entry_setup(entry, "climate") )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant