node-red-contrib-ccu 4.17.0 → 4.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +31 -0
- package/README.md +12 -1
- package/nodes/ccu-alarm.html +124 -0
- package/nodes/ccu-alarm.js +301 -0
- package/nodes/ccu-connection.html +19 -2
- package/nodes/ccu-connection.js +133 -8
- package/nodes/lib/alarm.js +246 -0
- package/nodes/locales/de/ccu-alarm.html +74 -0
- package/nodes/locales/de/ccu-alarm.json +7 -0
- package/nodes/locales/en-US/ccu-alarm.html +72 -0
- package/nodes/locales/en-US/ccu-alarm.json +7 -0
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,37 @@ Notable changes to node-red-contrib-ccu. Format follows
|
|
|
5
5
|
user-visible symptom and the cause, not the commit list (the release notes
|
|
6
6
|
append commits automatically).
|
|
7
7
|
|
|
8
|
+
## 4.18.0 (2026-11-30)
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **The alarm node for openccu-lite's alarm system.** `ccu-alarm` follows one
|
|
13
|
+
area of the alarm system addon: its state as Home Assistant names it
|
|
14
|
+
(`disarmed`, `arming`, `armed_home`, `armed_away`, `pending`, `triggered`)
|
|
15
|
+
in `msg.payload`, with `msg.alarm` (active, kind, sensor), `ready`,
|
|
16
|
+
`openSensors`, `delay` and `prealarm`, one message per change; and it takes
|
|
17
|
+
`arm_home`, `arm_away`, `disarm`, `silence`, `acknowledge` and `panic` (Home
|
|
18
|
+
Assistant's service names as well). The editor lists only the system's
|
|
19
|
+
alarm areas. A command the area refuses because its switch _Scharf/Unscharf
|
|
20
|
+
über lite-rpc erlauben_ is off shows on the node and in an error that names
|
|
21
|
+
the switch and where to set it; a panic alarm needs no switch.
|
|
22
|
+
|
|
23
|
+
## 4.17.1 (2026-11-29)
|
|
24
|
+
|
|
25
|
+
### Fixed
|
|
26
|
+
|
|
27
|
+
- **A taken callback port crashed Node-RED.** When the BINRPC listening port
|
|
28
|
+
of a ccu-connection node was already in use - by a second connection node
|
|
29
|
+
with the same port, as a flow imported with a copy of the connection node
|
|
30
|
+
brings it, or by another process - Node-RED ended with
|
|
31
|
+
`listen EADDRINUSE` at every start (on RedMatic: only the safe mode was
|
|
32
|
+
left). Since 4.1.0 the error of the BINRPC callback server went unheard.
|
|
33
|
+
Now only that connection fails: its nodes show `port <n> in use`, the log
|
|
34
|
+
names the port and the connection node holding it, and the rest of the
|
|
35
|
+
runtime keeps running. The editor marks a connection node whose listening
|
|
36
|
+
port another connection node uses. Reported by HA_Beginner
|
|
37
|
+
(homematic-forum).
|
|
38
|
+
|
|
8
39
|
## 4.17.0 (2026-11-28)
|
|
9
40
|
|
|
10
41
|
### Changed
|
package/README.md
CHANGED
|
@@ -67,6 +67,16 @@ CCU-Jack keep their own connections.
|
|
|
67
67
|
on the system, or a paired connection); without the addon the nodes show _Logic addon not installed_ and a write
|
|
68
68
|
is refused with that reason. `ccu-poll` has nothing to poll there (the values are events). **HM-Script does not
|
|
69
69
|
exist there**: the `ccu-script` node stays in the flows and answers every message with an error.
|
|
70
|
+
- **Alarm areas come from the alarm system addon.** It offers each area as a device `area-<key>` (type `ALARM-AREA`)
|
|
71
|
+
of its interface `Alarm`, followed like Logic's without a checkbox, so the value and event nodes reach an area like
|
|
72
|
+
any device. The `ccu-alarm` node is made for it: pick an area (the editor lists only alarm areas), and it emits the
|
|
73
|
+
area's state as Home Assistant names it (`disarmed`, `arming`, `armed_home`, `armed_away`, `pending`, `triggered`)
|
|
74
|
+
with the alarm (kind, sensor), readiness, open sensors, delay and pre-alarm in one message per change; it takes
|
|
75
|
+
`arm_home`, `arm_away`, `disarm`, `silence`, `acknowledge` and `panic` in `msg.payload`. The alarm system decides
|
|
76
|
+
what a command may do: arming, disarming, silencing and acknowledging are refused until the area's switch
|
|
77
|
+
_Scharf/Unscharf über lite-rpc erlauben_ (_Allow arming and disarming over lite-rpc_) is on - the node shows
|
|
78
|
+
_refused: lite-rpc switch off_ and its error names the switch -, arming is refused while sensors are open, and a
|
|
79
|
+
panic alarm always works.
|
|
70
80
|
|
|
71
81
|
## Topics
|
|
72
82
|
|
|
@@ -79,12 +89,13 @@ Every node that emits messages builds `msg.topic` from the same template, config
|
|
|
79
89
|
| get value | _(empty: `msg.topic` stays as it came in)_ |
|
|
80
90
|
| sysvar | `hm/status/sysvar/${Name}` |
|
|
81
91
|
| program | `hm/status/program/${Name}` |
|
|
92
|
+
| alarm | `hm/status/alarm/${Name}` |
|
|
82
93
|
| rpc | `${CCU}/${Interface}/${Method}` |
|
|
83
94
|
| script | `${CCU}/${Interface}` |
|
|
84
95
|
|
|
85
96
|
Placeholders are the message's properties, matched case-insensitively: `${CCU}`, `${Interface}`, `${device}`,
|
|
86
97
|
`${deviceName}`, `${deviceType}`, `${channel}`, `${channelName}`, `${channelType}`, `${channelIndex}`, `${datapoint}`,
|
|
87
|
-
`${datapointName}`; `${Name}` for a variable or
|
|
98
|
+
`${datapointName}`; `${Name}` for a variable, program or alarm area, `${Method}` for an RPC call. To get one scheme everywhere -
|
|
88
99
|
`hm/<interface>/<channel>/<datapoint>`, say - enter `hm/${Interface}/${channel}/${datapoint}` in each node. A default
|
|
89
100
|
applies to newly placed nodes only: existing nodes keep the topic they were saved with (the default of the sysvar
|
|
90
101
|
and program nodes was `ReGaHSS/${Name}` until 4.16.0), so existing flows and subscriptions keep working. The value node's input accepts a datapoint address in
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
RED.nodes.registerType('ccu-alarm', {
|
|
3
|
+
|
|
4
|
+
category: 'ccu',
|
|
5
|
+
defaults: {
|
|
6
|
+
name: {value: ''},
|
|
7
|
+
ccuConfig: {value: 'localhost', type: 'ccu-connection', required: true},
|
|
8
|
+
area: {value: '', required: true, validate: RED.validators.regex(/^area-[^:\s]+$/)},
|
|
9
|
+
topic: {value: 'hm/status/alarm/${Name}'},
|
|
10
|
+
cache: {value: true}
|
|
11
|
+
},
|
|
12
|
+
inputs: 1,
|
|
13
|
+
outputs: 1,
|
|
14
|
+
icon: 'ccu.png',
|
|
15
|
+
color: '#E2A3A3',
|
|
16
|
+
paletteLabel: 'alarm',
|
|
17
|
+
align: 'left',
|
|
18
|
+
label() {
|
|
19
|
+
return this.name || this.area || 'alarm';
|
|
20
|
+
},
|
|
21
|
+
labelStyle() {
|
|
22
|
+
return this.name ? 'node_label_italic' : '';
|
|
23
|
+
},
|
|
24
|
+
oneditprepare() {
|
|
25
|
+
const $area = $('#node-input-area');
|
|
26
|
+
const $select = $('#select-input-area');
|
|
27
|
+
const $tip = $('#ccu-alarm-none');
|
|
28
|
+
const current = this.area;
|
|
29
|
+
let request = 0;
|
|
30
|
+
|
|
31
|
+
function load(nodeId) {
|
|
32
|
+
// the dialog's own change event of the CCU field loads a second time: only the last
|
|
33
|
+
// answer fills the list
|
|
34
|
+
const mine = ++request;
|
|
35
|
+
if (!nodeId || nodeId === '_ADD_') {
|
|
36
|
+
$select.html('').hide();
|
|
37
|
+
$tip.hide();
|
|
38
|
+
$area.show();
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// task 38: only the alarm addon's areas (devices of the type ALARM-AREA)
|
|
43
|
+
$.getJSON('ccu?type=alarm&config=' + nodeId, data => {
|
|
44
|
+
if (mine !== request) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const want = $select.is(':visible') ? $select.val() : $area.val() || current;
|
|
49
|
+
$select.html('');
|
|
50
|
+
const addresses = Object.keys(data || {}).sort((a, b) =>
|
|
51
|
+
String(data[a].name).localeCompare(String(data[b].name)));
|
|
52
|
+
if (addresses.length === 0) {
|
|
53
|
+
$select.hide();
|
|
54
|
+
$area.show();
|
|
55
|
+
$tip.show();
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
$tip.hide();
|
|
60
|
+
if (want && !addresses.includes(want)) {
|
|
61
|
+
$select.append($('<option>').val(want).text(want + ' (not on the system)'));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
addresses.forEach(address => {
|
|
65
|
+
$select.append($('<option>').val(address).text(data[address].name + ' (' + address + ')'));
|
|
66
|
+
});
|
|
67
|
+
$select.val(want || addresses[0]);
|
|
68
|
+
$area.hide();
|
|
69
|
+
$select.show();
|
|
70
|
+
}).fail(() => {
|
|
71
|
+
if (mine === request) {
|
|
72
|
+
$tip.show();
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
load(this.ccuConfig);
|
|
78
|
+
$('#node-input-ccuConfig').change(() => load($('#node-input-ccuConfig').val()));
|
|
79
|
+
},
|
|
80
|
+
oneditsave() {
|
|
81
|
+
const $select = $('#select-input-area');
|
|
82
|
+
if ($select.is(':visible')) {
|
|
83
|
+
$('#node-input-area').val($select.val());
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
</script>
|
|
88
|
+
|
|
89
|
+
<script type="text/html" data-template-name="ccu-alarm">
|
|
90
|
+
<style>
|
|
91
|
+
label.ccu-checkbox {
|
|
92
|
+
display: block !important;
|
|
93
|
+
width: auto !important;
|
|
94
|
+
}
|
|
95
|
+
label.ccu-checkbox input {
|
|
96
|
+
width: auto !important;
|
|
97
|
+
margin-top: -3px !important;
|
|
98
|
+
}
|
|
99
|
+
select.ccu-dropdown {
|
|
100
|
+
width: 70%;
|
|
101
|
+
}
|
|
102
|
+
</style>
|
|
103
|
+
<div class="form-row">
|
|
104
|
+
<label for="node-input-ccuConfig"><i class="icon-globe"></i> CCU</label>
|
|
105
|
+
<input type="text" id="node-input-ccuConfig">
|
|
106
|
+
</div>
|
|
107
|
+
<div class="form-row">
|
|
108
|
+
<label for="node-input-area"><i class="fa fa-shield"></i> <span data-i18n="ccu-alarm.area"></span></label>
|
|
109
|
+
<input type="text" id="node-input-area" placeholder="area-…">
|
|
110
|
+
<select id="select-input-area" style="display:none" class="ccu-dropdown"></select>
|
|
111
|
+
</div>
|
|
112
|
+
<div class="form-tips" id="ccu-alarm-none" style="display:none" data-i18n="ccu-alarm.none"></div>
|
|
113
|
+
<div class="form-row">
|
|
114
|
+
<label class="ccu-checkbox" for="node-input-cache"><input type="checkbox" id="node-input-cache"> <span data-i18n="ccu-alarm.cache"></span></label>
|
|
115
|
+
</div>
|
|
116
|
+
<div class="form-row">
|
|
117
|
+
<label for="node-input-topic"><i class="icon-tasks"></i> Topic</label>
|
|
118
|
+
<input type="text" id="node-input-topic">
|
|
119
|
+
</div>
|
|
120
|
+
<div class="form-row">
|
|
121
|
+
<label for="node-input-name"><i class="icon-bookmark"></i> Name</label>
|
|
122
|
+
<input type="text" id="node-input-name">
|
|
123
|
+
</div>
|
|
124
|
+
</script>
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* task 38: an alarm area of openccu-lite's alarm addon as one node - its state and alarm out,
|
|
3
|
+
* arm/disarm/silence/acknowledge/panic in. The area is a device of the addon's interface (see
|
|
4
|
+
* lib/alarm.js); the node follows its value channel like a value node would, folds the datapoints
|
|
5
|
+
* into one message and writes the commands with setValue.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const path = require('path');
|
|
9
|
+
|
|
10
|
+
const statusHelper = require(path.join(__dirname, '/lib/status.js'));
|
|
11
|
+
const alarm = require(path.join(__dirname, '/lib/alarm.js'));
|
|
12
|
+
|
|
13
|
+
/** events of one change come in one multicall; they are folded into one message */
|
|
14
|
+
const FOLD_MS = 25;
|
|
15
|
+
|
|
16
|
+
module.exports = function (RED) {
|
|
17
|
+
class CcuAlarm {
|
|
18
|
+
constructor(config) {
|
|
19
|
+
RED.nodes.createNode(this, config);
|
|
20
|
+
|
|
21
|
+
this.config = config;
|
|
22
|
+
this.ccu = RED.nodes.getNode(config.ccuConfig);
|
|
23
|
+
this.iface = alarm.ALARM_IFACE;
|
|
24
|
+
|
|
25
|
+
if (!this.ccu) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
this.area = alarm.parseArea(config.area);
|
|
30
|
+
this.values = {};
|
|
31
|
+
this.changed = new Set();
|
|
32
|
+
this.foldCache = true;
|
|
33
|
+
this.foldTimer = null;
|
|
34
|
+
this.sent = false;
|
|
35
|
+
this.lastPayload = undefined;
|
|
36
|
+
this.refused = null;
|
|
37
|
+
|
|
38
|
+
this.ccu.register(this);
|
|
39
|
+
|
|
40
|
+
if (this.area) {
|
|
41
|
+
this.idSubscription = this.ccu.subscribe({cache: true, channel: this.area.channel}, (message) =>
|
|
42
|
+
this.take(message),
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
this.on('input', (message, send, done) => {
|
|
47
|
+
this.command(message)
|
|
48
|
+
.then(() => done())
|
|
49
|
+
.catch((error) => done(error));
|
|
50
|
+
});
|
|
51
|
+
this.on('close', this._destructor);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** the area's name on the system: the channel's, else the device's, else its key */
|
|
55
|
+
areaName() {
|
|
56
|
+
const names = this.ccu.channelNames || {};
|
|
57
|
+
return names[this.area.channel] || names[this.area.device] || this.area.key;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* One datapoint of the area: kept, and put out with the others of the same change.
|
|
62
|
+
* @param {object} message as the connection makes it
|
|
63
|
+
*/
|
|
64
|
+
take(message) {
|
|
65
|
+
if (!alarm.DATAPOINTS.includes(message.datapoint)) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
this.values[message.datapoint] = message.value;
|
|
70
|
+
if (!message.cache) {
|
|
71
|
+
this.foldCache = false;
|
|
72
|
+
this.changed.add(message.datapoint);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (message.datapoint === 'STATE' || message.datapoint === 'ALARM') {
|
|
76
|
+
// a new state or alarm ends what a refused command said
|
|
77
|
+
this.refused = null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (!this.foldTimer) {
|
|
81
|
+
this.foldTimer = setTimeout(() => this.flush(), FOLD_MS);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** the folded change as one message */
|
|
86
|
+
flush() {
|
|
87
|
+
this.foldTimer = null;
|
|
88
|
+
const cache = this.foldCache;
|
|
89
|
+
const changed = [...this.changed];
|
|
90
|
+
this.foldCache = true;
|
|
91
|
+
this.changed = new Set();
|
|
92
|
+
|
|
93
|
+
const state = alarm.areaState(this.values);
|
|
94
|
+
this.showState();
|
|
95
|
+
if (cache && (this.sent || !this.config.cache)) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const message = {
|
|
100
|
+
...state,
|
|
101
|
+
payloadPrevious: this.lastPayload,
|
|
102
|
+
area: {key: this.area.key, address: this.area.device, name: this.areaName()},
|
|
103
|
+
iface: this.ccu.alarmIface() || alarm.ALARM_IFACE,
|
|
104
|
+
channel: this.area.channel,
|
|
105
|
+
changed,
|
|
106
|
+
cache,
|
|
107
|
+
ts: Date.now(),
|
|
108
|
+
};
|
|
109
|
+
message.name = message.area.name;
|
|
110
|
+
message.topic = this.ccu.topicReplace(this.config.topic, message);
|
|
111
|
+
this.lastPayload = state.payload;
|
|
112
|
+
this.sent = true;
|
|
113
|
+
this.send(message);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* A command in msg.payload: written to the area, or refused with the reason.
|
|
118
|
+
* @param {object} message
|
|
119
|
+
* @returns {Promise<void>}
|
|
120
|
+
*/
|
|
121
|
+
async command(message) {
|
|
122
|
+
const command = alarm.parseCommand(message.payload);
|
|
123
|
+
if (!command) {
|
|
124
|
+
throw new Error(
|
|
125
|
+
'unknown command ' +
|
|
126
|
+
JSON.stringify(message.payload) +
|
|
127
|
+
' - one of ' +
|
|
128
|
+
Object.keys(alarm.COMMANDS).join(', '),
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (!this.area) {
|
|
133
|
+
throw new Error('no alarm area chosen');
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
let source = this.ccu.alarmSource();
|
|
137
|
+
if (source.waiting && typeof this.ccu.whenLogicKnown === 'function') {
|
|
138
|
+
// the system's list of interfaces is read at connect; a command right after a deploy waits for it
|
|
139
|
+
await this.ccu.whenLogicKnown();
|
|
140
|
+
source = this.ccu.alarmSource();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (source.error || source.waiting) {
|
|
144
|
+
throw new Error(
|
|
145
|
+
command.command + ': the alarm area cannot be reached - ' + (source.error || 'not connected yet'),
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
try {
|
|
150
|
+
await this.ccu.methodCall(source.iface, 'setValue', [
|
|
151
|
+
this.area.channel,
|
|
152
|
+
command.datapoint,
|
|
153
|
+
command.value,
|
|
154
|
+
]);
|
|
155
|
+
} catch (error) {
|
|
156
|
+
const refused = alarm.refusal(error);
|
|
157
|
+
const name = this.areaName();
|
|
158
|
+
let text;
|
|
159
|
+
switch (refused.reason) {
|
|
160
|
+
case 'switch':
|
|
161
|
+
this.refused = 'refused: lite-rpc switch off';
|
|
162
|
+
text = alarm.switchMessage(command.command, name);
|
|
163
|
+
break;
|
|
164
|
+
case 'not-ready':
|
|
165
|
+
this.refused = refused.text;
|
|
166
|
+
text = command.command + ' refused: the alarm area "' + name + '" is ' + refused.text;
|
|
167
|
+
break;
|
|
168
|
+
case 'armed':
|
|
169
|
+
this.refused = 'refused: armed at the other level';
|
|
170
|
+
text = command.command + ' refused: the alarm area "' + name + '" ' + refused.text;
|
|
171
|
+
break;
|
|
172
|
+
case 'unknown-area':
|
|
173
|
+
this.refused = 'area not found';
|
|
174
|
+
text = command.command + ': the alarm area ' + this.area.device + ' is not on the system';
|
|
175
|
+
break;
|
|
176
|
+
default:
|
|
177
|
+
this.refused = 'error';
|
|
178
|
+
text = command.command + ' failed for the alarm area "' + name + '": ' + refused.text;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
this.showState();
|
|
182
|
+
const failure = new Error(text);
|
|
183
|
+
failure.reason = refused.reason;
|
|
184
|
+
throw failure;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
this.refused = null;
|
|
188
|
+
this.showState();
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* The status: why the area cannot be reached, a refusal, or the area's state.
|
|
193
|
+
* @param {object} [data] what the connection pushed last
|
|
194
|
+
*/
|
|
195
|
+
showState(data) {
|
|
196
|
+
if (data) {
|
|
197
|
+
this.lastData = data;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const source = this.ccu.alarmSource();
|
|
201
|
+
if (source.iface) {
|
|
202
|
+
this.iface = source.iface;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const set = (status) => {
|
|
206
|
+
const key = JSON.stringify(status);
|
|
207
|
+
if (this.currentStatus !== key) {
|
|
208
|
+
this.status(status);
|
|
209
|
+
this.currentStatus = key;
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
if (source.error) {
|
|
214
|
+
set({fill: 'red', shape: 'ring', text: source.error});
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (source.waiting) {
|
|
219
|
+
set({fill: 'yellow', shape: 'ring', text: 'waiting'});
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (!this.area) {
|
|
224
|
+
set({fill: 'red', shape: 'ring', text: 'no area chosen'});
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const connected = this.lastData && this.lastData.ifaceStatus && this.lastData.ifaceStatus[this.iface];
|
|
229
|
+
if (!connected) {
|
|
230
|
+
this.currentStatus = null;
|
|
231
|
+
statusHelper(this, this.lastData);
|
|
232
|
+
this.currentStatus = 'iface';
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (this.refused) {
|
|
237
|
+
set({fill: 'red', shape: 'ring', text: this.refused.slice(0, 60)});
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const devices = this.ccu.metadata && this.ccu.metadata.devices && this.ccu.metadata.devices[this.iface];
|
|
242
|
+
if (this.ccu.litePictured && devices && !devices[this.area.device]) {
|
|
243
|
+
set({fill: 'red', shape: 'ring', text: 'area not found'});
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const state = alarm.areaState(this.values);
|
|
248
|
+
if (!state.payload) {
|
|
249
|
+
set({fill: 'green', shape: 'ring', text: 'connected'});
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
let text = state.payload;
|
|
254
|
+
let fill = 'green';
|
|
255
|
+
let shape = 'dot';
|
|
256
|
+
if (state.payload === 'disarmed') {
|
|
257
|
+
shape = 'ring';
|
|
258
|
+
if (state.ready === false) {
|
|
259
|
+
text += ', not ready' + (state.openSensors ? ' (' + state.openSensors + ')' : '');
|
|
260
|
+
}
|
|
261
|
+
} else if (state.payload === 'arming' || state.payload === 'pending') {
|
|
262
|
+
fill = 'yellow';
|
|
263
|
+
if (state.delay) {
|
|
264
|
+
text += ' ' + state.delay + ' s';
|
|
265
|
+
}
|
|
266
|
+
} else if (state.payload === 'triggered') {
|
|
267
|
+
fill = 'red';
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
if (state.alarm.active && state.payload !== 'triggered') {
|
|
271
|
+
fill = 'red';
|
|
272
|
+
shape = 'ring';
|
|
273
|
+
text += ', alarm' + (state.alarm.kind ? ': ' + state.alarm.kind : '');
|
|
274
|
+
} else if (state.alarm.active && state.alarm.kind) {
|
|
275
|
+
text += ': ' + state.alarm.kind;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (state.prealarm) {
|
|
279
|
+
fill = fill === 'red' ? fill : 'yellow';
|
|
280
|
+
text += ', pre-alarm';
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
set({fill, shape, text});
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
setStatus(data) {
|
|
287
|
+
this.showState(data);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
_destructor(done) {
|
|
291
|
+
clearTimeout(this.foldTimer);
|
|
292
|
+
if (this.idSubscription) {
|
|
293
|
+
this.ccu.unsubscribe(this.idSubscription);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
done();
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
RED.nodes.registerType('ccu-alarm', CcuAlarm);
|
|
301
|
+
};
|
|
@@ -14,6 +14,23 @@
|
|
|
14
14
|
ccuActivePairing = null;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
+
// a callback port another connection node listens on, too: only one of the two can open it
|
|
18
|
+
// (a flow imported with a copy of the connection node brings the same ports)
|
|
19
|
+
const ccuUniquePort = function (value) {
|
|
20
|
+
if (!value) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
let taken = false;
|
|
25
|
+
RED.nodes.eachConfig(node => {
|
|
26
|
+
if (node.type === 'ccu-connection' && node.id !== this.id && !node.d &&
|
|
27
|
+
(String(node.rpcBinPort) === String(value) || String(node.rpcXmlPort) === String(value))) {
|
|
28
|
+
taken = true;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
return !taken || 'port ' + value + ' is used by another ccu-connection node';
|
|
32
|
+
};
|
|
33
|
+
|
|
17
34
|
RED.nodes.registerType('ccu-connection', {
|
|
18
35
|
category: 'config',
|
|
19
36
|
defaults: {
|
|
@@ -45,8 +62,8 @@
|
|
|
45
62
|
rpcPingTimeout: {value: 60},
|
|
46
63
|
rpcInitAddress: {value: ''},
|
|
47
64
|
rpcServerHost: {value: '', required: true},
|
|
48
|
-
rpcBinPort: {value: '', required: true},
|
|
49
|
-
rpcXmlPort: {value: '', required: true},
|
|
65
|
+
rpcBinPort: {value: '', required: true, validate: ccuUniquePort},
|
|
66
|
+
rpcXmlPort: {value: '', required: true, validate: ccuUniquePort},
|
|
50
67
|
|
|
51
68
|
tls: {value: false},
|
|
52
69
|
inSecure: {value: false},
|
package/nodes/ccu-connection.js
CHANGED
|
@@ -20,6 +20,7 @@ const metaProvider = require('./lib/metaprovider.js');
|
|
|
20
20
|
const {InitRetry, retryDelay, RETRY_INTERVAL} = require('./lib/initretry.js');
|
|
21
21
|
const lite = require('./lib/lite.js');
|
|
22
22
|
const logic = require('./lib/logic.js');
|
|
23
|
+
const alarm = require('./lib/alarm.js');
|
|
23
24
|
const {Pairings} = require('./lib/pairing.js');
|
|
24
25
|
const {
|
|
25
26
|
writeJsonAtomic,
|
|
@@ -107,6 +108,11 @@ module.exports = function (RED) {
|
|
|
107
108
|
|
|
108
109
|
const ccu = {network: {listen: [], ports: []}};
|
|
109
110
|
|
|
111
|
+
// the callback ports the connection nodes of this runtime listen on, port -> {node, protocol}:
|
|
112
|
+
// a port that is taken names the config node holding it (two connection nodes with the same
|
|
113
|
+
// port, e.g. after importing a flow that carried a copy of one)
|
|
114
|
+
const callbackPorts = new Map();
|
|
115
|
+
|
|
110
116
|
/**
|
|
111
117
|
*
|
|
112
118
|
* @param start
|
|
@@ -419,6 +425,25 @@ module.exports = function (RED) {
|
|
|
419
425
|
res.status(200).send(JSON.stringify(config.program));
|
|
420
426
|
break;
|
|
421
427
|
|
|
428
|
+
case 'alarm': {
|
|
429
|
+
// task 38: the alarm addon's areas - only devices of the type ALARM-AREA
|
|
430
|
+
const all = (config.metadata && config.metadata.devices) || {};
|
|
431
|
+
Object.keys(all).forEach((iface) => {
|
|
432
|
+
const devices = all[iface] || {};
|
|
433
|
+
Object.keys(devices).forEach((addr) => {
|
|
434
|
+
const device = devices[addr];
|
|
435
|
+
if (device && !device.PARENT && device.TYPE === alarm.AREA_TYPE) {
|
|
436
|
+
object[addr] = {
|
|
437
|
+
name: config.channelNames[addr + ':1'] || config.channelNames[addr] || addr,
|
|
438
|
+
iface,
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
});
|
|
442
|
+
});
|
|
443
|
+
res.status(200).send(JSON.stringify(object));
|
|
444
|
+
break;
|
|
445
|
+
}
|
|
446
|
+
|
|
422
447
|
case 'signal': {
|
|
423
448
|
const devices = config.metadata.devices[request.query.iface];
|
|
424
449
|
if (devices) {
|
|
@@ -1127,7 +1152,7 @@ module.exports = function (RED) {
|
|
|
1127
1152
|
}
|
|
1128
1153
|
|
|
1129
1154
|
waiting = Boolean(waiting) && !connected;
|
|
1130
|
-
if (connected && this.ifaceError[iface]) {
|
|
1155
|
+
if (connected && this.ifaceError[iface] && !this.serverError[iface]) {
|
|
1131
1156
|
delete this.ifaceError[iface];
|
|
1132
1157
|
this.ifaceStatus[iface] = null; // the nodes drop the error text
|
|
1133
1158
|
}
|
|
@@ -3208,12 +3233,14 @@ module.exports = function (RED) {
|
|
|
3208
3233
|
this.logicIface = iface;
|
|
3209
3234
|
}
|
|
3210
3235
|
|
|
3236
|
+
const isAlarm = !isLogic && alarm.isAlarmIface(iface, info);
|
|
3211
3237
|
this.logger.info(
|
|
3212
3238
|
'lite-rpc: the interface ' +
|
|
3213
3239
|
iface +
|
|
3214
3240
|
(info.addon ? ' of the addon ' + info.addon : '') +
|
|
3215
3241
|
' is followed as well' +
|
|
3216
|
-
(isLogic ? ' - the system variables and programs' : '')
|
|
3242
|
+
(isLogic ? ' - the system variables and programs' : '') +
|
|
3243
|
+
(isAlarm ? ' - the alarm areas' : ''),
|
|
3217
3244
|
);
|
|
3218
3245
|
this.pushStatus();
|
|
3219
3246
|
return true;
|
|
@@ -3331,6 +3358,50 @@ module.exports = function (RED) {
|
|
|
3331
3358
|
return {iface: logic.LOGIC_IFACE, waiting: true};
|
|
3332
3359
|
}
|
|
3333
3360
|
|
|
3361
|
+
/**
|
|
3362
|
+
* task 38: the alarm addon's interface this connection follows, else null.
|
|
3363
|
+
* @returns {string|null}
|
|
3364
|
+
*/
|
|
3365
|
+
alarmIface() {
|
|
3366
|
+
const found = Object.keys(this.ifaceTypes).find(
|
|
3367
|
+
(iface) =>
|
|
3368
|
+
this.ifaceTypes[iface].addonIface &&
|
|
3369
|
+
!logic.isLogicIface(iface, {addon: this.ifaceTypes[iface].addon}) &&
|
|
3370
|
+
alarm.isAlarmIface(iface, {addon: this.ifaceTypes[iface].addon}),
|
|
3371
|
+
);
|
|
3372
|
+
return found || null;
|
|
3373
|
+
}
|
|
3374
|
+
|
|
3375
|
+
/**
|
|
3376
|
+
* task 38: what the alarm node shows: the alarm interface, or why there is none (a CCU, a
|
|
3377
|
+
* connection without lite-rpc, the addon not installed), or that it is not known yet.
|
|
3378
|
+
* @returns {{iface: string, error?: string, waiting?: boolean}}
|
|
3379
|
+
*/
|
|
3380
|
+
alarmSource() {
|
|
3381
|
+
const iface = this.alarmIface();
|
|
3382
|
+
if (iface) {
|
|
3383
|
+
return {iface};
|
|
3384
|
+
}
|
|
3385
|
+
|
|
3386
|
+
if (!this.metaMode) {
|
|
3387
|
+
// a CCU once its interfaces answer; until then it may still turn out to be openccu-lite
|
|
3388
|
+
const ccuUp = Object.keys(this.ifaceStatus).some((name) => this.ifaceStatus[name]);
|
|
3389
|
+
return ccuUp
|
|
3390
|
+
? {iface: alarm.ALARM_IFACE, error: 'needs openccu-lite'}
|
|
3391
|
+
: {iface: alarm.ALARM_IFACE, waiting: true};
|
|
3392
|
+
}
|
|
3393
|
+
|
|
3394
|
+
if (!this.lite) {
|
|
3395
|
+
return {iface: alarm.ALARM_IFACE, error: 'needs lite-rpc'};
|
|
3396
|
+
}
|
|
3397
|
+
|
|
3398
|
+
if (this.liteListed) {
|
|
3399
|
+
return {iface: alarm.ALARM_IFACE, error: 'alarm addon not installed'};
|
|
3400
|
+
}
|
|
3401
|
+
|
|
3402
|
+
return {iface: alarm.ALARM_IFACE, waiting: true};
|
|
3403
|
+
}
|
|
3404
|
+
|
|
3334
3405
|
/**
|
|
3335
3406
|
* task 32: the description of a datapoint of a Logic channel, where it was fetched.
|
|
3336
3407
|
* @param {string} channel
|
|
@@ -4266,6 +4337,12 @@ module.exports = function (RED) {
|
|
|
4266
4337
|
}
|
|
4267
4338
|
});
|
|
4268
4339
|
|
|
4340
|
+
callbackPorts.forEach((holder, port) => {
|
|
4341
|
+
if (holder.node === this) {
|
|
4342
|
+
callbackPorts.delete(port);
|
|
4343
|
+
}
|
|
4344
|
+
});
|
|
4345
|
+
|
|
4269
4346
|
this.logger.debug('queue binrpc server closing');
|
|
4270
4347
|
calls.push(() => {
|
|
4271
4348
|
return new Promise((resolve) => {
|
|
@@ -4336,6 +4413,54 @@ module.exports = function (RED) {
|
|
|
4336
4413
|
return protocol + '://' + (this.rpcInitAddress || this.rpcServerHost) + ':' + port;
|
|
4337
4414
|
}
|
|
4338
4415
|
|
|
4416
|
+
/**
|
|
4417
|
+
* The callback server of a protocol could not listen (the port is taken, the address is
|
|
4418
|
+
* gone): the interfaces that use it show why, the log names the port and who holds it, and
|
|
4419
|
+
* the rest of the runtime keeps running.
|
|
4420
|
+
* @param {string} protocol binrpc, http or https
|
|
4421
|
+
* @param {number} port the callback port
|
|
4422
|
+
* @param {Error} err the socket's error
|
|
4423
|
+
*/
|
|
4424
|
+
callbackServerError(protocol, port, err) {
|
|
4425
|
+
const kind = protocol === 'binrpc' ? 'BINRPC' : 'XMLRPC';
|
|
4426
|
+
let text;
|
|
4427
|
+
if (err && err.code === 'EADDRINUSE') {
|
|
4428
|
+
const holder = callbackPorts.get(port);
|
|
4429
|
+
const other = holder && holder.node !== this ? holder.node : null;
|
|
4430
|
+
const name = other ? '"' + (other.name || other.id) + '" (' + other.id + ')' : '';
|
|
4431
|
+
this.logger.error(
|
|
4432
|
+
kind +
|
|
4433
|
+
' listening port ' +
|
|
4434
|
+
port +
|
|
4435
|
+
' is already in use' +
|
|
4436
|
+
(other
|
|
4437
|
+
? ' by the ccu-connection config node ' + name
|
|
4438
|
+
: ' by another process or an older ccu-connection config node') +
|
|
4439
|
+
' - give this config node "' +
|
|
4440
|
+
(this.name || this.id) +
|
|
4441
|
+
'" (' +
|
|
4442
|
+
this.id +
|
|
4443
|
+
') another ' +
|
|
4444
|
+
kind +
|
|
4445
|
+
' listening port, or delete one of the two',
|
|
4446
|
+
);
|
|
4447
|
+
text = 'port ' + port + ' in use' + (other ? ' by ' + (other.name || other.id) : '');
|
|
4448
|
+
} else {
|
|
4449
|
+
const message = (err && err.message) || String(err);
|
|
4450
|
+
this.logger.error(kind + ' server on port ' + port + ': ' + message);
|
|
4451
|
+
text = kind + ' server: ' + ((err && err.code) || message);
|
|
4452
|
+
}
|
|
4453
|
+
|
|
4454
|
+
Object.keys(this.ifaceTypes).forEach((iface) => {
|
|
4455
|
+
if (this.enabledIfaces.includes(iface) && this.ifaceTypes[iface].protocol === protocol) {
|
|
4456
|
+
this.serverError[iface] = text;
|
|
4457
|
+
this.ifaceError[iface] = text;
|
|
4458
|
+
this.ifaceStatus[iface] = false;
|
|
4459
|
+
}
|
|
4460
|
+
});
|
|
4461
|
+
this.pushStatus();
|
|
4462
|
+
}
|
|
4463
|
+
|
|
4339
4464
|
/**
|
|
4340
4465
|
*
|
|
4341
4466
|
* @param iface
|
|
@@ -4349,6 +4474,7 @@ module.exports = function (RED) {
|
|
|
4349
4474
|
this.servers[protocol] = rpc.createServer({host: this.rpcServerHost, port}, () => {
|
|
4350
4475
|
// Todo homematic-xmlrpc and binrpc module: clarify onListening callback params
|
|
4351
4476
|
this.logger.info(protocol === 'binrpc' ? 'binrpc' : 'xmlrpc', 'server listening on', url);
|
|
4477
|
+
callbackPorts.set(port, {node: this, protocol});
|
|
4352
4478
|
this.serverError[iface] = null;
|
|
4353
4479
|
});
|
|
4354
4480
|
if (this.servers[protocol].httpServer) {
|
|
@@ -4363,12 +4489,11 @@ module.exports = function (RED) {
|
|
|
4363
4489
|
this.servers[protocol].httpServer.headersTimeout = KEEP_ALIVE_TIMEOUT_MS + 5000;
|
|
4364
4490
|
}
|
|
4365
4491
|
|
|
4366
|
-
//
|
|
4367
|
-
|
|
4368
|
-
|
|
4369
|
-
|
|
4370
|
-
|
|
4371
|
-
});
|
|
4492
|
+
// Both modules re-emit the errors of their listening socket on the server object.
|
|
4493
|
+
// The listener sits there: binrpc >= 4.2 re-emits on its Server, and an 'error'
|
|
4494
|
+
// without a listener is thrown - a taken callback port (EADDRINUSE) ended the
|
|
4495
|
+
// whole Node-RED process instead of this connection.
|
|
4496
|
+
this.servers[protocol].on('error', (err) => this.callbackServerError(protocol, port, err));
|
|
4372
4497
|
|
|
4373
4498
|
Object.keys(this.rpcMethods).forEach((method) => {
|
|
4374
4499
|
this.servers[protocol].on(method, (err, parameters, callback) => {
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* task 38: the alarm areas of openccu-lite's alarm addon (lite-addon-alarm). The addon offers each
|
|
3
|
+
* area as a device of an interface of its own, which the system's lite-rpc carries like the radio
|
|
4
|
+
* interfaces (and like the Logic addon's):
|
|
5
|
+
*
|
|
6
|
+
* area `haus` device area-haus (ALARM-AREA), channel area-haus:1
|
|
7
|
+
* read/event STATE (ENUM: DISARMED, ARMING, ARMED_PERIMETER, ARMED_FULL, ENTRY_DELAY,
|
|
8
|
+
* TRIGGERED - Home Assistant's alarm_control_panel states disarmed, arming,
|
|
9
|
+
* armed_home, armed_away, pending, triggered, in this order), ALARM, ALARM_KIND
|
|
10
|
+
* (NONE, INTRUSION, TAMPER, PANIC, HAZARD), ALARM_SENSOR, READY, OPEN_SENSORS,
|
|
11
|
+
* DELAY (s), PREALARM
|
|
12
|
+
* write ARM (ENUM: DISARMED, PERIMETER, FULL), SILENCE, ACKNOWLEDGE, PANIC (ACTION)
|
|
13
|
+
*
|
|
14
|
+
* The addon decides what a write may do: arming, disarming, silencing and acknowledging are refused
|
|
15
|
+
* (fault -6, "... not allowed for this source") unless the area's switch "Scharf/Unscharf über
|
|
16
|
+
* lite-rpc erlauben" is on - off for a new area; arming is refused over sensors that are not in
|
|
17
|
+
* order ("not ready: ..."); a panic alarm is always taken.
|
|
18
|
+
*
|
|
19
|
+
* Pure helpers, no connection state: the node (ccu-alarm.js) keeps the area's values.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/** the interface's name as lite-addon-alarm registers it */
|
|
23
|
+
const ALARM_IFACE = 'Alarm';
|
|
24
|
+
|
|
25
|
+
/** the addon's id, `addon` in GET /api/rpc/v1/interfaces */
|
|
26
|
+
const ALARM_ADDON = 'alarm';
|
|
27
|
+
|
|
28
|
+
/** an area's device type */
|
|
29
|
+
const AREA_TYPE = 'ALARM-AREA';
|
|
30
|
+
|
|
31
|
+
/** STATE's entries, by index, and Home Assistant's state for each */
|
|
32
|
+
const STATES = ['DISARMED', 'ARMING', 'ARMED_PERIMETER', 'ARMED_FULL', 'ENTRY_DELAY', 'TRIGGERED'];
|
|
33
|
+
const HA_STATES = ['disarmed', 'arming', 'armed_home', 'armed_away', 'pending', 'triggered'];
|
|
34
|
+
|
|
35
|
+
/** ALARM_KIND's entries, by index */
|
|
36
|
+
const ALARM_KINDS = ['NONE', 'INTRUSION', 'TAMPER', 'PANIC', 'HAZARD'];
|
|
37
|
+
|
|
38
|
+
/** ARM's entries, by index */
|
|
39
|
+
const ARM_TARGETS = ['DISARMED', 'PERIMETER', 'FULL'];
|
|
40
|
+
|
|
41
|
+
/** the datapoints of an area's value channel the node follows */
|
|
42
|
+
const DATAPOINTS = ['STATE', 'ALARM', 'ALARM_KIND', 'ALARM_SENSOR', 'READY', 'OPEN_SENSORS', 'DELAY', 'PREALARM'];
|
|
43
|
+
|
|
44
|
+
/** the switch a refused command needs, as the addon names it (de, en) */
|
|
45
|
+
const SWITCH_DE = 'Scharf/Unscharf über lite-rpc erlauben';
|
|
46
|
+
const SWITCH_EN = 'Allow arming and disarming over lite-rpc';
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The commands msg.payload may carry: each to a write of the area's value channel. Home
|
|
50
|
+
* Assistant's service names (alarm_arm_home, ...) and its states (armed_home, ...) are taken as
|
|
51
|
+
* well, so a payload from HA needs no change node.
|
|
52
|
+
*/
|
|
53
|
+
const COMMANDS = {
|
|
54
|
+
arm_home: {command: 'arm_home', datapoint: 'ARM', value: 1},
|
|
55
|
+
arm_away: {command: 'arm_away', datapoint: 'ARM', value: 2},
|
|
56
|
+
disarm: {command: 'disarm', datapoint: 'ARM', value: 0},
|
|
57
|
+
silence: {command: 'silence', datapoint: 'SILENCE', value: true},
|
|
58
|
+
acknowledge: {command: 'acknowledge', datapoint: 'ACKNOWLEDGE', value: true},
|
|
59
|
+
panic: {command: 'panic', datapoint: 'PANIC', value: true},
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const ALIASES = {
|
|
63
|
+
armed_home: 'arm_home',
|
|
64
|
+
alarm_arm_home: 'arm_home',
|
|
65
|
+
perimeter: 'arm_home',
|
|
66
|
+
armed_perimeter: 'arm_home',
|
|
67
|
+
armed_away: 'arm_away',
|
|
68
|
+
alarm_arm_away: 'arm_away',
|
|
69
|
+
full: 'arm_away',
|
|
70
|
+
armed_full: 'arm_away',
|
|
71
|
+
disarmed: 'disarm',
|
|
72
|
+
alarm_disarm: 'disarm',
|
|
73
|
+
ack: 'acknowledge',
|
|
74
|
+
alarm_trigger: 'panic',
|
|
75
|
+
trigger: 'panic',
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Whether an interface the system lists is the alarm addon's: by its addon id, else by its name.
|
|
80
|
+
* @param {string} name
|
|
81
|
+
* @param {{addon?: string}} [info] the entry of GET /api/rpc/v1/interfaces
|
|
82
|
+
* @returns {boolean}
|
|
83
|
+
*/
|
|
84
|
+
function isAlarmIface(name, info) {
|
|
85
|
+
if (info && info.addon) {
|
|
86
|
+
return info.addon === ALARM_ADDON;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return name === ALARM_IFACE;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* An area's device address and value channel from what the editor stored (the device address, or
|
|
94
|
+
* its channel), else null.
|
|
95
|
+
* @param {string} area e.g. area-haus, area-haus:1
|
|
96
|
+
* @returns {{key: string, device: string, channel: string}|null}
|
|
97
|
+
*/
|
|
98
|
+
function parseArea(area) {
|
|
99
|
+
const match = /^area-([^:\s]+)(?::1)?$/.exec(String(area || '').trim());
|
|
100
|
+
if (!match) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return {key: match[1], device: 'area-' + match[1], channel: 'area-' + match[1] + ':1'};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* The command a payload stands for, else null.
|
|
109
|
+
* @param {*} payload
|
|
110
|
+
* @returns {{command: string, datapoint: string, value: *}|null}
|
|
111
|
+
*/
|
|
112
|
+
function parseCommand(payload) {
|
|
113
|
+
if (typeof payload !== 'string') {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const word = payload.trim().toLowerCase();
|
|
118
|
+
const own = (table, key) => Object.prototype.hasOwnProperty.call(table, key);
|
|
119
|
+
const name = own(COMMANDS, word) ? word : own(ALIASES, word) ? ALIASES[word] : null;
|
|
120
|
+
return name ? {...COMMANDS[name]} : null;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* An ENUM value as its index: the number, or the entry's name.
|
|
125
|
+
* @param {*} value
|
|
126
|
+
* @param {string[]} list
|
|
127
|
+
* @returns {number} -1 when it is none of them
|
|
128
|
+
*/
|
|
129
|
+
function enumIndex(value, list) {
|
|
130
|
+
if (typeof value === 'number' && Number.isInteger(value) && value >= 0 && value < list.length) {
|
|
131
|
+
return value;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (typeof value === 'string') {
|
|
135
|
+
const index = list.indexOf(value.toUpperCase());
|
|
136
|
+
if (index !== -1) {
|
|
137
|
+
return index;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (/^\d+$/.test(value)) {
|
|
141
|
+
return enumIndex(Number(value), list);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return -1;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* The area as the node puts it out, from the values of its datapoints.
|
|
150
|
+
* @param {object} values STATE, ALARM, ... as the interface sent them (missing ones are not known yet)
|
|
151
|
+
* @returns {{payload: string|undefined, state: string|undefined, alarm: object, ready: boolean|undefined,
|
|
152
|
+
* openSensors: number|undefined, delay: number|undefined, prealarm: boolean|undefined}}
|
|
153
|
+
*/
|
|
154
|
+
function areaState(values) {
|
|
155
|
+
const v = values || {};
|
|
156
|
+
const state = enumIndex(v.STATE, STATES);
|
|
157
|
+
const kind = enumIndex(v.ALARM_KIND, ALARM_KINDS);
|
|
158
|
+
const bool = (x) => (x === undefined || x === null ? undefined : Boolean(x));
|
|
159
|
+
const number = (x) => (x === undefined || x === null || Number.isNaN(Number(x)) ? undefined : Number(x));
|
|
160
|
+
return {
|
|
161
|
+
payload: state === -1 ? undefined : HA_STATES[state],
|
|
162
|
+
state: state === -1 ? undefined : STATES[state],
|
|
163
|
+
alarm: {
|
|
164
|
+
active: bool(v.ALARM),
|
|
165
|
+
kind: kind > 0 ? ALARM_KINDS[kind].toLowerCase() : null,
|
|
166
|
+
sensor: typeof v.ALARM_SENSOR === 'string' && v.ALARM_SENSOR !== '' ? v.ALARM_SENSOR : null,
|
|
167
|
+
},
|
|
168
|
+
ready: bool(v.READY),
|
|
169
|
+
openSensors: number(v.OPEN_SENSORS),
|
|
170
|
+
delay: number(v.DELAY),
|
|
171
|
+
prealarm: bool(v.PREALARM),
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* What a refused write means, from the interface's fault: the area's switch is off, it is not
|
|
177
|
+
* ready (the sensors in the way), it is armed at the other level, or it is gone.
|
|
178
|
+
* @param {Error} error with faultCode/faultString where the interface answered
|
|
179
|
+
* @returns {{reason: 'switch'|'not-ready'|'armed'|'unknown-area'|'other', text: string}}
|
|
180
|
+
*/
|
|
181
|
+
function refusal(error) {
|
|
182
|
+
const text = String((error && (error.faultString || error.message)) || error || '');
|
|
183
|
+
// the interface's words: "<DATAPOINT> of <address>: <the engine's refusal>"
|
|
184
|
+
const reason = text.replace(/^[A-Z_]+ of area-\S+: /, '');
|
|
185
|
+
if (/not allowed for this source/.test(text)) {
|
|
186
|
+
return {reason: 'switch', text: reason};
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (/not ready/.test(text)) {
|
|
190
|
+
return {reason: 'not-ready', text: reason};
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (/armed at another level|armed at the other level/.test(text)) {
|
|
194
|
+
return {reason: 'armed', text: reason};
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if ((error && error.faultCode === -2) || /no such area|unknown (device|channel)|is gone/.test(text)) {
|
|
198
|
+
return {reason: 'unknown-area', text: reason};
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return {reason: 'other', text: reason};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* The log line for a command the area's switch refused: what to switch on, and where.
|
|
206
|
+
* @param {string} command e.g. arm_away
|
|
207
|
+
* @param {string} areaName
|
|
208
|
+
* @returns {string}
|
|
209
|
+
*/
|
|
210
|
+
function switchMessage(command, areaName) {
|
|
211
|
+
return (
|
|
212
|
+
command +
|
|
213
|
+
' refused: the alarm area "' +
|
|
214
|
+
areaName +
|
|
215
|
+
'" does not let lite-rpc clients arm, disarm, silence or acknowledge. Switch on "' +
|
|
216
|
+
SWITCH_DE +
|
|
217
|
+
'" (' +
|
|
218
|
+
SWITCH_EN +
|
|
219
|
+
') in the alarm addon: Bereiche → ' +
|
|
220
|
+
areaName +
|
|
221
|
+
' → ' +
|
|
222
|
+
SWITCH_DE +
|
|
223
|
+
'. A panic alarm needs no switch.'
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
module.exports = {
|
|
228
|
+
ALARM_IFACE,
|
|
229
|
+
ALARM_ADDON,
|
|
230
|
+
AREA_TYPE,
|
|
231
|
+
STATES,
|
|
232
|
+
HA_STATES,
|
|
233
|
+
ALARM_KINDS,
|
|
234
|
+
ARM_TARGETS,
|
|
235
|
+
DATAPOINTS,
|
|
236
|
+
SWITCH_DE,
|
|
237
|
+
SWITCH_EN,
|
|
238
|
+
COMMANDS,
|
|
239
|
+
isAlarmIface,
|
|
240
|
+
parseArea,
|
|
241
|
+
parseCommand,
|
|
242
|
+
enumIndex,
|
|
243
|
+
areaState,
|
|
244
|
+
refusal,
|
|
245
|
+
switchMessage,
|
|
246
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
<script type="text/html" data-help-name="ccu-alarm">
|
|
2
|
+
<p>Ein Bereich der Alarmanlage von openccu-lite (das Addon <i>Alarmanlage</i>): sein Zustand und seine Alarme
|
|
3
|
+
am Ausgang, Scharf- und Unscharfschalten, Stummschalten, Bestätigen und Panik am Eingang.</p>
|
|
4
|
+
<p>Die Alarmanlage ist eine Schnittstelle des Systems mit dem Namen <code>Alarm</code>; jeder Bereich ist dort
|
|
5
|
+
ein Gerät <code>area-<Schlüssel></code> vom Typ <code>ALARM-AREA</code>. Die Verbindung folgt ihr über
|
|
6
|
+
die lite-rpc des Systems, ohne Häkchen. Die Auswahl <i>Bereich</i> zeigt nur diese Geräte. Auf einer CCU, ohne
|
|
7
|
+
lite-rpc (die Verbindung nimmt sie für die angehakten Schnittstellen, mindestens eine muss es sein) oder ohne das Addon sagt der Node es (<i>needs openccu-lite</i>, <i>needs lite-rpc</i>, <i>alarm addon
|
|
8
|
+
not installed</i>).</p>
|
|
9
|
+
|
|
10
|
+
<h3>Eingang</h3>
|
|
11
|
+
<dl class="message-properties">
|
|
12
|
+
<dt>payload <span class="property-type">string</span></dt>
|
|
13
|
+
<dd>Der Befehl:
|
|
14
|
+
<ul>
|
|
15
|
+
<li><code>arm_home</code> - im Hüllschutz scharf schalten (<code>ARM</code> = <code>PERIMETER</code>)</li>
|
|
16
|
+
<li><code>arm_away</code> - im Vollschutz scharf schalten (<code>ARM</code> = <code>FULL</code>)</li>
|
|
17
|
+
<li><code>disarm</code> - unscharf schalten (<code>ARM</code> = <code>DISARMED</code>)</li>
|
|
18
|
+
<li><code>silence</code> - die Sirene stummschalten (<code>SILENCE</code>)</li>
|
|
19
|
+
<li><code>acknowledge</code> - den Alarm bestätigen (<code>ACKNOWLEDGE</code>)</li>
|
|
20
|
+
<li><code>panic</code> - einen Panikalarm auslösen (<code>PANIC</code>)</li>
|
|
21
|
+
</ul>
|
|
22
|
+
Groß- und Kleinschreibung zählt nicht. Die Dienste und Zustände von Home Assistant werden ebenso
|
|
23
|
+
verstanden: <code>alarm_arm_home</code>/<code>armed_home</code>, <code>alarm_arm_away</code>/<code>armed_away</code>,
|
|
24
|
+
<code>alarm_disarm</code>/<code>disarmed</code>, <code>alarm_trigger</code>.
|
|
25
|
+
</dd>
|
|
26
|
+
</dl>
|
|
27
|
+
<p><b>Was ein Befehl darf, entscheidet die Alarmanlage.</b> Scharf schalten, unscharf schalten, stummschalten
|
|
28
|
+
und bestätigen werden abgelehnt, solange der Schalter <i>Scharf/Unscharf über lite-rpc erlauben</i> des Bereichs
|
|
29
|
+
aus ist - bei einem neuen Bereich ist er aus. Einzuschalten ist er in der Alarmanlage unter
|
|
30
|
+
<i>Bereiche → (der Bereich) → Scharf/Unscharf über lite-rpc erlauben</i>. Der Node zeigt dann
|
|
31
|
+
<i>refused: lite-rpc switch off</i> und meldet einen Fehler (für einen <i>catch</i>-Node), der den Schalter
|
|
32
|
+
nennt. Scharf schalten wird auch mit dem Schalter abgelehnt, solange Melder nicht in Ordnung sind; der Fehler
|
|
33
|
+
nennt sie (<i>not ready: Fenster Küche (open)</i>), <code>msg.ready</code> sagt es vorher.
|
|
34
|
+
<b>Ein Panikalarm geht immer</b>, ohne den Schalter.</p>
|
|
35
|
+
|
|
36
|
+
<h3>Ausgang</h3>
|
|
37
|
+
<p>Eine Nachricht bei jeder Änderung des Bereichs; was in einem Schritt zusammen geändert wird (Zustand, Alarm,
|
|
38
|
+
Melder), kommt in einer Nachricht.</p>
|
|
39
|
+
<dl class="message-properties">
|
|
40
|
+
<dt>payload <span class="property-type">string</span></dt>
|
|
41
|
+
<dd>Der Zustand, wie Home Assistant ihn nennt: <code>disarmed</code>, <code>arming</code> (Ausgangsverzögerung),
|
|
42
|
+
<code>armed_home</code> (Hüllschutz), <code>armed_away</code> (Vollschutz), <code>pending</code>
|
|
43
|
+
(Eingangsverzögerung), <code>triggered</code> (Alarm).</dd>
|
|
44
|
+
<dt>state <span class="property-type">string</span></dt>
|
|
45
|
+
<dd>Derselbe Zustand mit dem Namen des Datenpunkts <code>STATE</code>: <code>DISARMED</code>, <code>ARMING</code>,
|
|
46
|
+
<code>ARMED_PERIMETER</code>, <code>ARMED_FULL</code>, <code>ENTRY_DELAY</code>, <code>TRIGGERED</code>.</dd>
|
|
47
|
+
<dt>payloadPrevious <span class="property-type">string</span></dt>
|
|
48
|
+
<dd>Der Zustand der vorigen Nachricht.</dd>
|
|
49
|
+
<dt>alarm <span class="property-type">object</span></dt>
|
|
50
|
+
<dd><code>active</code>: ein Alarm läuft oder ist vermerkt und nicht bestätigt; <code>kind</code>:
|
|
51
|
+
<code>intrusion</code>, <code>tamper</code>, <code>panic</code>, <code>hazard</code> oder <code>null</code>;
|
|
52
|
+
<code>sensor</code>: der Name des Melders, der ihn zuerst ausgelöst hat, oder <code>null</code>.</dd>
|
|
53
|
+
<dt>ready <span class="property-type">boolean</span></dt>
|
|
54
|
+
<dd>Nichts hindert den Bereich daran, im Vollschutz scharf zu schalten.</dd>
|
|
55
|
+
<dt>openSensors <span class="property-type">number</span></dt>
|
|
56
|
+
<dd>Wie viele Melder ihn daran hindern.</dd>
|
|
57
|
+
<dt>delay <span class="property-type">number</span></dt>
|
|
58
|
+
<dd>Die Länge der laufenden Ausgangs- oder Eingangsverzögerung in Sekunden, 0, wenn keine läuft.</dd>
|
|
59
|
+
<dt>prealarm <span class="property-type">boolean</span></dt>
|
|
60
|
+
<dd>Ein Voralarm läuft.</dd>
|
|
61
|
+
<dt>area <span class="property-type">object</span></dt>
|
|
62
|
+
<dd><code>key</code>, <code>address</code> (<code>area-<Schlüssel></code>) und <code>name</code> des Bereichs.</dd>
|
|
63
|
+
<dt>changed <span class="property-type">array</span></dt>
|
|
64
|
+
<dd>Die Datenpunkte, die sich geändert haben; leer bei der Nachricht beim Start.</dd>
|
|
65
|
+
<dt>cache <span class="property-type">boolean</span></dt>
|
|
66
|
+
<dd><code>true</code> bei der Nachricht beim Start (<i>Zustand beim Start ausgeben</i>).</dd>
|
|
67
|
+
</dl>
|
|
68
|
+
<p>Der Status des Nodes zeigt den Zustand, einen Alarm, einen Voralarm, einen nicht bereiten Bereich und eine
|
|
69
|
+
Ablehnung.</p>
|
|
70
|
+
|
|
71
|
+
<h3>Topic</h3>
|
|
72
|
+
<p><code>msg.topic</code> wird aus dem Feld <i>Topic</i> gebildet; <code>${Name}</code> steht für den Namen des
|
|
73
|
+
Bereichs (Vorgabe <code>hm/status/alarm/${Name}</code>).</p>
|
|
74
|
+
</script>
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
<script type="text/html" data-help-name="ccu-alarm">
|
|
2
|
+
<p>An area of openccu-lite's alarm system (the <i>alarm system</i> addon): its state and its alarms at the
|
|
3
|
+
output; arming, disarming, silencing, acknowledging and panic at the input.</p>
|
|
4
|
+
<p>The alarm system is an interface of the system called <code>Alarm</code>; every area is a device
|
|
5
|
+
<code>area-<key></code> of the type <code>ALARM-AREA</code> there. The connection follows it through the
|
|
6
|
+
system's lite-rpc, without a checkbox. The <i>Area</i> picker shows only these devices. On a CCU, without
|
|
7
|
+
lite-rpc (the connection uses it for its ticked interfaces, at least one has to be) or without the addon the node says so (<i>needs openccu-lite</i>, <i>needs lite-rpc</i>, <i>alarm addon
|
|
8
|
+
not installed</i>).</p>
|
|
9
|
+
|
|
10
|
+
<h3>Input</h3>
|
|
11
|
+
<dl class="message-properties">
|
|
12
|
+
<dt>payload <span class="property-type">string</span></dt>
|
|
13
|
+
<dd>The command:
|
|
14
|
+
<ul>
|
|
15
|
+
<li><code>arm_home</code> - arm at perimeter protection (<code>ARM</code> = <code>PERIMETER</code>)</li>
|
|
16
|
+
<li><code>arm_away</code> - arm at full protection (<code>ARM</code> = <code>FULL</code>)</li>
|
|
17
|
+
<li><code>disarm</code> - disarm (<code>ARM</code> = <code>DISARMED</code>)</li>
|
|
18
|
+
<li><code>silence</code> - silence the siren (<code>SILENCE</code>)</li>
|
|
19
|
+
<li><code>acknowledge</code> - acknowledge the alarm (<code>ACKNOWLEDGE</code>)</li>
|
|
20
|
+
<li><code>panic</code> - raise a panic alarm (<code>PANIC</code>)</li>
|
|
21
|
+
</ul>
|
|
22
|
+
Case does not matter. Home Assistant's services and states are understood as well:
|
|
23
|
+
<code>alarm_arm_home</code>/<code>armed_home</code>, <code>alarm_arm_away</code>/<code>armed_away</code>,
|
|
24
|
+
<code>alarm_disarm</code>/<code>disarmed</code>, <code>alarm_trigger</code>.
|
|
25
|
+
</dd>
|
|
26
|
+
</dl>
|
|
27
|
+
<p><b>What a command may do is decided by the alarm system.</b> Arming, disarming, silencing and acknowledging
|
|
28
|
+
are refused unless the area's switch <i>Allow arming and disarming over lite-rpc</i> (German <i>Scharf/Unscharf
|
|
29
|
+
über lite-rpc erlauben</i>) is on - it is off for a new area. It is switched on in the alarm system under
|
|
30
|
+
<i>Areas → (the area) → Allow arming and disarming over lite-rpc</i>. The node then shows <i>refused: lite-rpc
|
|
31
|
+
switch off</i> and reports an error (for a <i>catch</i> node) that names the switch. Arming is refused, even with
|
|
32
|
+
the switch on, while sensors are not in order; the error names them (<i>not ready: Kitchen window (open)</i>),
|
|
33
|
+
and <code>msg.ready</code> says so beforehand. <b>A panic alarm always works</b>, without the switch.</p>
|
|
34
|
+
|
|
35
|
+
<h3>Output</h3>
|
|
36
|
+
<p>A message at every change of the area; what changes together in one step (state, alarm, sensors) comes in one
|
|
37
|
+
message.</p>
|
|
38
|
+
<dl class="message-properties">
|
|
39
|
+
<dt>payload <span class="property-type">string</span></dt>
|
|
40
|
+
<dd>The state as Home Assistant names it: <code>disarmed</code>, <code>arming</code> (exit delay),
|
|
41
|
+
<code>armed_home</code> (perimeter), <code>armed_away</code> (full protection), <code>pending</code> (entry
|
|
42
|
+
delay), <code>triggered</code> (alarm).</dd>
|
|
43
|
+
<dt>state <span class="property-type">string</span></dt>
|
|
44
|
+
<dd>The same state by the name of the datapoint <code>STATE</code>: <code>DISARMED</code>, <code>ARMING</code>,
|
|
45
|
+
<code>ARMED_PERIMETER</code>, <code>ARMED_FULL</code>, <code>ENTRY_DELAY</code>, <code>TRIGGERED</code>.</dd>
|
|
46
|
+
<dt>payloadPrevious <span class="property-type">string</span></dt>
|
|
47
|
+
<dd>The state of the message before.</dd>
|
|
48
|
+
<dt>alarm <span class="property-type">object</span></dt>
|
|
49
|
+
<dd><code>active</code>: an alarm is running or is noted and not acknowledged; <code>kind</code>:
|
|
50
|
+
<code>intrusion</code>, <code>tamper</code>, <code>panic</code>, <code>hazard</code> or <code>null</code>;
|
|
51
|
+
<code>sensor</code>: the name of the sensor that raised it first, or <code>null</code>.</dd>
|
|
52
|
+
<dt>ready <span class="property-type">boolean</span></dt>
|
|
53
|
+
<dd>Nothing keeps the area from arming at full protection.</dd>
|
|
54
|
+
<dt>openSensors <span class="property-type">number</span></dt>
|
|
55
|
+
<dd>How many sensors keep it from that.</dd>
|
|
56
|
+
<dt>delay <span class="property-type">number</span></dt>
|
|
57
|
+
<dd>The length of the exit or entry delay that is running, in seconds; 0 when none is.</dd>
|
|
58
|
+
<dt>prealarm <span class="property-type">boolean</span></dt>
|
|
59
|
+
<dd>A pre-alarm is running.</dd>
|
|
60
|
+
<dt>area <span class="property-type">object</span></dt>
|
|
61
|
+
<dd>The area's <code>key</code>, <code>address</code> (<code>area-<key></code>) and <code>name</code>.</dd>
|
|
62
|
+
<dt>changed <span class="property-type">array</span></dt>
|
|
63
|
+
<dd>The datapoints that changed; empty for the message at start.</dd>
|
|
64
|
+
<dt>cache <span class="property-type">boolean</span></dt>
|
|
65
|
+
<dd><code>true</code> for the message at start (<i>Emit the state on start</i>).</dd>
|
|
66
|
+
</dl>
|
|
67
|
+
<p>The node's status shows the state, an alarm, a pre-alarm, an area that is not ready, and a refusal.</p>
|
|
68
|
+
|
|
69
|
+
<h3>Topic</h3>
|
|
70
|
+
<p><code>msg.topic</code> is built from the <i>Topic</i> field; <code>${Name}</code> stands for the area's name
|
|
71
|
+
(default <code>hm/status/alarm/${Name}</code>).</p>
|
|
72
|
+
</script>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-ccu",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.18.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "none",
|
|
6
6
|
"keywords": [
|
|
@@ -95,7 +95,8 @@
|
|
|
95
95
|
"ccu-switch": "nodes/ccu-switch.js",
|
|
96
96
|
"ccu-hm2mqtt": "nodes/ccu-mqtt.js",
|
|
97
97
|
"ccu-homeassistant": "nodes/ccu-homeassistant.js",
|
|
98
|
-
"ccu-alexa": "nodes/ccu-alexa.js"
|
|
98
|
+
"ccu-alexa": "nodes/ccu-alexa.js",
|
|
99
|
+
"ccu-alarm": "nodes/ccu-alarm.js"
|
|
99
100
|
}
|
|
100
101
|
},
|
|
101
102
|
"repository": {
|