Skip to content

Commit 436bbdc

Browse files
authored
[hue] Support API v2 motion and light sensor groups (openhab#20380)
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
1 parent caa0c18 commit 436bbdc

5 files changed

Lines changed: 155 additions & 22 deletions

File tree

bundles/org.openhab.binding.hue/doc/readme_v2.md

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,25 @@ A positive number means the dial was rotated clock-wise, whereas a negative numb
153153
Room and Zone things allow you to control the lights in a given zone or room.
154154
They support the following channels:
155155

156-
| Channel ID | Item Type | Description |
157-
|---------------------|--------------------|-----------------------------------------------------------------------------------|
158-
| brightness | Dimmer | Supports adjusting the brightness or switching the lights on and off. |
159-
| switch | Switch | Supports switching the lights on and off. |
160-
| scene<sup>1)</sup> | String | Setting the string to a valid scene friendly name activates the respective scene. |
161-
| dynamics | Number:Time | The duration of dynamic transitions between light or scene states. |
162-
| alert<sup>1)</sup> | String | This channel allows setting an alert on the lights e.g. flashing them. |
163-
164-
<sup>1)</sup> The scene and alert channels are optional.
165-
If the respective room or zone has no scenes or alerts associated with it, the respective channel will not be shown.
156+
| Channel ID | Item Type | Description |
157+
|--------------------------|--------------------|------------------------------------------------------------------------------------------------------|
158+
| brightness | Dimmer | Supports adjusting the brightness or switching the lights on and off. |
159+
| switch | Switch | Supports switching the lights on and off. |
160+
| scene | String | Setting the string to a valid scene friendly name activates the respective scene. |
161+
| dynamics | Number:Time | The duration of dynamic transitions between light or scene states. |
162+
| alert | String | This channel allows setting an alert on the lights e.g. flashing them. |
163+
| dimming-only | Dimmer | Allows access to the `dimming` parameter of the light(s) only. Has no impact on `on-off` parameter. |
164+
| on-off-only | Switch | Allows access to the `on-off` parameter of the light(s) only. Has no impact on `dimming` parameter. |
165+
| motion | Switch | Shows if motion has been detected by any of the sensors in the group. (Read Only) |
166+
| motion-enabled | Switch | Supports enabling / disabling the grouped motion sensor. (Advanced) |
167+
| motion-last-updated | DateTime | The date and time when the grouped motion value was last updated. (Read Only) (Advanced) |
168+
| light-level | Number:Illuminance | Shows the current amalgamated light level measured by the sensors in the group. (Read Only) |
169+
| light-level-last-updated | DateTime | The date and time when the grouped light level was last updated. (Read Only) (Advanced) |
170+
| light-level-enabled | Switch | Supports enabling / disabling the grouped light level sensor. (Advanced) |
171+
172+
The exact list of channels in a given room or zone is determined at run time when the system is started.
173+
Each room or zone reports its own live list of capabilities, and the respective list of channels is created accordingly.
174+
The channels `dimming-only` and `on-off-only` are _advanced_ channels - see [below](#advanced-channels-for-devices-rooms-and-zones) for more details.
166175

167176
### Channels for MotionAware™ Areas
168177

bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/handler/Clip2ThingHandler.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,11 +463,17 @@ public void handleCommand(ChannelUID channelUID, Command commandParam) {
463463
break;
464464

465465
case CHANNEL_2_MOTION_ENABLED:
466-
putResource = new Resource(getExtendedResourceType(ResourceType.MOTION)).setEnabled(command);
466+
ResourceType motionType = thisResource.getType() == ResourceType.DEVICE //
467+
? getExtendedResourceType(ResourceType.MOTION)
468+
: ResourceType.GROUPED_MOTION;
469+
putResource = new Resource(motionType).setEnabled(command);
467470
break;
468471

469472
case CHANNEL_2_LIGHT_LEVEL_ENABLED:
470-
putResource = new Resource(ResourceType.LIGHT_LEVEL).setEnabled(command);
473+
ResourceType lightLevelType = thisResource.getType() == ResourceType.DEVICE //
474+
? ResourceType.LIGHT_LEVEL
475+
: ResourceType.GROUPED_LIGHT_LEVEL;
476+
putResource = new Resource(lightLevelType).setEnabled(command);
471477
break;
472478

473479
case CHANNEL_2_SECURITY_CONTACT_ENABLED:
@@ -1080,6 +1086,7 @@ private boolean updateChannels(Resource resource) {
10801086
updateState(CHANNEL_2_ALERT, resource.getAlertState(), fullUpdate);
10811087
break;
10821088

1089+
case GROUPED_LIGHT_LEVEL:
10831090
case LIGHT_LEVEL:
10841091
updateState(CHANNEL_2_LIGHT_LEVEL, resource.getLightLevelState(), fullUpdate);
10851092
updateState(CHANNEL_2_LIGHT_LEVEL_LAST_UPDATED, resource.getLightLevelLastUpdatedState(), fullUpdate);
@@ -1107,6 +1114,7 @@ private boolean updateChannels(Resource resource) {
11071114
updateState(CHANNEL_2_MOTION_AREA_ENABLED, resource.getEnabledState(), fullUpdate);
11081115
break;
11091116

1117+
case GROUPED_MOTION:
11101118
case MOTION:
11111119
updateState(CHANNEL_2_MOTION, resource.getMotionState(), fullUpdate);
11121120
updateState(CHANNEL_2_MOTION_LAST_UPDATED, resource.getMotionLastUpdatedState(), fullUpdate);

bundles/org.openhab.binding.hue/src/main/resources/OH-INF/i18n/hue.properties

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,33 @@ thing-type.hue.geofencesensor.label = Geofence Sensor
8585
thing-type.hue.geofencesensor.description = A sensor providing geofence based presence detection.
8686
thing-type.hue.group.label = Hue Group
8787
thing-type.hue.group.description = A group of lights or a room that could be switched on and off.
88-
thing-type.hue.room.label = Hue Room Light Group
89-
thing-type.hue.room.description = A group of Hue API v2 lights that are located in a single room.
88+
thing-type.hue.room.label = Hue Room Group
89+
thing-type.hue.room.description = A group of Hue API v2 equipment that are located in a single room.
9090
thing-type.hue.room.channel.alert.description = Activate the alert for the group of lights in the room.
9191
thing-type.hue.room.channel.brightness.description = Controls the brightness and switches on/off the group of lights in the room.
9292
thing-type.hue.room.channel.dimming-only.description = Set the dimming parameter of the group of lights in the room without changing other state parameters.
93+
thing-type.hue.room.channel.light-level.description = Current light level.
94+
thing-type.hue.room.channel.light-level-enabled.description = Light level sensor enabled.
95+
thing-type.hue.room.channel.light-level-last-updated.label = Light Level Last Updated
96+
thing-type.hue.room.channel.light-level-last-updated.description = The date and time when the light level was last updated.
97+
thing-type.hue.room.channel.motion-enabled.description = Motion sensor enabled.
98+
thing-type.hue.room.channel.motion-last-updated.label = Motion Last Updated
99+
thing-type.hue.room.channel.motion-last-updated.description = The date and time when the motion value was last updated.
93100
thing-type.hue.room.channel.on-off-only.description = Set the on/off parameter of the group of lights in the room without changing other state parameters.
94101
thing-type.hue.room.channel.scene.description = Activate the scene for the group of lights in the room.
95102
thing-type.hue.room.channel.switch.description = Switch on/off the group of lights in the room.
96-
thing-type.hue.zone.label = Hue Zone Light Group
97-
thing-type.hue.zone.description = A group of Hue API v2 lights that are located in a zone.
103+
thing-type.hue.zone.label = Hue Zone Group
104+
thing-type.hue.zone.description = A group of Hue API v2 equipment that are located in a zone.
98105
thing-type.hue.zone.channel.alert.description = Activate the alert for the group of lights in the zone.
99106
thing-type.hue.zone.channel.brightness.description = Controls the brightness and switches on/off the group of lights in the zone.
100107
thing-type.hue.zone.channel.dimming-only.description = Set the dimming parameter of the group of lights in the zone without changing other state parameters.
108+
thing-type.hue.zone.channel.light-level.description = Current light level.
109+
thing-type.hue.zone.channel.light-level-enabled.description = Light level sensor enabled.
110+
thing-type.hue.zone.channel.light-level-last-updated.label = Light Level Last Updated
111+
thing-type.hue.zone.channel.light-level-last-updated.description = The date and time when the light level was last updated.
112+
thing-type.hue.zone.channel.motion-enabled.description = Motion sensor enabled.
113+
thing-type.hue.zone.channel.motion-last-updated.label = Motion Last Updated
114+
thing-type.hue.zone.channel.motion-last-updated.description = The date and time when the motion value was last updated.
101115
thing-type.hue.zone.channel.on-off-only.description = Set the on/off parameter of the group of lights in the zone without changing other state parameters.
102116
thing-type.hue.zone.channel.scene.description = Activate the scene for the group of lights in the zone.
103117
thing-type.hue.zone.channel.switch.description = Switch on/off the group of lights in the zone.
@@ -347,7 +361,7 @@ actionDesc = Send a light command with a custom fade time.
347361

348362
# discovery results
349363

350-
discovery.group.all-lights.label = All lights
364+
discovery.group.all-lights.label = All equipment
351365

352366
# api v2 dynamic actions
353367

bundles/org.openhab.binding.hue/src/main/resources/OH-INF/thing/Clip2Thing.xml

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@
134134
<bridge-type-ref id="bridge-api2"/>
135135
</supported-bridge-type-refs>
136136

137-
<label>Hue Room Light Group</label>
138-
<description>A group of Hue API v2 lights that are located in a single room.</description>
137+
<label>Hue Room Group</label>
138+
<description>A group of Hue API v2 equipment that are located in a single room.</description>
139139

140140
<channels>
141141
<channel id="brightness" typeId="system.brightness">
@@ -160,8 +160,30 @@
160160
<description>Set the on/off parameter of the group of lights in the room without changing other state
161161
parameters.</description>
162162
</channel>
163+
<channel id="motion" typeId="system.motion"/>
164+
<channel id="motion-last-updated" typeId="last-updated-v2">
165+
<label>Motion Last Updated</label>
166+
<description>The date and time when the motion value was last updated.</description>
167+
</channel>
168+
<channel id="motion-enabled" typeId="sensor-enabled">
169+
<description>Motion sensor enabled.</description>
170+
</channel>
171+
<channel id="light-level" typeId="illuminance">
172+
<description>Current light level.</description>
173+
</channel>
174+
<channel id="light-level-last-updated" typeId="last-updated-v2">
175+
<label>Light Level Last Updated</label>
176+
<description>The date and time when the light level was last updated.</description>
177+
</channel>
178+
<channel id="light-level-enabled" typeId="sensor-enabled">
179+
<description>Light level sensor enabled.</description>
180+
</channel>
163181
</channels>
164182

183+
<properties>
184+
<property name="thingTypeVersion">1</property>
185+
</properties>
186+
165187
<representation-property>resourceId</representation-property>
166188

167189
<config-description>
@@ -179,8 +201,8 @@
179201
<bridge-type-ref id="bridge-api2"/>
180202
</supported-bridge-type-refs>
181203

182-
<label>Hue Zone Light Group</label>
183-
<description>A group of Hue API v2 lights that are located in a zone.</description>
204+
<label>Hue Zone Group</label>
205+
<description>A group of Hue API v2 equipment that are located in a zone.</description>
184206

185207
<channels>
186208
<channel id="brightness" typeId="system.brightness">
@@ -204,8 +226,30 @@
204226
<channel id="on-off-only" typeId="advanced-power">
205227
<description>Set the on/off parameter of the group of lights in the zone without changing other state parameters.</description>
206228
</channel>
229+
<channel id="motion" typeId="system.motion"/>
230+
<channel id="motion-last-updated" typeId="last-updated-v2">
231+
<label>Motion Last Updated</label>
232+
<description>The date and time when the motion value was last updated.</description>
233+
</channel>
234+
<channel id="motion-enabled" typeId="sensor-enabled">
235+
<description>Motion sensor enabled.</description>
236+
</channel>
237+
<channel id="light-level" typeId="illuminance">
238+
<description>Current light level.</description>
239+
</channel>
240+
<channel id="light-level-last-updated" typeId="last-updated-v2">
241+
<label>Light Level Last Updated</label>
242+
<description>The date and time when the light level was last updated.</description>
243+
</channel>
244+
<channel id="light-level-enabled" typeId="sensor-enabled">
245+
<description>Light level sensor enabled.</description>
246+
</channel>
207247
</channels>
208248

249+
<properties>
250+
<property name="thingTypeVersion">1</property>
251+
</properties>
252+
209253
<representation-property>resourceId</representation-property>
210254

211255
<config-description>

bundles/org.openhab.binding.hue/src/main/resources/OH-INF/update/instructions.xml

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
xsi:schemaLocation="https://openhab.org/schemas/update-description/v1.0.0 https://openhab.org/schemas/update-description-1.0.0.xsd">
55

66
<thing-type uid="hue:device">
7-
87
<instruction-set targetVersion="1">
98
<add-channel id="motion-last-updated">
109
<type>hue:last-updated-v2</type>
@@ -32,7 +31,66 @@
3231
<description>The date and time when the rotary steps were last updated.</description>
3332
</add-channel>
3433
</instruction-set>
34+
</thing-type>
35+
36+
<thing-type uid="hue:room">
37+
<instruction-set targetVersion="1">
38+
<add-channel id="motion">
39+
<type>system:motion</type>
40+
</add-channel>
41+
<add-channel id="motion-last-updated">
42+
<type>hue:last-updated-v2</type>
43+
<label>Motion Last Updated</label>
44+
<description>The date and time when the motion value was last updated.</description>
45+
</add-channel>
46+
<add-channel id="motion-enabled">
47+
<type>hue:sensor-enabled</type>
48+
<description>Motion sensor enabled.</description>
49+
</add-channel>
50+
<add-channel id="light-level">
51+
<type>hue:illuminance</type>
52+
<description>Current light level.</description>
53+
</add-channel>
54+
<add-channel id="light-level-last-updated">
55+
<type>hue:last-updated-v2</type>
56+
<label>Light Level Last Updated</label>
57+
<description>The date and time when the light level was last updated.</description>
58+
</add-channel>
59+
<add-channel id="light-level-enabled">
60+
<type>hue:sensor-enabled</type>
61+
<description>Light level sensor enabled.</description>
62+
</add-channel>
63+
</instruction-set>
64+
</thing-type>
3565

66+
<thing-type uid="hue:zone">
67+
<instruction-set targetVersion="1">
68+
<add-channel id="motion">
69+
<type>system:motion</type>
70+
</add-channel>
71+
<add-channel id="motion-last-updated">
72+
<type>hue:last-updated-v2</type>
73+
<label>Motion Last Updated</label>
74+
<description>The date and time when the motion value was last updated.</description>
75+
</add-channel>
76+
<add-channel id="motion-enabled">
77+
<type>hue:sensor-enabled</type>
78+
<description>Motion sensor enabled.</description>
79+
</add-channel>
80+
<add-channel id="light-level">
81+
<type>hue:illuminance</type>
82+
<description>Current light level.</description>
83+
</add-channel>
84+
<add-channel id="light-level-last-updated">
85+
<type>hue:last-updated-v2</type>
86+
<label>Light Level Last Updated</label>
87+
<description>The date and time when the light level was last updated.</description>
88+
</add-channel>
89+
<add-channel id="light-level-enabled">
90+
<type>hue:sensor-enabled</type>
91+
<description>Light level sensor enabled.</description>
92+
</add-channel>
93+
</instruction-set>
3694
</thing-type>
3795

3896
</update:update-descriptions>

0 commit comments

Comments
 (0)