Skip to content

Commit

Permalink
Adding sensors (#118)
Browse files Browse the repository at this point in the history
* Adding sensors for current_temperature, current_humidity, sensor_rssi, and sensor_battery readings.
* Pick up pykumo v0.3.6
---------

Co-authored-by: Josh Barnard <barndawgie@users.noreply.github.com>
  • Loading branch information
dlarrick and barndawgie authored Aug 6, 2023
1 parent 6ed5913 commit fa40422
Show file tree
Hide file tree
Showing 3 changed files with 178 additions and 6 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,21 @@ Specific support and behavior can vary, depending on the capabilities of your in

## Home Assistant Sensors

Useful information from indoor units is provided as attributes on the associated `climate` entity. It's easier to use these attributes if you convert them to sensors using [templates](https://community.home-assistant.io/t/using-attributes-in-lovelace/72672). For example, here's a simple sensor for the target temperature.
Useful information from indoor units is provided as attributes on the associated `climate` entity. This data can be turned into sensors in one of two ways: sensors provided by the integration, or template sensors from the main entity's attributes.

### Sensors
By default a sensor for current temperature is enabled. It's possible to enable sensors for a few other values, if available:
- WiFi RSSI signal strength
- Current Humidity (provided by a linked PAC-USWHS003 or MHK2 device)
- PAC sensor battery level
- Sensor RSSI signal strength
- Outdoor temperature (provided by Kumo Station)

To enable these optional sensors, click on the Kumo tile in Settings -> Devices and Services, go into the Devices section, click on the indoor unit (or Kumo Station) and enable them under Sensors.

### Template Sensors

For additional attributes not covered above, or if you require more customization, you can convert attributes to sensors using [templates](https://community.home-assistant.io/t/using-attributes-in-lovelace/72672). For example, here's a simple sensor for the target temperature.

```yaml
# Get attribute of climate state in form of sensor
Expand Down
4 changes: 2 additions & 2 deletions custom_components/kumo/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"documentation": "https://github.com/dlarrick/hass-kumo",
"dependencies": [],
"codeowners": [ "@dlarrick" ],
"requirements": ["pykumo==0.3.5"],
"version": "0.3.6",
"requirements": ["pykumo==0.3.6"],
"version": "0.3.7",
"homeassistant": "2021.12.0"
}
164 changes: 161 additions & 3 deletions custom_components/kumo/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import homeassistant.helpers.config_validation as cv
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import SIGNAL_STRENGTH_DECIBELS, TEMP_CELSIUS
from homeassistant.const import SIGNAL_STRENGTH_DECIBELS, TEMP_CELSIUS, PERCENTAGE, PRECISION_TENTHS
from homeassistant.components.sensor import SensorDeviceClass
from homeassistant.helpers.typing import HomeAssistantType

Expand Down Expand Up @@ -44,6 +44,15 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry, async_a
all_serials = await hass.async_add_executor_job(account.get_all_units)
for serial in all_serials:
coordinator = coordinators[serial]

entities.append(KumoCurrentHumidity(coordinator))
_LOGGER.debug("Adding entity: current_humidity for %s", coordinator.get_device().get_name())
entities.append(KumoCurrentTemperature(coordinator))
_LOGGER.debug("Adding entity: current_temperature for %s", coordinator.get_device().get_name())
entities.append(KumoSensorBattery(coordinator))
_LOGGER.debug("Adding entity: sensor_battery for %s", coordinator.get_device().get_name())
entities.append(KumoSensorSignalStrength(coordinator))
_LOGGER.debug("Adding entity: sensor_signal_strength for %s", coordinator.get_device().get_name())
entities.append(KumoWifiSignal(coordinator))
_LOGGER.debug("Adding entity: wifi_signal for %s", coordinator.get_device().get_name())

Expand All @@ -56,6 +65,145 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry, async_a
if entities:
async_add_entities(entities, True)

class KumoCurrentHumidity(CoordinatedKumoEntitty, SensorEntity):
"""Representation of a Kumo's Unit's Current Humidity"""

def __init__(self, coordinator: KumoDataUpdateCoordinator):
"""Initialize the kumo station."""
super().__init__(coordinator)
self._name = self._pykumo.get_name() + " Current Humidity"

@property
def unique_id(self):
"""Return unique id"""
return f"{self._identifier}-current-humidity"

@property
def native_unit_of_measurement(self):
"""Return the unit of measurement which this thermostat uses."""
return PERCENTAGE

@property
def native_value(self):
"""Return the current humidity level."""
return self._pykumo.get_current_humidity()

@property
def device_class(self):
return SensorDeviceClass.HUMIDITY

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

@property
def entity_registry_enabled_default(self) -> bool:
"""Disable entity by default."""
return False

class KumoCurrentTemperature(CoordinatedKumoEntitty, SensorEntity):
"""Representation of a Kumo's Unit's Current Temperature"""

def __init__(self, coordinator: KumoDataUpdateCoordinator):
"""Initialize the kumo station."""
super().__init__(coordinator)
self._name = self._pykumo.get_name() + " Current Tempterature"

@property
def unique_id(self):
"""Return unique id"""
return f"{self._identifier}-current-temperature"

@property
def native_unit_of_measurement(self):
"""Return the unit of measurement which this thermostat uses."""
return TEMP_CELSIUS

@property
def native_value(self):
"""Return the current temperature."""
return self._pykumo.get_current_temperature()

@property
def device_class(self):
return SensorDeviceClass.TEMPERATURE

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

@property
def entity_registry_enabled_default(self) -> bool:
"""Enable entity by default."""
return True

class KumoSensorBattery(CoordinatedKumoEntitty, SensorEntity):
"""Representation of a Kumo Sensor's Battery Level."""

def __init__(self, coordinator: KumoDataUpdateCoordinator):
"""Initialize the kumo station."""
super().__init__(coordinator)
self._name = self._pykumo.get_name() + " Sensor Battery"

@property
def unique_id(self):
"""Return unique id"""
return f"{self._identifier}-sensor-battery"

@property
def native_unit_of_measurement(self):
"""Return the unit of measurement which this thermostat uses."""
return PERCENTAGE

@property
def native_value(self):
"""Return the sensor's current battery level."""
return self._pykumo.get_sensor_battery()

@property
def device_class(self):
return SensorDeviceClass.BATTERY

@property
def entity_registry_enabled_default(self) -> bool:
"""Disable entity by default."""
return False

class KumoSensorSignalStrength(CoordinatedKumoEntitty, SensorEntity):
"""Representation of a Kumo Sensor's Signal Strength."""

def __init__(self, coordinator: KumoDataUpdateCoordinator):
"""Initialize the kumo station."""
super().__init__(coordinator)
self._name = self._pykumo.get_name() + " Sensor Signal Strength"

@property
def unique_id(self):
"""Return unique id"""
return f"{self._identifier}-sensor-signal-strength"

@property
def native_unit_of_measurement(self):
"""Return the unit of measurement which this thermostat uses."""
return SIGNAL_STRENGTH_DECIBELS

@property
def native_value(self):
"""Return the sengor's signal strength in rssi."""
return self._pykumo.get_sensor_rssi()

@property
def device_class(self):
return SensorDeviceClass.SIGNAL_STRENGTH

@property
def entity_registry_enabled_default(self) -> bool:
"""Disable entity by default."""
return False


class KumoStationOutdoorTemperature(CoordinatedKumoEntitty, SensorEntity):
"""Representation of a Kumo Station Outdoor Temperature Sensor."""

Expand All @@ -76,13 +224,24 @@ def native_unit_of_measurement(self):

@property
def native_value(self):
"""Return the high dual setpoint temperature."""
"""Return the unit's reported outdoor temperature."""
return self._pykumo.get_outdoor_temperature()

@property
def device_class(self):
return SensorDeviceClass.TEMPERATURE

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

@property
def entity_registry_enabled_default(self) -> bool:
"""Disable entity by default."""
return False


class KumoWifiSignal(CoordinatedKumoEntitty, SensorEntity):
"""Representation of a Kumo's WiFi Signal Strength."""

Expand Down Expand Up @@ -114,4 +273,3 @@ def device_class(self):
def entity_registry_enabled_default(self) -> bool:
"""Disable entity by default."""
return False

0 comments on commit fa40422

Please sign in to comment.