├── .DS_Store ├── .github └── workflows │ ├── hassfest.yaml │ └── validate.yml ├── LICENSE ├── README.md ├── custom_components └── ecostream │ ├── __init__.py │ ├── button.py │ ├── climate.py │ ├── config_flow.py │ ├── const.py │ ├── fan.py │ ├── icons.json │ ├── manifest.json │ ├── sensor.py │ ├── strings.json │ ├── switch.py │ ├── translations │ └── en.json │ └── valve.py └── hacs.json /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/epodegrid/ecostream_homeassistant_integration/745d36ae474c3daf7b98f391fbdb72a256b81d80/.DS_Store -------------------------------------------------------------------------------- /.github/workflows/hassfest.yaml: -------------------------------------------------------------------------------- 1 | name: Validate with hassfest 2 | 3 | on: 4 | push: 5 | pull_request: 6 | schedule: 7 | - cron: "0 0 * * *" 8 | 9 | jobs: 10 | validate: 11 | runs-on: "ubuntu-latest" 12 | steps: 13 | - uses: "actions/checkout@v3" 14 | - uses: home-assistant/actions/hassfest@master 15 | -------------------------------------------------------------------------------- /.github/workflows/validate.yml: -------------------------------------------------------------------------------- 1 | name: Validate 2 | 3 | on: 4 | push: 5 | pull_request: 6 | schedule: 7 | - cron: "0 0 * * *" 8 | workflow_dispatch: 9 | 10 | jobs: 11 | validate-hacs: 12 | runs-on: "ubuntu-latest" 13 | steps: 14 | - uses: "actions/checkout@v3" 15 | - name: HACS validation 16 | uses: "hacs/action@main" 17 | with: 18 | category: "integration" 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Debashis Panda 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Buva Ecostream Home Assistant Integration 2 | 3 | This integration allows you to control your Buva Ecostream HRV unit, from Home Assistant. It connects to your local unit, 4 | using Python WebSockets. 5 | 6 | More controls are to be added later. 7 | 8 | ## Disclaimer 9 | 10 | This project is not affiliated with or endorsed by Buva. 11 | 12 | ## Installation via HACS: 13 | 14 | #### Add the repository as a custom repository 15 | [![Open your Home Assistant instance and open a repository inside the Home Assistant Community Store.](https://my.home-assistant.io/badges/hacs_repository.svg)](https://my.home-assistant.io/redirect/hacs_repository/?owner=epodegrid&repository=ecostream_homeassistant_integration&category=integration) 16 | 17 | #### Start configuration 18 | [![Open your Home Assistant instance and start setting up a new integration.](https://my.home-assistant.io/badges/config_flow_start.svg)](https://my.home-assistant.io/redirect/config_flow_start/?domain=ecostream) 19 | 20 | ## Installation (Manual) 21 | 1. Copy the ecostream folder to custom_components in Home Assistant. 22 | 2. Add the integration in Home Assistant, by configuring your Ecostream IP address 23 | 24 | ## Notice 25 | 26 | The use of this Project is subject to the following terms: 27 | 28 | - The project is provided on an "as-is" basis, without any warranties or conditions, express or implied. 29 | - The user of the project assumes all responsibility and risk for its use. 30 | - The project contributors disclaim all liability for any damages, direct or indirect, resulting from the use of the project. 31 | -------------------------------------------------------------------------------- /custom_components/ecostream/__init__.py: -------------------------------------------------------------------------------- 1 | """The ecostream integration.""" 2 | 3 | from __future__ import annotations 4 | 5 | import asyncio 6 | from datetime import timedelta 7 | import json 8 | import logging 9 | import websockets # type: ignore 10 | 11 | from homeassistant.config_entries import ConfigEntry # type: ignore 12 | from homeassistant.const import CONF_HOST, Platform # type: ignore 13 | from homeassistant.core import HomeAssistant 14 | from homeassistant.helpers.update_coordinator import DataUpdateCoordinator # type: ignore 15 | 16 | from .const import DOMAIN 17 | 18 | _LOGGER = logging.getLogger(__name__) 19 | 20 | PLATFORMS: list[Platform] = [ 21 | Platform.SENSOR, 22 | Platform.FAN, 23 | Platform.BUTTON, 24 | Platform.CLIMATE, 25 | Platform.VALVE, 26 | Platform.SWITCH, 27 | ] 28 | 29 | class EcostreamWebsocketsAPI: 30 | """Class representing the EcostreamWebsocketsAPI.""" 31 | 32 | def __init__(self) -> None: 33 | """Initialize the EcostreamWebsocketsAPI class.""" 34 | self.connection = None 35 | self._data = {} 36 | self._host = None 37 | self._update_interval = 60 # Update interval in seconds 38 | self._update_task = None 39 | self._device_name = None 40 | 41 | async def connect(self, host): 42 | """Connect to the specified host.""" 43 | _LOGGER.debug("Connecting to %s", host) 44 | self._host = host 45 | self.connection = await websockets.connect(f"ws://{host}") 46 | 47 | await self._update_data() 48 | self._device_name = self._data["system"]["system_name"] 49 | 50 | async def reconnect(self): 51 | """Reconnect to the websocket.""" 52 | _LOGGER.debug("Reconnecting to %s", self._host) 53 | self.connection = await websockets.connect(f"ws://{self._host}") 54 | 55 | async def get_data(self): 56 | """Get the data from the API.""" 57 | await self._update_data() 58 | return self._data 59 | 60 | async def _update_data(self): 61 | """Update data by receiving from the WebSocket.""" 62 | try: 63 | response = await self.connection.recv() 64 | parsed_response = json.loads(response) 65 | 66 | # The Ecostream sents various kinds of responses and does not always 67 | # include all values. Keep the values for the missing keys and update 68 | # the ones that are returned by the ecostream. 69 | for key in ["comm_wifi", "system", "config", "status"]: 70 | self._data[key] = self._data.get(key, {}) | parsed_response.get(key, {}) 71 | except websockets.ConnectionClosed: 72 | _LOGGER.error("Connection closed unexpectedly.") 73 | await self.reconnect() 74 | except Exception as e: 75 | _LOGGER.error("Error receiving data: %s", e) 76 | 77 | async def send_json(self, payload: dict): 78 | """Send a JSON payload through the WebSocket connection.""" 79 | try: 80 | await self.connection.send(json.dumps(payload)) 81 | except websockets.ConnectionClosed: 82 | _LOGGER.error("Connection closed. Reconnecting...") 83 | await self.reconnect() 84 | await self.connection.send(json.dumps(payload)) # Resend after reconnecting 85 | except Exception as e: 86 | _LOGGER.error("Failed to send data: %s", e) 87 | 88 | class EcostreamDataUpdateCoordinator(DataUpdateCoordinator): 89 | """Class to manage fetching data from the API.""" 90 | 91 | def __init__(self, hass: HomeAssistant, api: EcostreamWebsocketsAPI): 92 | """Initialize.""" 93 | self.api = api 94 | super().__init__( 95 | hass, 96 | _LOGGER, 97 | name=DOMAIN, 98 | update_interval=timedelta(seconds=30) # Refresh interval in seconds 99 | ) 100 | 101 | async def _async_update_data(self): 102 | """Fetch data from the API.""" 103 | return await self.api.get_data() 104 | 105 | async def send_json(self, payload: dict): 106 | await self.api.send_json(payload) 107 | 108 | # Immediately refresh the data such that the direct response is persisted 109 | await self.async_refresh() 110 | 111 | # In addition, schedule a delayed update such that actions that take a some 112 | # time to be completed (e.g. opening / closing the bypass valve) will be 113 | # updated soon and don't have to wait the polling interval to be updated. 114 | await self.async_request_refresh() 115 | 116 | async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: 117 | """Set up ecostream from a config entry.""" 118 | hass.data.setdefault(DOMAIN, {}) 119 | 120 | api = EcostreamWebsocketsAPI() 121 | await api.connect(entry.data[CONF_HOST]) 122 | 123 | hass.data[DOMAIN][entry.entry_id] = api 124 | hass.data[DOMAIN]["ws_client"] = api 125 | 126 | coordinator = EcostreamDataUpdateCoordinator(hass, api) 127 | await coordinator.async_config_entry_first_refresh() 128 | 129 | entry.runtime_data = coordinator 130 | 131 | await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) 132 | 133 | return True 134 | 135 | async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: 136 | """Unload an ecostream config entry.""" 137 | api = hass.data[DOMAIN].pop(entry.entry_id) 138 | if api._update_task: 139 | api._update_task.cancel() 140 | 141 | return await hass.config_entries.async_unload_platforms(entry, PLATFORMS) 142 | -------------------------------------------------------------------------------- /custom_components/ecostream/button.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | from dateutil.relativedelta import relativedelta 3 | from homeassistant.util import dt 4 | 5 | from homeassistant.components.button import ButtonEntity 6 | from homeassistant.helpers.entity import DeviceInfo 7 | from homeassistant.config_entries import ConfigEntry # type: ignore 8 | from homeassistant.core import HomeAssistant # type: ignore 9 | from homeassistant.helpers.entity_platform import AddEntitiesCallback 10 | from homeassistant.helpers.update_coordinator import CoordinatorEntity # type: ignore 11 | from homeassistant.const import UnitOfTime # type: ignore 12 | 13 | from . import EcostreamDataUpdateCoordinator, EcostreamWebsocketsAPI 14 | from .const import DOMAIN 15 | 16 | async def async_setup_entry( 17 | hass: HomeAssistant, 18 | entry: ConfigEntry[EcostreamDataUpdateCoordinator], 19 | async_add_entities: AddEntitiesCallback, 20 | ) -> None: 21 | """Set up the button platform.""" 22 | coordinator = entry.runtime_data 23 | 24 | buttons = [ 25 | FilterResetButton(coordinator, entry) 26 | ] 27 | 28 | # Add your button entity 29 | async_add_entities(buttons) 30 | 31 | class EcostreamButtonBase(CoordinatorEntity, ButtonEntity): 32 | """Base class for ecostream buttons.""" 33 | def __init__(self, coordinator: EcostreamDataUpdateCoordinator, entry: ConfigEntry): 34 | """Initialize the sensor.""" 35 | super().__init__(coordinator) 36 | self._entry_id = entry.entry_id 37 | 38 | @property 39 | def device_info(self) -> DeviceInfo: 40 | """Return the device info.""" 41 | return DeviceInfo( 42 | identifiers={(DOMAIN, self.coordinator.api._host)}, 43 | name="EcoStream", 44 | manufacturer="Buva", 45 | model="EcoStream", 46 | ) 47 | 48 | class FilterResetButton(EcostreamButtonBase): 49 | """Button that resets the filter replacement date.""" 50 | 51 | def __init__(self, coordinator: EcostreamDataUpdateCoordinator, entry: ConfigEntry): 52 | """Initialize the button""" 53 | super().__init__(coordinator, entry) 54 | self._last_pressed = None 55 | 56 | @property 57 | def unique_id(self): 58 | return f"{self._entry_id}_reset_filter" 59 | 60 | @property 61 | def name(self): 62 | return "Ecostream Reset Filter" 63 | 64 | @property 65 | def icon(self): 66 | """Return the icon to use in the frontend, if any.""" 67 | return "mdi:air-filter" 68 | 69 | @property 70 | def extra_state_attributes(self): 71 | """Return additional state attributes.""" 72 | return { 73 | "last_pressed": self._last_pressed 74 | } 75 | 76 | async def async_press(self) -> None: 77 | """Handle the button press.""" 78 | 79 | # Get current date and time 80 | now = dt.utcnow() 81 | self._last_pressed = now 82 | 83 | # Add 3 months (which seems to correspond with what the ecostream app does) 84 | nextReplacementDate = now + relativedelta(months=3) 85 | nextReplacementTimestamp = int(nextReplacementDate.timestamp()) 86 | 87 | # Send the new filter replacement date to the unit 88 | payload = { 89 | "config": { 90 | "filter_datetime": nextReplacementTimestamp 91 | } 92 | } 93 | await self.coordinator.send_json(payload) 94 | -------------------------------------------------------------------------------- /custom_components/ecostream/climate.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | 3 | import math 4 | from typing import Any, Optional 5 | 6 | from homeassistant.helpers.entity import DeviceInfo 7 | from homeassistant.components.climate import ( 8 | ClimateEntity, 9 | ClimateEntityFeature, 10 | HVACAction, 11 | HVACMode, 12 | ) 13 | from homeassistant.const import UnitOfTemperature, PRECISION_WHOLE 14 | from homeassistant.config_entries import ConfigEntry 15 | from homeassistant.core import HomeAssistant, callback 16 | from homeassistant.helpers.entity_platform import AddEntitiesCallback 17 | from homeassistant.helpers.update_coordinator import CoordinatorEntity 18 | 19 | from . import EcostreamDataUpdateCoordinator 20 | from .const import DOMAIN 21 | 22 | async def async_setup_entry( 23 | hass: HomeAssistant, 24 | entry: ConfigEntry[EcostreamDataUpdateCoordinator], 25 | async_add_entities: AddEntitiesCallback, 26 | ): 27 | coordinator = entry.runtime_data 28 | 29 | climates = [ 30 | EcostreamSummerComfortClimate(coordinator, entry), 31 | ] 32 | 33 | async_add_entities(climates, update_before_add=True) 34 | 35 | class EcostreamSummerComfortClimate(CoordinatorEntity, ClimateEntity): 36 | _attr_hvac_modes = [HVACMode.OFF, HVACMode.COOL] 37 | _attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE 38 | 39 | _attr_temperature_unit = UnitOfTemperature.CELSIUS 40 | _attr_target_temperature_step = PRECISION_WHOLE 41 | _attr_min_temp = 10 42 | _attr_max_temp = 30 43 | 44 | def __init__(self, coordinator: EcostreamDataUpdateCoordinator, entry: ConfigEntry): 45 | super().__init__(coordinator) 46 | self._entry_id = entry.entry_id 47 | self._attr_hvac_mode = self._current_hvac_mode() 48 | self._attr_hvac_action = self._current_hvac_action() 49 | self._attr_current_temperature = self._current_temperature() 50 | self._attr_target_temperature = self._target_temperature() 51 | 52 | @property 53 | def unique_id(self): 54 | return f"{self._entry_id}_summer_comfort_climate" 55 | 56 | @property 57 | def name(self): 58 | return "Ecostream Summer Comfort Climate" 59 | 60 | @property 61 | def device_info(self) -> DeviceInfo: 62 | """Return the device info.""" 63 | return DeviceInfo( 64 | identifiers={(DOMAIN, self.coordinator.api._host)}, 65 | name="EcoStream", 66 | manufacturer="Buva", 67 | model="EcoStream", 68 | ) 69 | 70 | async def async_set_temperature(self, temperature, **kwargs): 71 | payload = { 72 | "config": { 73 | "sum_com_temp": int(temperature) 74 | } 75 | } 76 | 77 | await self.coordinator.send_json(payload) 78 | 79 | async def async_set_hvac_mode(self, hvac_mode): 80 | enable_summer_control = hvac_mode == "cool" 81 | 82 | payload = { 83 | "config": { 84 | "sum_com_enabled": enable_summer_control, 85 | } 86 | } 87 | await self.coordinator.send_json(payload) 88 | 89 | def _current_hvac_mode(self) -> HVACMode: 90 | is_summer_control_enabled = self.coordinator.data["config"]["sum_com_enabled"] 91 | return HVACMode.COOL if is_summer_control_enabled else HVACMode.OFF 92 | 93 | def _current_hvac_action(self) -> HVACAction: 94 | bypass_position = self.coordinator.data["status"]["bypass_pos"] 95 | return HVACAction.COOLING if bypass_position > 0 else HVACAction.IDLE 96 | 97 | def _target_temperature(self) -> float: 98 | return self.coordinator.data["config"]["sum_com_temp"] 99 | 100 | def _current_temperature(self) -> float: 101 | return self.coordinator.data["status"]["sensor_temp_eta"] 102 | 103 | @callback 104 | def _handle_coordinator_update(self) -> None: 105 | self._attr_hvac_mode = self._current_hvac_mode() 106 | self._attr_hvac_action = self._current_hvac_action() 107 | self._attr_current_temperature = self._current_temperature() 108 | self._attr_target_temperature = self._target_temperature() 109 | self.async_write_ha_state() 110 | -------------------------------------------------------------------------------- /custom_components/ecostream/config_flow.py: -------------------------------------------------------------------------------- 1 | """Config flow for ecostream integration.""" 2 | from __future__ import annotations 3 | 4 | import logging 5 | from typing import Any, Optional 6 | import voluptuous as vol # type: ignore 7 | 8 | from homeassistant import config_entries # type: ignore 9 | from homeassistant.core import HomeAssistant # type: ignore 10 | from homeassistant.data_entry_flow import FlowResult # type: ignore 11 | from homeassistant.const import CONF_HOST 12 | from homeassistant.helpers.service_info.zeroconf import ZeroconfServiceInfo # type: ignore 13 | 14 | from .const import DOMAIN # Import your domain name from const.py 15 | from .__init__ import EcostreamWebsocketsAPI # Import the API class 16 | 17 | LOGGER = logging.getLogger(__name__) 18 | 19 | # Define the configuration schema 20 | STEP_USER_DATA_SCHEMA = vol.Schema({ 21 | vol.Required(CONF_HOST): str, 22 | }) 23 | 24 | class EcostreamConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): 25 | """Handle a config flow for ecostream.""" 26 | 27 | VERSION = 1 28 | 29 | async def async_step_user(self, user_input=None) -> FlowResult: 30 | """Handle the initial step.""" 31 | errors = {} 32 | 33 | if user_input is not None: 34 | host = user_input[CONF_HOST] 35 | 36 | # Validate the WebSocket connection 37 | api = await self._test_connection(host) 38 | valid = api is not None 39 | 40 | if valid: 41 | # Create a config entry if the connection is valid 42 | return self.async_create_entry(title=api._device_name, data=user_input) 43 | else: 44 | errors["base"] = "cannot_connect" 45 | 46 | return self.async_show_form( 47 | step_id="user", data_schema=STEP_USER_DATA_SCHEMA, errors=errors 48 | ) 49 | 50 | async def async_step_zeroconf( 51 | self, discovery_info: ZeroconfServiceInfo 52 | ) -> config_entries.ConfigFlowResult: 53 | """Handle zeroconf discovery.""" 54 | self.host = f"{discovery_info.host}:{discovery_info.port}" 55 | LOGGER.debug("Discovered device: %s", self.host) 56 | 57 | self.api = await self._test_connection(self.host) 58 | 59 | if self.api is None: 60 | return self.async_abort(reason="cannot_connect") 61 | 62 | await self.async_set_unique_id(self.api._device_name) 63 | 64 | self._abort_if_unique_id_configured( 65 | updates={CONF_HOST: self.host}, 66 | error="already_configured_device", 67 | ) 68 | 69 | self.context.update( 70 | { 71 | "title_placeholders": { 72 | "name": self.api._device_name, 73 | }, 74 | } 75 | ) 76 | 77 | return await self.async_step_discovery_confirm() 78 | 79 | async def async_step_discovery_confirm( 80 | self, user_input: dict[str, Any] | None = None 81 | ) -> config_entries.ConfigFlowResult: 82 | """Confirm discovery.""" 83 | if user_input is not None: 84 | return self.async_create_entry( 85 | title=self.api._device_name, 86 | data={CONF_HOST: self.host}, 87 | ) 88 | 89 | self._set_confirm_only() 90 | 91 | return self.async_show_form(step_id="discovery_confirm") 92 | 93 | async def _test_connection(self, host: str) -> Optional[EcostreamWebsocketsAPI]: 94 | """Test the WebSocket connection to the specified host.""" 95 | try: 96 | api = EcostreamWebsocketsAPI() 97 | await api.connect(host) 98 | await api.get_data() # Attempt to fetch data to confirm the connection works 99 | return api 100 | except Exception as e: 101 | LOGGER.error("Failed to connect to %s: %s", host, e) 102 | return None 103 | 104 | async def async_step_reauth(self, data: dict) -> FlowResult: 105 | """Handle re-authentication.""" 106 | self.context["title_placeholders"] = { 107 | CONF_HOST: data[CONF_HOST], 108 | } 109 | return await self.async_step_user(user_input=data) 110 | -------------------------------------------------------------------------------- /custom_components/ecostream/const.py: -------------------------------------------------------------------------------- 1 | """Constants for the ecostream integration.""" 2 | 3 | DOMAIN = "ecostream" 4 | -------------------------------------------------------------------------------- /custom_components/ecostream/fan.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | 3 | import math 4 | from typing import Any, Optional 5 | 6 | from homeassistant.helpers.entity import DeviceInfo 7 | from homeassistant.components.fan import ( 8 | FanEntity, 9 | FanEntityFeature, 10 | ) 11 | from homeassistant.config_entries import ConfigEntry 12 | from homeassistant.core import HomeAssistant, callback 13 | from homeassistant.helpers.entity_platform import AddEntitiesCallback 14 | from homeassistant.helpers.update_coordinator import CoordinatorEntity 15 | from homeassistant.util.percentage import ( 16 | percentage_to_ranged_value, 17 | ranged_value_to_percentage, 18 | int_states_in_range, 19 | ) 20 | 21 | from . import EcostreamDataUpdateCoordinator, EcostreamWebsocketsAPI 22 | from .const import DOMAIN 23 | 24 | PRESET_MODE_LOW = "low" 25 | PRESET_MODE_MID = "mid" 26 | PRESET_MODE_HIGH = "high" 27 | 28 | async def async_setup_entry( 29 | hass: HomeAssistant, 30 | entry: ConfigEntry[EcostreamDataUpdateCoordinator], 31 | async_add_entities: AddEntitiesCallback, 32 | ): 33 | """Set up the fan entity.""" 34 | coordinator = entry.runtime_data 35 | 36 | async_add_entities([EcoStreamFan(coordinator, entry)], update_before_add=True) 37 | 38 | 39 | class EcoStreamFan(CoordinatorEntity, FanEntity): 40 | """Ecostream fan component.""" 41 | 42 | _attr_supported_features = ( 43 | FanEntityFeature.PRESET_MODE 44 | | FanEntityFeature.SET_SPEED 45 | | FanEntityFeature.TURN_OFF 46 | | FanEntityFeature.TURN_ON 47 | ) 48 | 49 | _attr_preset_modes = [ 50 | PRESET_MODE_LOW, 51 | PRESET_MODE_MID, 52 | PRESET_MODE_HIGH, 53 | ] 54 | 55 | _attr_translation_key = "ecostream_fan" 56 | 57 | current_speed: float | None = None 58 | 59 | def __init__(self, coordinator: EcostreamDataUpdateCoordinator, entry: ConfigEntry): 60 | """Initialize the sensor.""" 61 | super().__init__(coordinator) 62 | self._entry_id = entry.entry_id 63 | 64 | self.current_speed = self.coordinator.data.get("status", {}).get("qset") 65 | 66 | self._speed_range = ( 67 | self.coordinator.api._data["config"]["capacity_min"], 68 | self.coordinator.api._data["config"]["capacity_max"], 69 | ) 70 | 71 | self._preset_speeds = { 72 | PRESET_MODE_LOW: self.coordinator.api._data["config"]["setpoint_low"], 73 | PRESET_MODE_MID: self.coordinator.api._data["config"]["setpoint_mid"], 74 | PRESET_MODE_HIGH: self.coordinator.api._data["config"]["setpoint_high"], 75 | } 76 | 77 | @property 78 | def unique_id(self): 79 | return f"{self._entry_id}_fan_control" 80 | 81 | @property 82 | def name(self): 83 | """Return the name of the fan.""" 84 | return "Ecostream Fan" 85 | 86 | @property 87 | def device_info(self) -> DeviceInfo: 88 | """Return the device info.""" 89 | return DeviceInfo( 90 | identifiers={(DOMAIN, self.coordinator.api._host)}, 91 | name="EcoStream", 92 | manufacturer="Buva", 93 | model="EcoStream", 94 | ) 95 | 96 | async def set_speed(self, speed: int, preset_mode: Optional[str] = None): 97 | """Set the speed of the fan.""" 98 | payload = { 99 | "config": { 100 | "man_override_set": speed, 101 | "man_override_set_time": 1800 102 | } 103 | } 104 | await self.coordinator.send_json(payload) 105 | self.current_speed = speed 106 | self.preset_mode = preset_mode 107 | 108 | self.async_write_ha_state() 109 | 110 | async def async_set_percentage(self, percentage: int) -> None: 111 | """Set the speed percentage of the fan.""" 112 | await self.set_speed(math.ceil(percentage_to_ranged_value(self._speed_range, percentage))) 113 | 114 | async def async_turn_on(self, speed: Optional[str] = None, percentage: Optional[int] = None, **kwargs: Any) -> None: 115 | """Set the speed percentage of the fan to the provided percentage or """ 116 | await self.set_speed(math.ceil(percentage_to_ranged_value(self._speed_range, percentage or 100))) 117 | 118 | async def async_turn_off(self, **kwargs): 119 | """Turn the speed to the minimum value""" 120 | await self.set_speed(math.ceil(percentage_to_ranged_value(self._speed_range, 0))) 121 | 122 | @property 123 | def percentage(self) -> int | None: 124 | """Return the current speed percentage.""" 125 | if self.current_speed is None: 126 | return None 127 | return ranged_value_to_percentage(self._speed_range, self.current_speed) 128 | 129 | @property 130 | def speed_count(self) -> int: 131 | """Return the number of speeds the fan supports.""" 132 | return int_states_in_range(self._speed_range) 133 | 134 | async def async_set_preset_mode(self, preset_mode: str): 135 | """Set the preset mode of the fan.""" 136 | speed = self._preset_speeds.get(preset_mode) 137 | 138 | if speed is None: 139 | raise Exception("Unknown preset mode") 140 | 141 | await self.set_speed(speed, preset_mode) 142 | 143 | @callback 144 | def _handle_coordinator_update(self) -> None: 145 | """Handle updated data from the coordinator.""" 146 | new_speed = self.coordinator.data.get("status", {}).get("qset") 147 | 148 | if new_speed is None: 149 | return 150 | 151 | if new_speed != self.current_speed: 152 | self.preset_mode = None 153 | 154 | self.current_speed = new_speed 155 | 156 | self.async_write_ha_state() -------------------------------------------------------------------------------- /custom_components/ecostream/icons.json: -------------------------------------------------------------------------------- 1 | { 2 | "entity": { 3 | "fan": { 4 | "ecostream_fan": { 5 | "state_attributes": { 6 | "preset_mode": { 7 | "default": "mdi:fan", 8 | "state": { 9 | "low": "mdi:fan-speed-1", 10 | "mid": "mdi:fan-speed-2", 11 | "high": "mdi:fan-speed-3" 12 | } 13 | } 14 | } 15 | } 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /custom_components/ecostream/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "domain": "ecostream", 3 | "name": "Buva Ecostream", 4 | "codeowners": [ 5 | "@epodegrid" 6 | ], 7 | "config_flow": true, 8 | "dependencies": [], 9 | "documentation": "https://github.com/epodegrid/ecostream_homeassistant_integration/blob/main/README.md", 10 | "homekit": {}, 11 | "iot_class": "local_push", 12 | "issue_tracker": "https://github.com/epodegrid/ecostream_homeassistant_integration/issues", 13 | "requirements": [ 14 | "websocket-client==1.8.0" 15 | ], 16 | "ssdp": [], 17 | "version": "1.4.1", 18 | "zeroconf": [ 19 | { 20 | "type": "_http._tcp.local.", 21 | "name": "ecostream*" 22 | } 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /custom_components/ecostream/sensor.py: -------------------------------------------------------------------------------- 1 | """Sensor platform for the ecostream integration.""" 2 | from __future__ import annotations 3 | from datetime import datetime 4 | 5 | from homeassistant.helpers.entity import Entity # type: ignore 6 | from homeassistant.helpers.entity import DeviceInfo 7 | from homeassistant.config_entries import ConfigEntry # type: ignore 8 | from homeassistant.core import HomeAssistant # type: ignore 9 | from homeassistant.helpers.entity_platform import AddEntitiesCallback 10 | from homeassistant.helpers.update_coordinator import CoordinatorEntity # type: ignore 11 | from homeassistant.components.sensor import SensorDeviceClass 12 | from homeassistant.const import ( 13 | CONCENTRATION_PARTS_PER_BILLION, 14 | CONCENTRATION_PARTS_PER_MILLION, 15 | REVOLUTIONS_PER_MINUTE, 16 | UnitOfTemperature, 17 | UnitOfTime, 18 | UnitOfVolumeFlowRate, 19 | EntityCategory, 20 | PERCENTAGE, 21 | ) 22 | 23 | from . import EcostreamDataUpdateCoordinator 24 | from .const import DOMAIN 25 | 26 | async def async_setup_entry( 27 | hass: HomeAssistant, 28 | entry: ConfigEntry[EcostreamDataUpdateCoordinator], 29 | async_add_entities: AddEntitiesCallback, 30 | ): 31 | """Set up ecostream sensors from a config entry.""" 32 | coordinator = entry.runtime_data 33 | 34 | sensors = [ 35 | EcostreamFilterReplacementWarningSensor(coordinator, entry), 36 | EcostreamFrostProtectionSensor(coordinator, entry), 37 | EcostreamQsetSensor(coordinator, entry), 38 | EcostreamModeTimeLeftSensor(coordinator, entry), 39 | EcostreamFanEHASpeed(coordinator, entry), 40 | EcostreamFanSUPSpeed(coordinator, entry), 41 | EcostreamEco2EtaSensor(coordinator, entry), 42 | EcostreamRhEtaSensor(coordinator, entry), 43 | EcostreamTempEhaSensor(coordinator, entry), 44 | EcostreamTempEtaSensor(coordinator, entry), 45 | EcostreamTempOdaSensor(coordinator, entry), 46 | EcostreamTvocEtaSensor(coordinator, entry), 47 | EcostreamScheduledEnabledSensor(coordinator, entry), 48 | EcostreamSummerComfortEnabledSensor(coordinator, entry), 49 | EcostreamSummerComfortTemperatureSensor(coordinator, entry), 50 | EcostreamBypassPositionSensor(coordinator, entry), 51 | EcostreamBypassOverridePosition(coordinator, entry), 52 | EcostreamBypassOverrideTimeLeftSensor(coordinator, entry), 53 | EcostreamFilterReplacementDateSensor(coordinator, entry), 54 | EcostreamWifiSSID(coordinator, entry), 55 | EcostreamWifiRSSI(coordinator, entry), 56 | EcostreamWifiIP(coordinator, entry), 57 | EcostreamUptime(coordinator, entry), 58 | ] 59 | 60 | async_add_entities(sensors, update_before_add=True) 61 | 62 | class EcostreamSensorBase(CoordinatorEntity, Entity): 63 | """Base class for ecostream sensors.""" 64 | 65 | def __init__(self, coordinator: EcostreamDataUpdateCoordinator, entry: ConfigEntry): 66 | """Initialize the sensor.""" 67 | super().__init__(coordinator) 68 | self._entry_id = entry.entry_id 69 | 70 | @property 71 | def should_poll(self): 72 | """No polling needed, coordinator will handle updates.""" 73 | return False 74 | 75 | @property 76 | def device_info(self) -> DeviceInfo: 77 | """Return the device info.""" 78 | return DeviceInfo( 79 | identifiers={(DOMAIN, self.coordinator.api._host)}, 80 | name="EcoStream", 81 | manufacturer="Buva", 82 | model="EcoStream", 83 | ) 84 | 85 | class EcostreamFrostProtectionSensor(EcostreamSensorBase): 86 | """Sensor for frost protection status.""" 87 | 88 | @property 89 | def unique_id(self): 90 | return f"{self._entry_id}_frost_protection" 91 | 92 | @property 93 | def name(self): 94 | return "Ecostream Frost Protection" 95 | 96 | @property 97 | def state(self): 98 | return self.coordinator.data.get("status", {}).get("frost_protection") 99 | 100 | @property 101 | def icon(self): 102 | """Return the icon to use in the frontend, if any.""" 103 | return "mdi:snowflake-melt" 104 | 105 | class EcostreamFilterReplacementWarningSensor(EcostreamSensorBase): 106 | """Sensor for the filter replacement warning.""" 107 | 108 | @property 109 | def unique_id(self): 110 | return f"{self._entry_id}_filter_replacement_warning" 111 | 112 | @property 113 | def name(self): 114 | return "Ecostream Filter Replacement" 115 | 116 | @property 117 | def state(self): 118 | errors = self.coordinator.data.get("status", {}).get("errors", []) 119 | 120 | return any(error["type"] == "ERROR_FILTER" for error in errors) 121 | 122 | @property 123 | def icon(self): 124 | """Return the icon to use in the frontend, if any.""" 125 | return "mdi:air-filter" 126 | 127 | class EcostreamFilterReplacementDateSensor(EcostreamSensorBase): 128 | """Sensor for Filter Replacement Date.""" 129 | 130 | def __init__(self, coordinator: EcostreamDataUpdateCoordinator, entry: ConfigEntry): 131 | """Initialize the sensor.""" 132 | super().__init__(coordinator, entry) 133 | self._last_valid_filter_replacement_date = None 134 | 135 | @property 136 | def unique_id(self): 137 | return f"{self._entry_id}_filter_replacement_date" 138 | 139 | @property 140 | def name(self): 141 | return "Ecostream Filter Replacement Date" 142 | 143 | @property 144 | def state(self): 145 | 146 | # Try to get the timestamp from the received JSON message. 147 | # It appears that this isn't sent with every update, but is is there in the initial message and after the filter has been reset 148 | timestamp = self.coordinator.data.get("config", {}).get("filter_datetime") 149 | 150 | # Check if we received a valid timestamp, otherwise return the last valid value 151 | if timestamp is None: 152 | return self._last_valid_filter_replacement_date 153 | 154 | # convert timestamp in unix seconds to usable datetime 155 | filter_replacement_date = datetime.fromtimestamp(timestamp) 156 | 157 | # update the last valid value for future use 158 | self._last_valid_filter_replacement_date = filter_replacement_date 159 | 160 | return filter_replacement_date 161 | 162 | @property 163 | def icon(self): 164 | """Return the icon to use in the frontend, if any.""" 165 | return "mdi:air-filter" 166 | 167 | class EcostreamQsetSensor(EcostreamSensorBase): 168 | """Sensor for Qset status.""" 169 | 170 | @property 171 | def unique_id(self): 172 | return f"{self._entry_id}_qset" 173 | 174 | @property 175 | def name(self): 176 | return "Ecostream Qset" 177 | 178 | @property 179 | def state(self): 180 | return self.coordinator.data.get("status", {}).get("qset") 181 | 182 | @property 183 | def unit_of_measurement(self): 184 | return UnitOfVolumeFlowRate.CUBIC_METERS_PER_HOUR 185 | 186 | class EcostreamModeTimeLeftSensor(EcostreamSensorBase): 187 | """Sensor for mode time left.""" 188 | 189 | @property 190 | def unique_id(self): 191 | return f"{self._entry_id}_mode_time_left" 192 | 193 | @property 194 | def name(self): 195 | return "Ecostream Mode Time Left" 196 | 197 | @property 198 | def state(self): 199 | return self.coordinator.data.get("status", {}).get("override_set_time_left") 200 | 201 | @property 202 | def unit_of_measurement(self): 203 | return UnitOfTime.SECONDS 204 | 205 | @property 206 | def icon(self): 207 | """Return the icon to use in the frontend, if any.""" 208 | return "mdi:timer-play" 209 | 210 | class EcostreamFanEHASpeed(EcostreamSensorBase): 211 | 212 | @property 213 | def unique_id(self): 214 | return f"{self._entry_id}_fan_eha_speed" 215 | 216 | @property 217 | def name(self): 218 | return "Ecostream Fan Exhaust Speed" 219 | 220 | @property 221 | def state(self): 222 | return self.coordinator.data.get("status", {}).get("fan_eha_speed") 223 | 224 | @property 225 | def icon(self): 226 | """Return the icon to use in the frontend, if any.""" 227 | return "mdi:fan" 228 | 229 | @property 230 | def unit_of_measurement(self): 231 | return REVOLUTIONS_PER_MINUTE 232 | 233 | class EcostreamFanSUPSpeed(EcostreamSensorBase): 234 | 235 | @property 236 | def unique_id(self): 237 | return f"{self._entry_id}_fan_sup_speed" 238 | 239 | @property 240 | def name(self): 241 | return "Ecostream Fan Supply Speed" 242 | 243 | @property 244 | def state(self): 245 | return self.coordinator.data.get("status", {}).get("fan_sup_speed") 246 | 247 | @property 248 | def icon(self): 249 | """Return the icon to use in the frontend, if any.""" 250 | return "mdi:fan" 251 | 252 | @property 253 | def unit_of_measurement(self): 254 | return REVOLUTIONS_PER_MINUTE 255 | 256 | class EcostreamEco2EtaSensor(EcostreamSensorBase): 257 | """Sensor for eCO2 Return.""" 258 | 259 | @property 260 | def unique_id(self): 261 | return f"{self._entry_id}_eco2_eta" 262 | 263 | @property 264 | def name(self): 265 | return "Ecostream eCO2 Return" 266 | 267 | @property 268 | def state(self): 269 | return self.coordinator.data.get("status", {}).get("sensor_eco2_eta") 270 | 271 | @property 272 | def unit_of_measurement(self): 273 | return CONCENTRATION_PARTS_PER_MILLION 274 | 275 | @property 276 | def icon(self): 277 | """Return the icon to use in the frontend, if any.""" 278 | return "mdi:molecule-co2" 279 | 280 | class EcostreamTempEhaSensor(EcostreamSensorBase): 281 | """Sensor for Exhaust Air Temperature.""" 282 | 283 | @property 284 | def unique_id(self): 285 | return f"{self._entry_id}_temp_eha" 286 | 287 | @property 288 | def name(self): 289 | return "Ecostream Exhaust Air Temperature" 290 | 291 | @property 292 | def state(self): 293 | return self.coordinator.data.get("status", {}).get("sensor_temp_eha") 294 | 295 | @property 296 | def unit_of_measurement(self): 297 | return UnitOfTemperature.CELSIUS 298 | 299 | @property 300 | def icon(self): 301 | """Return the icon to use in the frontend, if any.""" 302 | return "mdi:temperature-celsius" 303 | 304 | class EcostreamTempEtaSensor(EcostreamSensorBase): 305 | """Sensor for Return Air Temperature.""" 306 | 307 | @property 308 | def unique_id(self): 309 | return f"{self._entry_id}_temp_eta" 310 | 311 | @property 312 | def name(self): 313 | return "Ecostream Return Air Temperature" 314 | 315 | @property 316 | def state(self): 317 | return self.coordinator.data.get("status", {}).get("sensor_temp_eta") 318 | 319 | @property 320 | def unit_of_measurement(self): 321 | return UnitOfTemperature.CELSIUS 322 | 323 | @property 324 | def icon(self): 325 | """Return the icon to use in the frontend, if any.""" 326 | return "mdi:temperature-celsius" 327 | 328 | class EcostreamTempOdaSensor(EcostreamSensorBase): 329 | """Sensor for Outside Air Temperature.""" 330 | 331 | @property 332 | def unique_id(self): 333 | return f"{self._entry_id}_temp_oda" 334 | 335 | @property 336 | def name(self): 337 | return "Ecostream Outside Air Temperature" 338 | 339 | @property 340 | def state(self): 341 | return self.coordinator.data.get("status", {}).get("sensor_temp_oda") 342 | 343 | @property 344 | def unit_of_measurement(self): 345 | return UnitOfTemperature.CELSIUS 346 | 347 | @property 348 | def icon(self): 349 | """Return the icon to use in the frontend, if any.""" 350 | return "mdi:temperature-celsius" 351 | 352 | class EcostreamTvocEtaSensor(EcostreamSensorBase): 353 | """Sensor for Total Volatile Organic Compounds Outside Air.""" 354 | 355 | @property 356 | def unique_id(self): 357 | return f"{self._entry_id}_tvoc_eta" 358 | 359 | @property 360 | def name(self): 361 | return "Ecostream Total Volatile Organic Compounds Outside Air" 362 | 363 | @property 364 | def state(self): 365 | return self.coordinator.data.get("status", {}).get("sensor_tvoc_eta") 366 | 367 | @property 368 | def unit_of_measurement(self): 369 | return CONCENTRATION_PARTS_PER_BILLION 370 | 371 | @property 372 | def icon(self): 373 | """Return the icon to use in the frontend, if any.""" 374 | return "mdi:air-purifier" 375 | 376 | class EcostreamScheduledEnabledSensor(EcostreamSensorBase): 377 | @property 378 | def unique_id(self): 379 | return f"{self._entry_id}_schedule_enabled" 380 | 381 | @property 382 | def name(self): 383 | return "Ecostream Schedule Enabled" 384 | 385 | @property 386 | def state(self): 387 | return self.coordinator.data["config"]["schedule_enabled"] 388 | 389 | @property 390 | def icon(self): 391 | return "mdi:toggle-switch-variant" if self.state else "mdi:toggle-switch-variant-off" 392 | 393 | class EcostreamSummerComfortEnabledSensor(EcostreamSensorBase): 394 | @property 395 | def unique_id(self): 396 | return f"{self._entry_id}_summer_comfort_enabled" 397 | 398 | @property 399 | def name(self): 400 | return "Ecostream Summer Comfort Enabled" 401 | 402 | @property 403 | def state(self): 404 | return self.coordinator.data["config"]["sum_com_enabled"] 405 | 406 | @property 407 | def icon(self): 408 | return "mdi:toggle-switch-variant" if self.state else "mdi:toggle-switch-variant-off" 409 | 410 | class EcostreamSummerComfortTemperatureSensor(EcostreamSensorBase): 411 | @property 412 | def unique_id(self): 413 | return f"{self._entry_id}_summer_comfort_temperature" 414 | 415 | @property 416 | def name(self): 417 | return "Ecostream Summer Comfort Temperature" 418 | 419 | @property 420 | def state(self): 421 | return self.coordinator.data["config"]["sum_com_temp"] 422 | 423 | @property 424 | def unit_of_measurement(self): 425 | return UnitOfTemperature.CELSIUS 426 | 427 | @property 428 | def icon(self): 429 | return "mdi:temperature-celsius" 430 | 431 | class EcostreamBypassPositionSensor(EcostreamSensorBase): 432 | @property 433 | def unique_id(self): 434 | return f"{self._entry_id}_bypass_pos" 435 | 436 | @property 437 | def name(self): 438 | return "Ecostream Bypass Position" 439 | 440 | @property 441 | def state(self): 442 | return self.coordinator.data["status"]["bypass_pos"] 443 | 444 | @property 445 | def unit_of_measurement(self): 446 | return PERCENTAGE 447 | 448 | class EcostreamBypassOverridePosition(EcostreamSensorBase): 449 | @property 450 | def unique_id(self): 451 | return f"{self._entry_id}_bypass_override_pos" 452 | 453 | @property 454 | def name(self): 455 | return "Ecostream Bypass Override Position" 456 | 457 | @property 458 | def state(self): 459 | return self.coordinator.data["config"]["man_override_bypass"] 460 | 461 | @property 462 | def unit_of_measurement(self): 463 | return PERCENTAGE 464 | 465 | class EcostreamBypassOverrideTimeLeftSensor(EcostreamSensorBase): 466 | @property 467 | def unique_id(self): 468 | return f"{self._entry_id}_override_bypass_time_left" 469 | 470 | @property 471 | def name(self): 472 | return "Ecostream Bypass Override Time Left" 473 | 474 | @property 475 | def state(self): 476 | return self.coordinator.data["status"]["override_bypass_time_left"] 477 | 478 | @property 479 | def unit_of_measurement(self): 480 | return UnitOfTime.SECONDS 481 | 482 | @property 483 | def icon(self): 484 | return "mdi:timer-play" 485 | 486 | class EcostreamRhEtaSensor(EcostreamSensorBase): 487 | """Sensor for Relative Humidity Return.""" 488 | 489 | @property 490 | def unique_id(self): 491 | return f"{self._entry_id}_rh_eta" 492 | 493 | @property 494 | def name(self): 495 | return "Ecostream Relative Humidity Return" 496 | 497 | @property 498 | def state(self): 499 | return self.coordinator.data.get("status", {}).get("sensor_rh_eta") 500 | 501 | @property 502 | def unit_of_measurement(self): 503 | return "%" 504 | 505 | @property 506 | def icon(self): 507 | """Return the icon to use in the frontend, if any.""" 508 | return "mdi:water-percent" 509 | 510 | class EcostreamWifiSSID(EcostreamSensorBase): 511 | @property 512 | def entity_category(self): 513 | return EntityCategory.DIAGNOSTIC 514 | 515 | @property 516 | def unique_id(self): 517 | return f"{self._entry_id}_wifi_ssid" 518 | 519 | @property 520 | def name(self): 521 | return "Ecostream Wifi SSID" 522 | 523 | @property 524 | def state(self): 525 | return self.coordinator.data["comm_wifi"]["ssid"] 526 | 527 | @property 528 | def icon(self): 529 | return "mdi:wifi" 530 | 531 | class EcostreamWifiRSSI(EcostreamSensorBase): 532 | @property 533 | def entity_category(self): 534 | return EntityCategory.DIAGNOSTIC 535 | 536 | @property 537 | def device_class(self): 538 | return SensorDeviceClass.SIGNAL_STRENGTH 539 | 540 | @property 541 | def unit_of_measurement(self): 542 | return "dBm" 543 | 544 | @property 545 | def unique_id(self): 546 | return f"{self._entry_id}_wifi_rssi" 547 | 548 | @property 549 | def name(self): 550 | return "Ecostream Wifi RSSI" 551 | 552 | @property 553 | def state(self): 554 | return int(self.coordinator.data["comm_wifi"]["rssi"]) 555 | 556 | @property 557 | def icon(self): 558 | return "mdi:wifi" 559 | 560 | class EcostreamWifiIP(EcostreamSensorBase): 561 | @property 562 | def entity_category(self): 563 | return EntityCategory.DIAGNOSTIC 564 | 565 | @property 566 | def unique_id(self): 567 | return f"{self._entry_id}_wifi_ip" 568 | 569 | @property 570 | def name(self): 571 | return "Ecostream Wifi IP" 572 | 573 | @property 574 | def state(self): 575 | return self.coordinator.data["comm_wifi"]["wifi_ip"] 576 | 577 | @property 578 | def icon(self): 579 | return "mdi:network-outline" 580 | 581 | class EcostreamUptime(EcostreamSensorBase): 582 | @property 583 | def entity_category(self): 584 | return EntityCategory.DIAGNOSTIC 585 | 586 | @property 587 | def unique_id(self): 588 | return f"{self._entry_id}_uptime" 589 | 590 | @property 591 | def name(self): 592 | return "Ecostream uptime" 593 | 594 | @property 595 | def state(self): 596 | return self.coordinator.data["system"]["uptime"] 597 | 598 | @property 599 | def icon(self): 600 | return "mdi:progress-clock" 601 | 602 | @property 603 | def unit_of_measurement(self): 604 | return UnitOfTime.SECONDS 605 | -------------------------------------------------------------------------------- /custom_components/ecostream/strings.json: -------------------------------------------------------------------------------- 1 | { 2 | "config": { 3 | "step": { 4 | "user": { 5 | "data": { 6 | "host": "[%key:common::config_flow::data::host%]" 7 | } 8 | } 9 | }, 10 | "error": { 11 | "cannot_connect": "[%key:common::config_flow::error::cannot_connect%]", 12 | "invalid_auth": "[%key:common::config_flow::error::invalid_auth%]", 13 | "unknown": "[%key:common::config_flow::error::unknown%]" 14 | }, 15 | "abort": { 16 | "already_configured": "[%key:common::config_flow::abort::already_configured_device%]" 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /custom_components/ecostream/switch.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | 3 | from homeassistant.components.switch import SwitchEntity 4 | from homeassistant.helpers.entity import DeviceInfo 5 | from homeassistant.config_entries import ConfigEntry 6 | from homeassistant.core import HomeAssistant, callback 7 | from homeassistant.helpers.entity_platform import AddEntitiesCallback 8 | from homeassistant.helpers.update_coordinator import CoordinatorEntity 9 | 10 | from . import EcostreamDataUpdateCoordinator, EcostreamWebsocketsAPI 11 | from .const import DOMAIN 12 | 13 | async def async_setup_entry( 14 | hass: HomeAssistant, 15 | entry: ConfigEntry[EcostreamDataUpdateCoordinator], 16 | async_add_entities: AddEntitiesCallback, 17 | ) -> None: 18 | coordinator = entry.runtime_data 19 | 20 | buttons = [ 21 | ScheduleSwitch(coordinator, entry) 22 | ] 23 | 24 | async_add_entities(buttons) 25 | 26 | class EcostreamSwitchBase(CoordinatorEntity, SwitchEntity): 27 | def __init__(self, coordinator: EcostreamDataUpdateCoordinator, entry: ConfigEntry): 28 | super().__init__(coordinator) 29 | self._entry_id = entry.entry_id 30 | 31 | @property 32 | def device_info(self) -> DeviceInfo: 33 | return DeviceInfo( 34 | identifiers={(DOMAIN, self.coordinator.api._host)}, 35 | name="EcoStream", 36 | manufacturer="Buva", 37 | model="EcoStream", 38 | ) 39 | 40 | class ScheduleSwitch(EcostreamSwitchBase): 41 | def __init__(self, coordinator: EcostreamDataUpdateCoordinator, entry: ConfigEntry): 42 | super().__init__(coordinator, entry) 43 | 44 | @property 45 | def unique_id(self): 46 | return f"{self._entry_id}_schedule_switch" 47 | 48 | @property 49 | def name(self): 50 | return "Schedule" 51 | 52 | @property 53 | def icon(self): 54 | return "mdi:calendar-month-outline" 55 | 56 | @callback 57 | def _handle_coordinator_update(self): 58 | self._attr_is_on = self.coordinator.data["config"]["schedule_enabled"] 59 | self.async_write_ha_state() 60 | 61 | async def async_turn_on(self): 62 | await self._change_schedule(True) 63 | 64 | async def async_turn_off(self): 65 | await self._change_schedule(False) 66 | 67 | async def _change_schedule(self, schedule_enabled: bool): 68 | payload = { 69 | "config": { 70 | "schedule_enabled": schedule_enabled 71 | } 72 | } 73 | await self.coordinator.send_json(payload) -------------------------------------------------------------------------------- /custom_components/ecostream/translations/en.json: -------------------------------------------------------------------------------- 1 | { 2 | "config": { 3 | "abort": { 4 | "already_configured": "Device is already configured" 5 | }, 6 | "error": { 7 | "cannot_connect": "Failed to connect", 8 | "invalid_auth": "Invalid authentication", 9 | "unknown": "Unexpected error" 10 | }, 11 | "step": { 12 | "user": { 13 | "data": { 14 | "host": "Host" 15 | } 16 | } 17 | } 18 | }, 19 | "entity": { 20 | "fan": { 21 | "ecostream_fan": { 22 | "state_attributes": { 23 | "preset_mode": { 24 | "state": { 25 | "low": "Low", 26 | "mid": "Medium", 27 | "high": "High" 28 | } 29 | } 30 | } 31 | } 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /custom_components/ecostream/valve.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | 3 | import math 4 | from typing import Any, Optional 5 | 6 | from homeassistant.helpers.entity import DeviceInfo 7 | from homeassistant.components.valve import ( 8 | ValveDeviceClass, 9 | ValveEntity, 10 | ValveEntityFeature, 11 | ) 12 | from homeassistant.config_entries import ConfigEntry 13 | from homeassistant.core import HomeAssistant, callback 14 | from homeassistant.helpers.entity_platform import AddEntitiesCallback 15 | from homeassistant.helpers.update_coordinator import CoordinatorEntity 16 | 17 | from . import EcostreamDataUpdateCoordinator 18 | from .const import DOMAIN 19 | 20 | async def async_setup_entry( 21 | hass: HomeAssistant, 22 | entry: ConfigEntry[EcostreamDataUpdateCoordinator], 23 | async_add_entities: AddEntitiesCallback, 24 | ): 25 | coordinator = entry.runtime_data 26 | 27 | valves = [ 28 | EcostreamBypassValve(coordinator, entry), 29 | ] 30 | 31 | async_add_entities(valves, update_before_add=True) 32 | 33 | class EcostreamBypassValve(CoordinatorEntity, ValveEntity): 34 | reports_position = True 35 | 36 | _attr_supported_features = ( 37 | ValveEntityFeature.CLOSE 38 | | ValveEntityFeature.OPEN 39 | | ValveEntityFeature.SET_POSITION 40 | ) 41 | 42 | def __init__(self, coordinator: EcostreamDataUpdateCoordinator, entry: ConfigEntry): 43 | super().__init__(coordinator) 44 | self._entry_id = entry.entry_id 45 | 46 | @property 47 | def unique_id(self): 48 | return f"{self._entry_id}_bypass_valve" 49 | 50 | @property 51 | def name(self): 52 | return "Ecostream Bypass Valve" 53 | 54 | @property 55 | def device_info(self) -> DeviceInfo: 56 | """Return the device info.""" 57 | return DeviceInfo( 58 | identifiers={(DOMAIN, self.coordinator.api._host)}, 59 | name="EcoStream", 60 | manufacturer="Buva", 61 | model="EcoStream", 62 | ) 63 | 64 | async def async_set_valve_position(self, position: int): 65 | man_override_bypass_time = 24 * 3600 66 | 67 | if position == 0: 68 | # When the valve is closed, also disable the override to ensure 69 | # other processes like summer comfort control can control the 70 | # bypass valve again. 71 | man_override_bypass_time = 0 72 | 73 | payload = { 74 | "config": { 75 | "man_override_bypass": position, 76 | "man_override_bypass_time": man_override_bypass_time, 77 | } 78 | } 79 | 80 | await self.coordinator.send_json(payload) 81 | 82 | @callback 83 | def _handle_coordinator_update(self): 84 | self._attr_current_valve_position = self.coordinator.data["status"]["bypass_pos"] 85 | 86 | config = self.coordinator.data["config"] 87 | 88 | # Most of the time, there is no movement in the bypass valve. Not are we able to determine 89 | # the current action when the bypass is not currently in override mode. 90 | self._attr_is_closing = False 91 | self._attr_is_opening = False 92 | 93 | if config["man_override_bypass_time"] > 0: 94 | target = config["man_override_bypass"] 95 | 96 | if abs(self._attr_current_valve_position - target) < 0.1: 97 | # The difference is more likely due to rounding issues. Don't report a current action. 98 | pass 99 | elif self._attr_current_valve_position > target: 100 | self._attr_is_closing = True 101 | elif self._attr_current_valve_position < target: 102 | self._attr_is_opening = True 103 | elif not config["sum_com_enabled"] and self._attr_current_valve_position > 0: 104 | # If summer comfort is not enabled and the bypass is currently open, it will be closing 105 | self._attr_is_closing = True 106 | 107 | self.async_write_ha_state() 108 | -------------------------------------------------------------------------------- /hacs.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Buva Ecostream", 3 | "content_in_root": false 4 | } 5 | --------------------------------------------------------------------------------