Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ The integration exposes various entities to configure additional features of you
- **Auto Light**: Automatically controls the display lights based on HVAC operations. When enabled, lights will turn on/off with the AC unit. *Note: This is an integration feature, not an actual AC unit state*
- **Temperature Step**: Sets the increment step for adjusting the target temperature. This allows you to configure how much the temperature changes when using the up/down controls in Home Assistant
- **External Temperature Sensor**: Select a temperature sensor entity to use instead of the built-in AC sensor. Choose 'None' to use the built-in sensor. This is useful if you have a more accurate room temperature sensor that you want the AC to use for temperature readings
- **External Humidity Sensor**: Select a humidity sensor entity to use instead of the built-in AC sensor. Choose 'None' to use the built-in sensor. This is useful if you have a more accurate room humidity sensor that you want the AC to use for humidity readings

## Credits

Expand Down
23 changes: 22 additions & 1 deletion custom_components/gree/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,9 @@ def __init__(

self._temp_sensor_offset = temp_sensor_offset

# Store for external temp sensor entity (set by sensor entity)
# Store for external temp and humid sensor entity (set by sensor entity)
self._external_temperature_sensor = None
self._external_humidity_sensor = None

# Keep unsub callbacks for deregistering listeners
self._listeners: list = []
Expand Down Expand Up @@ -450,11 +451,26 @@ def UpdateHAOutsideTemperature(self):
_LOGGER.debug(f"{self._name}: UpdateHAOutsideTemperature: HA outside temperature set with device built-in outside temperature sensor state: {self._current_outside_temperature}{self._unit_of_measurement}")

def UpdateHARoomHumidity(self):
# Use external humidity sensor if available
if self._external_humidity_sensor:
external_sensor_state = self.hass.states.get(self._external_humidity_sensor)

if external_sensor_state and external_sensor_state.state not in ("unknown", "unavailable"):
try:
_LOGGER.debug(f"{self._name}: Using external humidity sensor {self._external_humidity_sensor}: {external_sensor_state.state}%")
self._current_room_humidity = float(external_sensor_state.state)
_LOGGER.debug(f"{self._name}: Current room humidity from external sensor: {self._current_room_humidity}%")
return
except (ValueError, TypeError) as ex:
_LOGGER.error(f"{self._name}: Unable to update from external humidity sensor {self._external_humidity_sensor}: {ex}")

# Update room humidity from built-in AC room humidity sensor if available
if self._has_room_humidity_sensor:
_LOGGER.debug(f"{self._name}: UpdateHARoomHumidity: DwatSen: {self._acOptions['DwatSen']}")
self._current_room_humidity = self._acOptions["DwatSen"]
_LOGGER.debug(f"{self._name}: UpdateHARoomHumidity: HA room humidity set with device built-in room humidity sensor state: {self._current_room_humidity}%")
else:
self._current_room_humidity = None

def UpdateHAStateToCurrentACState(self):
self.UpdateHATargetTemperature()
Expand Down Expand Up @@ -652,6 +668,11 @@ def current_temperature(self):
# Return the current temperature.
return self._current_temperature

@property
def current_humidity(self) -> float | None:
# Return the current humidity.
return self._current_room_humidity

@property
def min_temp(self):
if self._unit_of_measurement == "°C":
Expand Down
36 changes: 33 additions & 3 deletions custom_components/gree/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ def get_temperature_sensor_options(hass: HomeAssistant) -> list[str]:

return options

def get_humidity_sensor_options(hass: HomeAssistant) -> list[str]:
"""Get list of available humidity sensor entities."""
options = ["None"] # Always include "None" as first option

# Get all entities from the registry
for state in hass.states.async_all():
# Look for humidity sensors
if state.entity_id.startswith("sensor."):
# Check for explicit device_class
if state.attributes.get("device_class") == "humidity":
options.append(state.entity_id)

return options


SELECTS: tuple[GreeSelectEntityDescription, ...] = (
GreeSelectEntityDescription(
Expand All @@ -62,6 +76,16 @@ def get_temperature_sensor_options(hass: HomeAssistant) -> list[str]:
restore_state=True,
options_fn=lambda hass: get_temperature_sensor_options(hass),
),
GreeSelectEntityDescription(
property_key="external_humidity_sensor",
icon="mdi:water-percent",
options=[], # Will be populated dynamically
value_fn=lambda device: getattr(device, "_external_humidity_sensor", "None"),
set_fn=lambda device, value: setattr(device, "_external_humidity_sensor", None if value == "None" else value),
entity_category=EntityCategory.CONFIG,
restore_state=True,
options_fn=lambda hass: get_humidity_sensor_options(hass),
),
)


Expand All @@ -83,7 +107,9 @@ def __init__(self, hass: HomeAssistant, entry, description: GreeSelectEntityDesc
super().__init__(hass, entry, description)
self._hass = hass
# Initialize with no external sensor configured
self._device._external_temperature_sensor = None
attr_name = f"_{description.property_key}"
if not hasattr(self._device, attr_name):
setattr(self._device, attr_name, None)
# Set up options dynamically
if description.options_fn:
self._attr_options = description.options_fn(hass)
Expand Down Expand Up @@ -121,8 +147,12 @@ async def async_select_option(self, option: str) -> None:

if self.entity_description.set_fn:
self.entity_description.set_fn(self._device, option)
self.async_write_ha_state()
_LOGGER.info("Selected %s: %s", self.entity_description.property_key, option)
self._device.UpdateHACurrentTemperature()
self._device.UpdateHARoomHumidity()
self._device.async_write_ha_state()

self.async_write_ha_state()
_LOGGER.info("Selected %s: %s", self.entity_description.property_key, option)

async def async_update(self) -> None:
"""Update the entity."""
Expand Down
4 changes: 4 additions & 0 deletions custom_components/gree/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@
"external_temperature_sensor": {
"name": "External Temperature Sensor",
"description": "Select a temperature sensor entity to use instead of the built-in AC sensor. Choose 'None' to use the built-in sensor."
},
"external_humidity_sensor": {
"name": "External Humidity Sensor",
"description": "Select a humidity sensor entity to use instead of the built-in AC sensor. Choose 'None' to use the built-in sensor."
}
},
"sensor": {
Expand Down