Skip to content
Merged
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 homeassistant/components/automation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
"garage_door",
"gate",
"humidifier",
"humidity",
"lawn_mower",
"light",
"lock",
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/humidity/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Integration for humidity triggers."""
"""Integration for humidity triggers and conditions."""

from __future__ import annotations

Expand Down
38 changes: 38 additions & 0 deletions homeassistant/components/humidity/condition.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""Provides conditions for humidity."""

from __future__ import annotations

from homeassistant.components.climate import (
ATTR_CURRENT_HUMIDITY as CLIMATE_ATTR_CURRENT_HUMIDITY,
DOMAIN as CLIMATE_DOMAIN,
)
from homeassistant.components.humidifier import (
ATTR_CURRENT_HUMIDITY as HUMIDIFIER_ATTR_CURRENT_HUMIDITY,
DOMAIN as HUMIDIFIER_DOMAIN,
)
from homeassistant.components.number import DOMAIN as NUMBER_DOMAIN, NumberDeviceClass
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN, SensorDeviceClass
from homeassistant.const import PERCENTAGE
from homeassistant.core import HomeAssistant
from homeassistant.helpers.automation import DomainSpec, NumericalDomainSpec
from homeassistant.helpers.condition import Condition, make_entity_numerical_condition

HUMIDITY_DOMAIN_SPECS = {
CLIMATE_DOMAIN: NumericalDomainSpec(
value_source=CLIMATE_ATTR_CURRENT_HUMIDITY,
),
HUMIDIFIER_DOMAIN: NumericalDomainSpec(
value_source=HUMIDIFIER_ATTR_CURRENT_HUMIDITY,
),
SENSOR_DOMAIN: DomainSpec(device_class=SensorDeviceClass.HUMIDITY),
NUMBER_DOMAIN: DomainSpec(device_class=NumberDeviceClass.HUMIDITY),
}

CONDITIONS: dict[str, type[Condition]] = {
"value": make_entity_numerical_condition(HUMIDITY_DOMAIN_SPECS, PERCENTAGE),
}
Comment thread
justanotherariel marked this conversation as resolved.


async def async_get_conditions(hass: HomeAssistant) -> dict[str, type[Condition]]:
"""Return the conditions for humidity."""
return CONDITIONS
43 changes: 43 additions & 0 deletions homeassistant/components/humidity/conditions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
.number_or_entity: &number_or_entity
required: false
selector:
choose:
choices:
number:
selector:
number:
mode: box
unit_of_measurement: "%"
entity:
selector:
entity:
filter:
- domain: input_number
unit_of_measurement: "%"
- domain: number
device_class: humidity
- domain: sensor
device_class: humidity
translation_key: number_or_entity

value:
target:
entity:
- domain: sensor
device_class: humidity
- domain: number
device_class: humidity
- domain: climate
- domain: humidifier
fields:
behavior:
required: true
default: any
selector:
select:
translation_key: condition_behavior
options:
- all
- any
above: *number_or_entity
below: *number_or_entity
5 changes: 5 additions & 0 deletions homeassistant/components/humidity/icons.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"conditions": {
"value": {
"condition": "mdi:water-percent"
}
},
"triggers": {
"changed": {
"trigger": "mdi:water-percent"
Expand Down
28 changes: 28 additions & 0 deletions homeassistant/components/humidity/strings.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,37 @@
{
"common": {
"condition_behavior_description": "How the state should match on the targeted entities.",
"condition_behavior_name": "Behavior",
"trigger_behavior_description": "The behavior of the targeted entities to trigger on.",
"trigger_behavior_name": "Behavior"
},
"conditions": {
"value": {
"description": "Tests if a relative humidity value is above a threshold, below a threshold, or in a range of values.",
"fields": {
"above": {
"description": "Require the relative humidity to be above this value.",
"name": "Above"
},
"behavior": {
"description": "[%key:component::humidity::common::condition_behavior_description%]",
"name": "[%key:component::humidity::common::condition_behavior_name%]"
},
"below": {
"description": "Require the relative humidity to be below this value.",
"name": "Below"
}
},
"name": "Relative humidity"
}
},
"selector": {
"condition_behavior": {
"options": {
"all": "All",
"any": "Any"
}
},
"number_or_entity": {
"choices": {
"entity": "Entity",
Expand Down
Loading
Loading