Skip to content

Commit ea978fe

Browse files
authored
[boschshc] Provide alarm channel for smoke detectors (openhab#18194)
Signed-off-by: David Pace <[email protected]>
1 parent 28ce3c2 commit ea978fe

19 files changed

+448
-51
lines changed

bundles/org.openhab.binding.boschshc/README.md

+19-15
Original file line numberDiff line numberDiff line change
@@ -284,34 +284,38 @@ A smart bulb connected to the bridge via Zigbee such as a Ledvance Smart+ bulb.
284284

285285
**Thing Type ID**: `smart-bulb`
286286

287-
| Channel Type ID | Item Type | Writable | Description |
288-
| ----------------| --------- | :------: | -------------------------------------------------------------- |
289-
| power-switch | Switch | &#9745; | Switches the light on or off. |
290-
| brightness | Dimmer | &#9745; | Regulates the brightness on a percentage scale from 0 to 100%. |
291-
| color | Color | &#9745; | The color of the emitted light. |
287+
| Channel Type ID | Item Type | Writable | Description |
288+
| ---------------- | --------- | :------: | -------------------------------------------------------------- |
289+
| power-switch | Switch | &#9745; | Switches the light on or off. |
290+
| brightness | Dimmer | &#9745; | Regulates the brightness on a percentage scale from 0 to 100%. |
291+
| color | Color | &#9745; | The color of the emitted light. |
292292

293293
### Smoke Detector
294294

295295
The smoke detector warns you in case of fire.
296296

297297
**Thing Type ID**: `smoke-detector`
298298

299-
| Channel Type ID | Item Type | Writable | Description |
300-
| ------------------ | -------------------- | :------: | ------------------------------------------------------------------------------------------------- |
301-
| smoke-check | String | &#9745; | State of the smoke check. Also used to request a new smoke check. |
299+
| Channel Type ID | Item Type | Writable | Description |
300+
| ---------------- | --------- | :------: | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
301+
| alarm | String | &#9745; | Alarm state of the smoke detector. Possible values to read are: `IDLE_OFF`, `PRIMARY_ALARM`, `SECONDARY_ALARM` and `INTRUSION_ALARM`. Possible values to write are: `INTRUSION_ALARM_ON_REQUESTED` and `INTRUSION_ALARM_OFF_REQUESTED`. |
302+
| smoke-check | String | &#9745; | State of the smoke check. Also used to request a new smoke check. |
303+
| battery-level | Number | &#9744; | Current battery level percentage as integer number. Bosch-specific battery levels are mapped to numbers as follows: `OK`: 100, `LOW_BATTERY`: 10, `CRITICAL_LOW`: 1, `CRITICALLY_LOW_BATTERY`: 1, `NOT_AVAILABLE`: `UNDEF`. |
304+
| low-battery | Switch | &#9744; | Indicates whether the battery is low (`ON`) or OK (`OFF`). |
302305

303306
### Smoke Detector II
304307

305308
The smoke detector warns you in case of fire.
306309

307-
**Thing Type ID**: `smoke-detector`
310+
**Thing Type ID**: `smoke-detector-2`
308311

309-
| Channel Type ID | Item Type | Writable | Description |
310-
|-------------------|-------------| :------: |-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
311-
| smoke-check | String | &#9745; | State of the smoke check. Also used to request a new smoke check. |
312-
| battery-level | Number | &#9744; | Current battery level percentage as integer number. Bosch-specific battery levels are mapped to numbers as follows: `OK`: 100, `LOW_BATTERY`: 10, `CRITICAL_LOW`: 1, `CRITICALLY_LOW_BATTERY`: 1, `NOT_AVAILABLE`: `UNDEF`. |
313-
| low-battery | Switch | &#9744; | Indicates whether the battery is low (`ON`) or OK (`OFF`). |
314-
| signal-strength | Number | &#9744; | Communication quality between the device and the Smart Home Controller. Possible values range between 0 (unknown) and 4 (best signal strength). |
312+
| Channel Type ID | Item Type | Writable | Description |
313+
| --------------- | --------- | :------: | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
314+
| alarm | String | &#9745; | Alarm state of the smoke detector. Possible values to read are: `IDLE_OFF`, `PRIMARY_ALARM`, `SECONDARY_ALARM` and `INTRUSION_ALARM`. Possible values to write are: `INTRUSION_ALARM_ON_REQUESTED` and `INTRUSION_ALARM_OFF_REQUESTED`. |
315+
| smoke-check | String | &#9745; | State of the smoke check. Also used to request a new smoke check. |
316+
| battery-level | Number | &#9744; | Current battery level percentage as integer number. Bosch-specific battery levels are mapped to numbers as follows: `OK`: 100, `LOW_BATTERY`: 10, `CRITICAL_LOW`: 1, `CRITICALLY_LOW_BATTERY`: 1, `NOT_AVAILABLE`: `UNDEF`. |
317+
| low-battery | Switch | &#9744; | Indicates whether the battery is low (`ON`) or OK (`OFF`). |
318+
| signal-strength | Number | &#9744; | Communication quality between the device and the Smart Home Controller. Possible values range between 0 (unknown) and 4 (best signal strength). |
315319

316320
### User-defined States
317321

bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/console/BoschShcCommandExtension.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ public BoschShcCommandExtension(final @Reference ThingRegistry thingRegistry) {
8181
* <code>src/main/java/org/openhab/binding/boschshc/internal/services</code>.
8282
*/
8383
List<String> getAllBoschShcServices() {
84-
return List.of("airqualitylevel", "batterylevel", "binaryswitch", "bypass", "cameranotification", "childlock",
85-
"childprotection", "communicationquality", "hsbcoloractuator", "humiditylevel", "illuminance",
86-
"impulseswitch", "intrusion", "keypad", "latestmotion", "multilevelswitch", "powermeter", "powerswitch",
87-
"privacymode", "roomclimatecontrol", "shuttercontact", "shuttercontrol", "silentmode",
84+
return List.of("airqualitylevel", "alarm", "batterylevel", "binaryswitch", "bypass", "cameranotification",
85+
"childlock", "childprotection", "communicationquality", "hsbcoloractuator", "humiditylevel",
86+
"illuminance", "impulseswitch", "intrusion", "keypad", "latestmotion", "multilevelswitch", "powermeter",
87+
"powerswitch", "privacymode", "roomclimatecontrol", "shuttercontact", "shuttercontrol", "silentmode",
8888
"smokedetectorcheck", "temperaturelevel", "userstate", "valvetappet", "waterleakagesensor",
8989
"waterleakagesensorcheck", "waterleakagesensortilt");
9090
}

bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/devices/AbstractSmokeDetectorHandler.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,8 @@ protected void initializeServices() throws BoschSHCException {
5252
public void handleCommand(ChannelUID channelUID, Command command) {
5353
super.handleCommand(channelUID, command);
5454

55-
switch (channelUID.getId()) {
56-
case CHANNEL_SMOKE_CHECK:
57-
this.handleServiceCommand(this.smokeDetectorCheckService, command);
58-
break;
55+
if (CHANNEL_SMOKE_CHECK.equals(channelUID.getId())) {
56+
this.handleServiceCommand(this.smokeDetectorCheckService, command);
5957
}
6058
}
6159

bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/devices/BoschSHCBindingConstants.java

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ private BoschSHCBindingConstants() {
116116
public static final String CHANNEL_IMPULSE_SWITCH = "impulse-switch";
117117
public static final String CHANNEL_IMPULSE_LENGTH = "impulse-length";
118118
public static final String CHANNEL_INSTANT_OF_LAST_IMPULSE = "instant-of-last-impulse";
119+
public static final String CHANNEL_ALARM = "alarm";
119120
// numbered channels
120121
// the rationale for introducing numbered channels was discussed in
121122
// https://github.com/openhab/openhab-addons/pull/16400
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright (c) 2010-2025 Contributors to the openHAB project
3+
*
4+
* See the NOTICE file(s) distributed with this work for additional
5+
* information.
6+
*
7+
* This program and the accompanying materials are made available under the
8+
* terms of the Eclipse Public License 2.0 which is available at
9+
* http://www.eclipse.org/legal/epl-2.0
10+
*
11+
* SPDX-License-Identifier: EPL-2.0
12+
*/
13+
package org.openhab.binding.boschshc.internal.devices.smokedetector;
14+
15+
import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.CHANNEL_ALARM;
16+
17+
import java.util.List;
18+
19+
import org.eclipse.jdt.annotation.NonNullByDefault;
20+
import org.openhab.binding.boschshc.internal.devices.AbstractSmokeDetectorHandler;
21+
import org.openhab.binding.boschshc.internal.exceptions.BoschSHCException;
22+
import org.openhab.binding.boschshc.internal.services.alarm.AlarmService;
23+
import org.openhab.binding.boschshc.internal.services.alarm.dto.AlarmServiceState;
24+
import org.openhab.core.library.types.StringType;
25+
import org.openhab.core.thing.ChannelUID;
26+
import org.openhab.core.thing.Thing;
27+
import org.openhab.core.types.Command;
28+
29+
/**
30+
* Abstract handler for smoke detectors that have an <code>Alarm</code> service.
31+
* <p>
32+
* Note that this includes Smoke Detector and Smoke Detector II, but not Twinguard.
33+
*
34+
* @author David Pace - Initial contribution
35+
*
36+
*/
37+
@NonNullByDefault
38+
public abstract class AbstractSmokeDetectorHandlerWithAlarmService extends AbstractSmokeDetectorHandler {
39+
40+
private AlarmService alarmService;
41+
42+
protected AbstractSmokeDetectorHandlerWithAlarmService(Thing thing) {
43+
super(thing);
44+
this.alarmService = new AlarmService();
45+
}
46+
47+
@Override
48+
protected void initializeServices() throws BoschSHCException {
49+
super.initializeServices();
50+
51+
this.registerService(alarmService, this::updateChannels, List.of(CHANNEL_ALARM));
52+
}
53+
54+
private void updateChannels(AlarmServiceState state) {
55+
updateState(CHANNEL_ALARM, new StringType(state.value.toString()));
56+
}
57+
58+
@Override
59+
public void handleCommand(ChannelUID channelUID, Command command) {
60+
super.handleCommand(channelUID, command);
61+
62+
if (CHANNEL_ALARM.equals(channelUID.getId())) {
63+
this.handleServiceCommand(this.alarmService, command);
64+
}
65+
}
66+
}

bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/devices/smokedetector/SmokeDetector2Handler.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import java.util.List;
1818

1919
import org.eclipse.jdt.annotation.NonNullByDefault;
20-
import org.openhab.binding.boschshc.internal.devices.AbstractSmokeDetectorHandler;
2120
import org.openhab.binding.boschshc.internal.exceptions.BoschSHCException;
2221
import org.openhab.binding.boschshc.internal.services.communicationquality.CommunicationQualityService;
2322
import org.openhab.binding.boschshc.internal.services.communicationquality.dto.CommunicationQualityServiceState;
@@ -29,7 +28,7 @@
2928
* @author Patrick Gell - Initial contribution
3029
*/
3130
@NonNullByDefault
32-
public class SmokeDetector2Handler extends AbstractSmokeDetectorHandler {
31+
public class SmokeDetector2Handler extends AbstractSmokeDetectorHandlerWithAlarmService {
3332

3433
public SmokeDetector2Handler(Thing thing) {
3534
super(thing);

bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/devices/smokedetector/SmokeDetectorHandler.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
package org.openhab.binding.boschshc.internal.devices.smokedetector;
1414

1515
import org.eclipse.jdt.annotation.NonNullByDefault;
16-
import org.openhab.binding.boschshc.internal.devices.AbstractSmokeDetectorHandler;
1716
import org.openhab.core.thing.Thing;
1817

1918
/**
@@ -23,7 +22,7 @@
2322
* @author Gerd Zanker - AbstractSmokeDetectorHandler refactoring for reuse
2423
*/
2524
@NonNullByDefault
26-
public class SmokeDetectorHandler extends AbstractSmokeDetectorHandler {
25+
public class SmokeDetectorHandler extends AbstractSmokeDetectorHandlerWithAlarmService {
2726

2827
public SmokeDetectorHandler(Thing thing) {
2928
super(thing);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) 2010-2025 Contributors to the openHAB project
3+
*
4+
* See the NOTICE file(s) distributed with this work for additional
5+
* information.
6+
*
7+
* This program and the accompanying materials are made available under the
8+
* terms of the Eclipse Public License 2.0 which is available at
9+
* http://www.eclipse.org/legal/epl-2.0
10+
*
11+
* SPDX-License-Identifier: EPL-2.0
12+
*/
13+
package org.openhab.binding.boschshc.internal.services.alarm;
14+
15+
import org.eclipse.jdt.annotation.NonNullByDefault;
16+
import org.openhab.binding.boschshc.internal.exceptions.BoschSHCException;
17+
import org.openhab.binding.boschshc.internal.services.BoschSHCService;
18+
import org.openhab.binding.boschshc.internal.services.alarm.dto.AlarmServiceState;
19+
import org.openhab.binding.boschshc.internal.services.alarm.dto.AlarmState;
20+
import org.openhab.core.library.types.StringType;
21+
import org.openhab.core.types.Command;
22+
23+
/**
24+
* Alarm service for smoke detectors.
25+
*
26+
* @author David Pace - Initial contribution
27+
*
28+
*/
29+
@NonNullByDefault
30+
public class AlarmService extends BoschSHCService<AlarmServiceState> {
31+
public AlarmService() {
32+
super("Alarm", AlarmServiceState.class);
33+
}
34+
35+
@Override
36+
public AlarmServiceState handleCommand(Command command) throws BoschSHCException {
37+
if (command instanceof StringType stringCommand) {
38+
AlarmServiceState state = new AlarmServiceState();
39+
state.value = AlarmState.from(stringCommand.toFullString());
40+
return state;
41+
}
42+
return super.handleCommand(command);
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) 2010-2025 Contributors to the openHAB project
3+
*
4+
* See the NOTICE file(s) distributed with this work for additional
5+
* information.
6+
*
7+
* This program and the accompanying materials are made available under the
8+
* terms of the Eclipse Public License 2.0 which is available at
9+
* http://www.eclipse.org/legal/epl-2.0
10+
*
11+
* SPDX-License-Identifier: EPL-2.0
12+
*/
13+
package org.openhab.binding.boschshc.internal.services.alarm.dto;
14+
15+
import org.openhab.binding.boschshc.internal.services.dto.BoschSHCServiceState;
16+
17+
/**
18+
* State for alarm services of smoke detectors.
19+
*
20+
* @author David Pace - Initial contribution
21+
*
22+
*/
23+
public class AlarmServiceState extends BoschSHCServiceState {
24+
public AlarmServiceState() {
25+
super("alarmState");
26+
}
27+
28+
public AlarmState value;
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) 2010-2025 Contributors to the openHAB project
3+
*
4+
* See the NOTICE file(s) distributed with this work for additional
5+
* information.
6+
*
7+
* This program and the accompanying materials are made available under the
8+
* terms of the Eclipse Public License 2.0 which is available at
9+
* http://www.eclipse.org/legal/epl-2.0
10+
*
11+
* SPDX-License-Identifier: EPL-2.0
12+
*/
13+
package org.openhab.binding.boschshc.internal.services.alarm.dto;
14+
15+
import org.slf4j.Logger;
16+
import org.slf4j.LoggerFactory;
17+
18+
/**
19+
* Possible states of smoke detector alarms.
20+
*
21+
* @author David Pace - Initial contribution
22+
*
23+
*/
24+
public enum AlarmState {
25+
IDLE_OFF,
26+
PRIMARY_ALARM,
27+
SECONDARY_ALARM,
28+
INTRUSION_ALARM,
29+
INTRUSION_ALARM_ON_REQUESTED,
30+
INTRUSION_ALARM_OFF_REQUESTED;
31+
32+
private static final Logger LOGGER = LoggerFactory.getLogger(AlarmState.class);
33+
34+
public static AlarmState from(String identifier) {
35+
try {
36+
return valueOf(identifier);
37+
} catch (IllegalArgumentException e) {
38+
LOGGER.warn("Unsupported alarm state: {}", identifier);
39+
return IDLE_OFF;
40+
}
41+
}
42+
}

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

+8
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ channel-type.boschshc.alarm-state.state.option.PRE_ALARM = Alarm is about to go
8484
channel-type.boschshc.alarm-state.state.option.ALARM_ON = Alarm was triggered
8585
channel-type.boschshc.alarm-state.state.option.ALARM_MUTED = Alarm is muted
8686
channel-type.boschshc.alarm-state.state.option.UNKNOWN = Alarm status is unknown
87+
channel-type.boschshc.alarm.label = Alarm
88+
channel-type.boschshc.alarm.description = Alarm state of the smoke detector.
89+
channel-type.boschshc.alarm.state.option.IDLE_OFF = Alarm off
90+
channel-type.boschshc.alarm.state.option.PRIMARY_ALARM = Primary alarm
91+
channel-type.boschshc.alarm.state.option.SECONDARY_ALARM = Secondary alarm
92+
channel-type.boschshc.alarm.state.option.INTRUSION_ALARM = Intrusion alarm
93+
channel-type.boschshc.alarm.state.option.INTRUSION_ALARM_ON_REQUESTED = Intrusion alarm on requested
94+
channel-type.boschshc.alarm.state.option.INTRUSION_ALARM_OFF_REQUESTED = Intrusion alarm off requested
8795
channel-type.boschshc.arm-action.label = Arm Action
8896
channel-type.boschshc.arm-action.description = Arms the intrusion detection system using the given profile ID.
8997
channel-type.boschshc.arming-state.label = Arming State

bundles/org.openhab.binding.boschshc/src/main/resources/OH-INF/thing/thing-types.xml

+27
Original file line numberDiff line numberDiff line change
@@ -344,11 +344,16 @@
344344
<description>The smoke detector warns you in case of fire.</description>
345345

346346
<channels>
347+
<channel id="alarm" typeId="alarm"/>
347348
<channel id="smoke-check" typeId="smoke-check"/>
348349
<channel id="battery-level" typeId="system.battery-level"/>
349350
<channel id="low-battery" typeId="system.low-battery"/>
350351
</channels>
351352

353+
<properties>
354+
<property name="thingTypeVersion">1</property>
355+
</properties>
356+
352357
<config-description-ref uri="thing-type:boschshc:device"/>
353358
</thing-type>
354359

@@ -412,12 +417,17 @@
412417
<description>The smoke detector warns you in case of fire.</description>
413418

414419
<channels>
420+
<channel id="alarm" typeId="alarm"/>
415421
<channel id="smoke-check" typeId="smoke-check"/>
416422
<channel id="battery-level" typeId="system.battery-level"/>
417423
<channel id="low-battery" typeId="system.low-battery"/>
418424
<channel id="signal-strength" typeId="system.signal-strength"/>
419425
</channels>
420426

427+
<properties>
428+
<property name="thingTypeVersion">1</property>
429+
</properties>
430+
421431
<config-description-ref uri="thing-type:boschshc:device"/>
422432
</thing-type>
423433

@@ -887,4 +897,21 @@
887897
<state readOnly="true"/>
888898
</channel-type>
889899

900+
<channel-type id="alarm">
901+
<item-type>String</item-type>
902+
<label>Alarm</label>
903+
<description>Alarm state of the smoke detector.</description>
904+
<category>Alarm</category>
905+
<state readOnly="false">
906+
<options>
907+
<option value="IDLE_OFF">Alarm off</option>
908+
<option value="PRIMARY_ALARM">Primary alarm</option>
909+
<option value="SECONDARY_ALARM">Secondary alarm</option>
910+
<option value="INTRUSION_ALARM">Intrusion alarm</option>
911+
<option value="INTRUSION_ALARM_ON_REQUESTED">Intrusion alarm on requested</option>
912+
<option value="INTRUSION_ALARM_OFF_REQUESTED">Intrusion alarm off requested</option>
913+
</options>
914+
</state>
915+
</channel-type>
916+
890917
</thing:thing-descriptions>

0 commit comments

Comments
 (0)