Skip to content

Commit 3373f88

Browse files
Merge pull request #14 from andrew-codechimp/attributes
Attributes
2 parents 4142dba + 8c12c53 commit 3373f88

4 files changed

Lines changed: 40 additions & 0 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ for:
9898
seconds: 0
9999
```
100100

101+
- For advanced automations the state of the motion and door sensors are exposed as attributes within the binary sensor.
102+
101103
---
102104

103105
[commits-shield]: https://img.shields.io/github/commit-activity/y/andrew-codechimp/HA-Wasp-In-A-Box.svg?style=for-the-badge

custom_components/wasp_in_a_box/binary_sensor.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
)
2626

2727
from .const import (
28+
ATTR_DOOR_SENSOR_STATE,
29+
ATTR_MOTION_SENSOR_STATE,
2830
CONF_BOX_ID,
2931
CONF_DOOR_CLOSED_DELAY,
3032
CONF_DOOR_OPEN_TIMEOUT,
@@ -70,6 +72,7 @@ class WaspInABoxSensor(BinarySensorEntity):
7072

7173
_attr_device_class = BinarySensorDeviceClass.OCCUPANCY
7274
_attr_should_poll = False
75+
_attr_translation_key = "wasp_in_a_box"
7376
_state_had_real_change = False
7477
_wasp_state: str = STATE_UNKNOWN
7578
_box_state: str = STATE_UNKNOWN
@@ -179,6 +182,14 @@ def is_on(self) -> bool | None:
179182
# Convert state to boolean - "on" means occupied
180183
return self._state == STATE_ON
181184

185+
@property
186+
def extra_state_attributes(self) -> dict[str, str]:
187+
"""Return state attributes."""
188+
return {
189+
ATTR_MOTION_SENSOR_STATE: self._wasp_state,
190+
ATTR_DOOR_SENSOR_STATE: self._box_state,
191+
}
192+
182193
@callback
183194
def _async_wasp_state_listener(self, event: Event[EventStateChangedData]) -> None:
184195
"""Handle the wasp sensor state changes."""

custom_components/wasp_in_a_box/const.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@
2121
DEFAULT_DOOR_CLOSED_DELAY = 30
2222
DEFAULT_OPEN_DOOR_TIMEOUT = 300
2323
DEFAULT_IMMEDIATE_ON = True
24+
25+
ATTR_MOTION_SENSOR_STATE = "motion_sensor_state"
26+
ATTR_DOOR_SENSOR_STATE = "door_sensor_state"

custom_components/wasp_in_a_box/translations/en.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,29 @@
4141
}
4242
}
4343
}
44+
},
45+
"entity": {
46+
"binary_sensor": {
47+
"wasp_in_a_box": {
48+
"state_attributes": {
49+
"motion_sensor_state": {
50+
"name": "Motion sensor state",
51+
"state": {
52+
"on": "Motion detected",
53+
"off": "No motion",
54+
"unknown": "Unknown"
55+
}
56+
},
57+
"door_sensor_state": {
58+
"name": "Door sensor state",
59+
"state": {
60+
"on": "Open",
61+
"off": "Closed",
62+
"unknown": "Unknown"
63+
}
64+
}
65+
}
66+
}
67+
}
4468
}
4569
}

0 commit comments

Comments
 (0)