Skip to content

Commit e3cf7da

Browse files
Konstantin Sinitsynclaude
andcommitted
OpenHAB-MQTT esp32 & Arduino: add Night arm mode, fix PGM topic space
Propagates the PR taligentx#362 / taligentx#363 fixes (which upstream only applied to the esp8266 example) to the esp32 and Arduino OpenHAB-MQTT examples for consistency: armed-night ("1N") support plus armed-mode channel, and the PGM state-topic corrections ("dsc/Get/PGM 1"/"PGM 8" -> "PGM1"/"PGM8"). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 7279574 commit e3cf7da

2 files changed

Lines changed: 38 additions & 4 deletions

File tree

examples/Arduino/OpenHAB-MQTT/OpenHAB-MQTT.ino

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,16 @@ Bridge mqtt:broker:mymqtt "My MQTT" [host="MQTT broker IP address or hostname"]
2929
3030
Thing mqtt:topic:mymqtt:dsc "DSC Security System" (mqtt:broker:mymqtt) @ "Home" {
3131
Channels:
32+
Type string : partition1_armed_mode "Alarm Armed Mode" [stateTopic="dsc/Get/Partition1", commandTopic="dsc/Set"]
3233
Type switch : partition1_armed_away "Partition 1 Armed Away" [stateTopic="dsc/Get/Partition1", commandTopic="dsc/Set", on="1A", off="1D"]
3334
Type switch : partition1_armed_stay "Partition 1 Armed Stay" [stateTopic="dsc/Get/Partition1", commandTopic="dsc/Set", on="1S", off="1D"]
35+
Type switch : partition1_armed_night "Partition 1 Armed Night" [stateTopic="dsc/Get/Partition1", commandTopic="dsc/Set", on="1N", off="1D"]
3436
Type switch : partition1_alarm "Partition 1 Alarm" [stateTopic="dsc/Get/Partition1", on="1T", off="1D"]
3537
Type switch : partition1_fire "Partition 1 Fire" [stateTopic="dsc/Get/Fire1", on="1", off="0"]
3638
Type switch : panel_online "Panel Online" [stateTopic="dsc/Status", on="online", off="offline"]
3739
Type switch : panel_trouble "Panel Trouble" [stateTopic="dsc/Get/Trouble", on="1", off="0"]
38-
Type switch : pgm1 "PGM 1" [stateTopic="dsc/Get/PGM 1", on="1", off="0"]
39-
Type switch : pgm8 "PGM 8" [stateTopic="dsc/Get/PGM 8", on="1", off="0"]
40+
Type switch : pgm1 "PGM 1" [stateTopic="dsc/Get/PGM1", on="1", off="0"]
41+
Type switch : pgm8 "PGM 8" [stateTopic="dsc/Get/PGM8", on="1", off="0"]
4042
Type contact : zone1 "Zone 1" [stateTopic="dsc/Get/Zone1", on="1", off="0"]
4143
Type contact : zone2 "Zone 2" [stateTopic="dsc/Get/Zone2", on="1", off="0"]
4244
Type contact : zone3 "Zone 3" [stateTopic="dsc/Get/Zone3", on="1", off="0"]
@@ -45,8 +47,10 @@ Thing mqtt:topic:mymqtt:dsc "DSC Security System" (mqtt:broker:mymqtt) @ "Home"
4547
* 3. Create an "items" file for the security system as (OpenHAB configuration directory)/items/dsc.items:
4648
* - https://www.openhab.org/docs/configuration/items.html
4749
50+
String partition1_armed_mode "Armed Mode" {channel="mqtt:topic:mymqtt:dsc:partition1_armed_mode"}
4851
Switch partition1_armed_away "Partition 1 Armed Away" <shield> {channel="mqtt:topic:mymqtt:dsc:partition1_armed_away"}
4952
Switch partition1_armed_stay "Partition 1 Armed Stay" <shield> {channel="mqtt:topic:mymqtt:dsc:partition1_armed_stay"}
53+
Switch partition1_armed_night "Partition 1 Armed Night" <shield> {channel="mqtt:topic:mymqtt:dsc:partition1_armed_night"}
5054
Switch partition1_triggered "Partition 1 Alarm" <alarm> {channel="mqtt:topic:mymqtt:dsc:partition1_alarm"}
5155
Switch partition1_fire "Partition 1 Fire" <fire> {channel="mqtt:topic:mymqtt:dsc:partition1_fire"}
5256
Switch panel_online "Panel Online" <switch> {channel="mqtt:topic:mymqtt:dsc:panel_online"}
@@ -61,6 +65,7 @@ Contact zone3 "Zone 3" <motion> {channel="mqtt:topic:mymqtt:dsc:zone3"}
6165
* The commands to set the alarm state are setup in OpenHAB with the partition number (1-8) as a prefix to the command:
6266
* Partition 1 stay arm: "1S"
6367
* Partition 1 away arm: "1A"
68+
* Partition 1 night (no entry delay) arm: "1N"
6469
* Partition 2 disarm: "2D"
6570
*
6671
* The interface listens for commands in the configured mqttSubscribeTopic, and publishes partition status in a
@@ -243,6 +248,11 @@ void loop() {
243248
publishState(mqttPartitionTopic, partition, "A");
244249
}
245250

251+
// Armed - Night Mode / Instant Alarm (Stay and no Entry Delay)
252+
else if (dsc.armedStay[partition] && dsc.noEntryDelay[partition]) {
253+
publishState(mqttPartitionTopic, partition, "N");
254+
}
255+
246256
// Armed stay
247257
else if (dsc.armedStay[partition]) {
248258
publishState(mqttPartitionTopic, partition, "S");
@@ -384,6 +394,13 @@ void mqttCallback(char* topic, byte* payload, unsigned int length) {
384394
return;
385395
}
386396

397+
// Arm - No Entry Delay - Night Mode
398+
if (payload[payloadIndex] == 'N' && !dsc.armed[partition] && !dsc.exitDelay[partition]) {
399+
dsc.writePartition = partition + 1; // Sets writes to the partition number
400+
dsc.write('n'); // Keypad - Arm with no entry delay (night arm)
401+
return;
402+
}
403+
387404
// Disarm
388405
if (payload[payloadIndex] == 'D' && (dsc.armed[partition] || dsc.exitDelay[partition] || dsc.alarm[partition])) {
389406
dsc.writePartition = partition + 1; // Sets writes to the partition number

examples/esp32/OpenHAB-MQTT/OpenHAB-MQTT.ino

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,16 @@ Bridge mqtt:broker:mymqtt "My MQTT" [host="MQTT broker IP address or hostname"]
3131
Thing mqtt:topic:mymqtt:dsc "DSC Security System" (mqtt:broker:mymqtt) @ "Home" {
3232
Channels:
3333
Type string : partition1_message "Partition 1" [stateTopic="dsc/Get/Partition1/Message"]
34+
Type string : partition1_armed_mode "Alarm Armed Mode" [stateTopic="dsc/Get/Partition1", commandTopic="dsc/Set"]
3435
Type switch : partition1_armed_away "Partition 1 Armed Away" [stateTopic="dsc/Get/Partition1", commandTopic="dsc/Set", on="1A", off="1D"]
3536
Type switch : partition1_armed_stay "Partition 1 Armed Stay" [stateTopic="dsc/Get/Partition1", commandTopic="dsc/Set", on="1S", off="1D"]
37+
Type switch : partition1_armed_night "Partition 1 Armed Night" [stateTopic="dsc/Get/Partition1", commandTopic="dsc/Set", on="1N", off="1D"]
3638
Type switch : partition1_alarm "Partition 1 Alarm" [stateTopic="dsc/Get/Partition1", on="1T", off="1D"]
3739
Type switch : partition1_fire "Partition 1 Fire" [stateTopic="dsc/Get/Fire1", on="1", off="0"]
3840
Type switch : panel_online "Panel Online" [stateTopic="dsc/Status", on="online", off="offline"]
3941
Type switch : panel_trouble "Panel Trouble" [stateTopic="dsc/Get/Trouble", on="1", off="0"]
40-
Type switch : pgm1 "PGM 1" [stateTopic="dsc/Get/PGM 1", on="1", off="0"]
41-
Type switch : pgm8 "PGM 8" [stateTopic="dsc/Get/PGM 8", on="1", off="0"]
42+
Type switch : pgm1 "PGM 1" [stateTopic="dsc/Get/PGM1", on="1", off="0"]
43+
Type switch : pgm8 "PGM 8" [stateTopic="dsc/Get/PGM8", on="1", off="0"]
4244
Type contact : zone1 "Zone 1" [stateTopic="dsc/Get/Zone1", on="1", off="0"]
4345
Type contact : zone2 "Zone 2" [stateTopic="dsc/Get/Zone2", on="1", off="0"]
4446
Type contact : zone3 "Zone 3" [stateTopic="dsc/Get/Zone3", on="1", off="0"]
@@ -48,8 +50,10 @@ Thing mqtt:topic:mymqtt:dsc "DSC Security System" (mqtt:broker:mymqtt) @ "Home"
4850
* - https://www.openhab.org/docs/configuration/items.html
4951
5052
String partition1_message "Partition 1 [%s]" <shield> {channel="mqtt:topic:mymqtt:dsc:partition1_message"}
53+
String partition1_armed_mode "Armed Mode" {channel="mqtt:topic:mymqtt:dsc:partition1_armed_mode"}
5154
Switch partition1_armed_away "Partition 1 Armed Away" <shield> {channel="mqtt:topic:mymqtt:dsc:partition1_armed_away"}
5255
Switch partition1_armed_stay "Partition 1 Armed Stay" <shield> {channel="mqtt:topic:mymqtt:dsc:partition1_armed_stay"}
56+
Switch partition1_armed_night "Partition 1 Armed Night" <shield> {channel="mqtt:topic:mymqtt:dsc:partition1_armed_night"}
5357
Switch partition1_triggered "Partition 1 Alarm" <alarm> {channel="mqtt:topic:mymqtt:dsc:partition1_alarm"}
5458
Switch partition1_fire "Partition 1 Fire" <fire> {channel="mqtt:topic:mymqtt:dsc:partition1_fire"}
5559
Switch panel_online "Panel Online" <switch> {channel="mqtt:topic:mymqtt:dsc:panel_online"}
@@ -64,6 +68,7 @@ Contact zone3 "Zone 3" <motion> {channel="mqtt:topic:mymqtt:dsc:zone3"}
6468
* The commands to set the alarm state are setup in OpenHAB with the partition number (1-8) as a prefix to the command:
6569
* Partition 1 stay arm: "1S"
6670
* Partition 1 away arm: "1A"
71+
* Partition 1 night (no entry delay) arm: "1N"
6772
* Partition 2 disarm: "2D"
6873
*
6974
* The interface listens for commands in the configured mqttSubscribeTopic, and publishes partition status in a
@@ -256,6 +261,11 @@ void loop() {
256261
publishState(mqttPartitionTopic, partition, "A");
257262
}
258263

264+
// Armed - Night Mode / Instant Alarm (Stay and no Entry Delay)
265+
else if (dsc.armedStay[partition] && dsc.noEntryDelay[partition]) {
266+
publishState(mqttPartitionTopic, partition, "N");
267+
}
268+
259269
// Armed stay
260270
else if (dsc.armedStay[partition]) {
261271
publishState(mqttPartitionTopic, partition, "S");
@@ -397,6 +407,13 @@ void mqttCallback(char* topic, byte* payload, unsigned int length) {
397407
return;
398408
}
399409

410+
// Arm - No Entry Delay - Night Mode
411+
if (payload[payloadIndex] == 'N' && !dsc.armed[partition] && !dsc.exitDelay[partition]) {
412+
dsc.writePartition = partition + 1; // Sets writes to the partition number
413+
dsc.write('n'); // Keypad - Arm with no entry delay (night arm)
414+
return;
415+
}
416+
400417
// Disarm
401418
if (payload[payloadIndex] == 'D' && (dsc.armed[partition] || dsc.exitDelay[partition] || dsc.alarm[partition])) {
402419
dsc.writePartition = partition + 1; // Sets writes to the partition number

0 commit comments

Comments
 (0)