Skip to content

Examples - esp8266 - OpenHAB-MQTT --> Enhancement: Arm Mode Night (Stay with no entry delay) #362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
23 changes: 21 additions & 2 deletions examples/esp8266/OpenHAB-MQTT/OpenHAB-MQTT.ino
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@ Bridge mqtt:broker:mymqtt "My MQTT" [host="MQTT broker IP address or hostname"]
Thing mqtt:topic:mymqtt:dsc "DSC Security System" (mqtt:broker:mymqtt) @ "Home" {
Channels:
Type string : partition1_message "Partition 1" [stateTopic="dsc/Get/Partition1/Message"]
Type string : partition1_armed_mode "Alarm Armed Mode" [stateTopic="dsc/Get/Partition1", commandTopic="dsc/Set"]
Type switch : partition1_armed_away "Partition 1 Armed Away" [stateTopic="dsc/Get/Partition1", commandTopic="dsc/Set", on="1A", off="1D"]
Type switch : partition1_armed_stay "Partition 1 Armed Stay" [stateTopic="dsc/Get/Partition1", commandTopic="dsc/Set", on="1S", off="1D"]
Type switch : partition1_armed_night "Partition 1 Armed Night" [stateTopic="dsc/Get/Partition1", commandTopic="dsc/Set", on="1N", off="1D"]
Type switch : partition1_alarm "Partition 1 Alarm" [stateTopic="dsc/Get/Partition1", on="1T", off="1D"]
Type switch : partition1_fire "Partition 1 Fire" [stateTopic="dsc/Get/Fire1", on="1", off="0"]
Type switch : panel_online "Panel Online" [stateTopic="dsc/Status", on="online", off="offline"]
Type switch : panel_trouble "Panel Trouble" [stateTopic="dsc/Get/Trouble", on="1", off="0"]
Type switch : pgm1 "PGM 1" [stateTopic="dsc/Get/PGM 1", on="1", off="0"]
Type switch : pgm8 "PGM 8" [stateTopic="dsc/Get/PGM 8", on="1", off="0"]
Type switch : pgm1 "PGM 1" [stateTopic="dsc/Get/PGM1", on="1", off="0"]
Type switch : pgm8 "PGM 8" [stateTopic="dsc/Get/PGM8", on="1", off="0"]
Type contact : zone1 "Zone 1" [stateTopic="dsc/Get/Zone1", on="1", off="0"]
Type contact : zone2 "Zone 2" [stateTopic="dsc/Get/Zone2", on="1", off="0"]
Type contact : zone3 "Zone 3" [stateTopic="dsc/Get/Zone3", on="1", off="0"]
Expand All @@ -48,8 +50,10 @@ Thing mqtt:topic:mymqtt:dsc "DSC Security System" (mqtt:broker:mymqtt) @ "Home"
* - https://www.openhab.org/docs/configuration/items.html

String partition1_message "Partition 1 [%s]" <shield> {channel="mqtt:topic:mymqtt:dsc:partition1_message"}
String partition1_armed_mode "Armed Mode" {channel="mqtt:topic:mymqtt:dsc:partition1_armed_mode"}
Switch partition1_armed_away "Partition 1 Armed Away" <shield> {channel="mqtt:topic:mymqtt:dsc:partition1_armed_away"}
Switch partition1_armed_stay "Partition 1 Armed Stay" <shield> {channel="mqtt:topic:mymqtt:dsc:partition1_armed_stay"}
Switch partition1_armed_night "Partition 1 Armed Night" <shield> {channel="mqtt:topic:mymqtt:dsc:partition1_armed_night"}
Switch partition1_triggered "Partition 1 Alarm" <alarm> {channel="mqtt:topic:mymqtt:dsc:partition1_alarm"}
Switch partition1_fire "Partition 1 Fire" <fire> {channel="mqtt:topic:mymqtt:dsc:partition1_fire"}
Switch panel_online "Panel Online" <switch> {channel="mqtt:topic:mymqtt:dsc:panel_online"}
Expand All @@ -64,6 +68,7 @@ Contact zone3 "Zone 3" <motion> {channel="mqtt:topic:mymqtt:dsc:zone3"}
* The commands to set the alarm state are setup in OpenHAB with the partition number (1-8) as a prefix to the command:
* Partition 1 stay arm: "1S"
* Partition 1 away arm: "1A"
* Partition 1 night (no entry delay) arm: "1N"
* Partition 2 disarm: "2D"
*
* The interface listens for commands in the configured mqttSubscribeTopic, and publishes partition status in a
Expand Down Expand Up @@ -257,12 +262,19 @@ void loop() {
publishState(mqttPartitionTopic, partition, "A");
}

// Armed - Night Mode / Instant Alarm (Stay and no Entry Delay)
else if (dsc.armedStay[partition] && dsc.noEntryDelay[partition]) {
publishState(mqttPartitionTopic, partition, "N");
}

// Armed stay
else if (dsc.armedStay[partition]) {
publishState(mqttPartitionTopic, partition, "S");
}

}


// Disarmed
else publishState(mqttPartitionTopic, partition, "D");
}
Expand Down Expand Up @@ -398,6 +410,13 @@ void mqttCallback(char* topic, byte* payload, unsigned int length) {
return;
}

// Arm - No Entry Delay - Night Mode
if (payload[payloadIndex] == 'N' && !dsc.armed[partition] && !dsc.exitDelay[partition]) {
dsc.writePartition = partition + 1; // Sets writes to the partition number
dsc.write('n'); // Keypad - Arm with no entry delay (night arm)
return;
}

// Disarm
if (payload[payloadIndex] == 'D' && (dsc.armed[partition] || dsc.exitDelay[partition] || dsc.alarm[partition])) {
dsc.writePartition = partition + 1; // Sets writes to the partition number
Expand Down