Skip to content
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

[openwebnet] Add a time stamp when an alarm zone event occurs #14743

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
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
14 changes: 7 additions & 7 deletions bundles/org.openhab.binding.openwebnet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,13 @@ OPEN command to execute: *5*8#134##

### Alarm channels

| Channel Type ID (channel ID) | Applies to Thing Type IDs | Item Type | Description | Read/Write |
|------------------------------|----------------------------------------|-------------|-----------------------------------------------------------------------|:-----------:|
| `state` | `bus_alarm_system`, `bus_alarm_zone` | Switch | Alarm system or zone is active (`ON`) or inactive (`OFF`) | R |
| `network` | `bus_alarm_system` | Switch | Alarm system network state (`ON` = network ok, `OFF` = no network) | R |
| `battery` | `bus_alarm_system` | String | Alarm system battery state (`OK`, `FAULT`, `UNLOADED`) | R |
| `armed` | `bus_alarm_system` | Switch | Alarm system is armed (`ON`) or disarmed (`OFF`) | R |
| `alarm` | `bus_alarm_zone` | String | Current alarm for the zone (`SILENT`, `INTRUSION`, `TAMPERING`, `ANTI_PANIC`) | R |
| Channel Type ID (channel ID) | Applies to Thing Type IDs | Item Type | Description | Read/Write |
|------------------------------|----------------------------------------|-------------|----------------------------------------------------------------------------------------------------------------------------------------------|:-----------:|
| `state` | `bus_alarm_system`, `bus_alarm_zone` | Switch | Alarm system or zone is active (`ON`) or inactive (`OFF`) | R |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not modify other lines if they are not related to the PR

| `network` | `bus_alarm_system` | Switch | Alarm system network state (`ON` = network ok, `OFF` = no network) | R |
| `battery` | `bus_alarm_system` | String | Alarm system battery state (`OK`, `FAULT`, `UNLOADED`) | R |
| `armed` | `bus_alarm_system` | Switch | Alarm system is armed (`ON`) or disarmed (`OFF`) | R |
| `alarm` | `bus_alarm_zone` | String | Current alarm for the zone (`SILENT`, `INTRUSION`, `TAMPERING`, `ANTI_PANIC`) as well as the date and time of the event (YY/MM/DD hh:mm:ss) | R |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this channel should remain as it was before: it's not a good idea to put together two differnet information: the type of alarm that was triggered an its timestamp. This is not a good desing at all, as it makes difficult for example for scripts to detect which type of alarm has been triggered (you would need to parse the string).
As already suggested, have a look to the Verisure Alarm binding, where there is one channel for the alarm type (of type String) and one for the timestamp (of type DateTime)


### Thermo channels

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

import static org.openhab.binding.openwebnet.internal.OpenWebNetBindingConstants.*;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.HashSet;
import java.util.Set;

Expand Down Expand Up @@ -43,6 +46,7 @@
* {@link OpenWebNetThingHandler}.
*
* @author Massimo Valla - Initial contribution
* @author Giovanni Fabiani - Added timestamp
*/
@NonNullByDefault
public class OpenWebNetAlarmHandler extends OpenWebNetThingHandler {
Expand Down Expand Up @@ -229,27 +233,29 @@ private void updateZoneState(WhatAlarm w) {
}

private void updateZoneAlarm(WhatAlarm w) {
LocalDateTime now = LocalDateTime.now(ZoneId.systemDefault());
DateTimeFormatter format = DateTimeFormatter.ofPattern("MM-dd-yyyy HH:mm:ss");
switch (w) {
case ZONE_ALARM_INTRUSION:
updateState(CHANNEL_ALARM_ZONE_ALARM, new StringType(ALARM_INTRUSION));
updateState(CHANNEL_ALARM_ZONE_ALARM, new StringType(ALARM_INTRUSION + " " + now.format(format)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

timestamp should not be concatenated to the alarm channel, but returned in a new timestamp channel. This is not a good design. See explanation in previous comment

break;
case ZONE_ALARM_TAMPERING:
updateState(CHANNEL_ALARM_ZONE_ALARM, new StringType(ALARM_TAMPERING));
updateState(CHANNEL_ALARM_ZONE_ALARM, new StringType(ALARM_TAMPERING + " " + now.format(format)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see previous comment

break;
case ZONE_ALARM_ANTI_PANIC:
updateState(CHANNEL_ALARM_ZONE_ALARM, new StringType(ALARM_ANTI_PANIC));
updateState(CHANNEL_ALARM_ZONE_ALARM, new StringType(ALARM_ANTI_PANIC + " " + now.format(format)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see previous comment

break;
case ZONE_ALARM_SILENT:
updateState(CHANNEL_ALARM_ZONE_ALARM, new StringType(ALARM_SILENT));
updateState(CHANNEL_ALARM_ZONE_ALARM, new StringType(ALARM_SILENT + " " + now.format(format)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see previous comment

break;
case ZONE_ALARM_TECHNICAL:
updateState(CHANNEL_ALARM_ZONE_ALARM, new StringType(ALARM_TECHNICAL));
updateState(CHANNEL_ALARM_ZONE_ALARM, new StringType(ALARM_TECHNICAL + " " + now.format(format)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see previous comment

break;
case ZONE_ALARM_TECHNICAL_RESET:
updateState(CHANNEL_ALARM_ZONE_ALARM, new StringType(ALARM_TECHNICAL_RESET));
updateState(CHANNEL_ALARM_ZONE_ALARM, new StringType(ALARM_TECHNICAL_RESET + " " + now.format(format)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see previous comment

break;
default:
updateState(CHANNEL_ALARM_ZONE_ALARM, new StringType(ALARM_NONE));
updateState(CHANNEL_ALARM_ZONE_ALARM, new StringType(ALARM_NONE + " " + now.format(format)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see previous comment

Copy link
Contributor Author

@fabgio fabgio Apr 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, ok I will keep working on the basis of what you suggested. Do not consider this PR!

logger.warn("Alarm.updateZoneAlarm() Ignoring unsupported WHAT {} for zone {}", w, this.deviceWhere);
}
}
Expand Down