-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAltSensorState-mqtthing-1.32.patch
40 lines (39 loc) · 2.03 KB
/
AltSensorState-mqtthing-1.32.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
--- index-1.32.js 2021-11-24 13:00:26.000000000 +0100
+++ index.js 2021-11-24 09:47:32.000000000 +0100
@@ -1516,6 +1516,27 @@
function characteristic_StatusTampered( service ) {
booleanCharacteristic( service, 'statusTampered', Characteristic.StatusTampered, null, config.topics.getStatusTampered );
}
+
+ // Characteristic.AltSensorState to help detecting triggered state with multiple sensors
+ function characteristic_AltSensorState( service ) {
+ // additional MQTT subscription instead of set-callback due to correct averaging:
+ mqttSubscribe( config.topics.getAltSensorState, 'AltSensorState', function( topic, message ) {
+ // determine whether this is an on or off value
+ let newState = false; // assume off
+ if( isRecvValueOn( message ) ) {
+ newState = true; // received on value so on
+ } else if( !isRecvValueOff( message ) ) {
+ // received value NOT acceptable as 'off' so ignore message
+ return;
+ }
+
+ // if changed, set
+ if( state[ property ] != newState ) {
+ state[ property ] = newState;
+ propChangedHandler();
+ }
+ } );
+ }
// Characteristic.StatusLowBattery
function characteristic_StatusLowBattery( service ) {
@@ -2907,6 +2928,9 @@
if( config.topics.getStatusTampered ) {
characteristic_StatusTampered( service );
}
+ if( config.topics.getAltSensorState ) {
+ characteristic_AltSensorState( service );
+ }
// todo: SecuritySystemAlarmType
} else if( configType == "smokeSensor" ) {
service = new Service.SmokeSensor( name, subtype );