mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2024-11-17 02:48:31 -07:00
Elapsed time (#909)
* new elapsed attribute giving the elapsed time since the previous msg * configurable elapsed attribute * Update deviceReceive.js * Update deviceReceive.js
This commit is contained in:
parent
d324a91a5f
commit
9e5fb04314
@ -58,4 +58,6 @@ advanced:
|
||||
# Optional: Add a last_seen attribute to MQTT messages, contains date/time of last Zigbee message
|
||||
# possible values are: disable (default), ISO_8601, epoch
|
||||
last_seen: 'disable'
|
||||
# Optional: Add an elapsed attribute to MQTT messages, contains milliseconds since the previous msg
|
||||
elapsed: false
|
||||
```
|
@ -13,6 +13,7 @@ class DeviceReceive {
|
||||
this.state = state;
|
||||
this.publishDeviceState = publishDeviceState;
|
||||
this.coordinator = null;
|
||||
this.elapsed = {};
|
||||
}
|
||||
|
||||
onZigbeeStarted() {
|
||||
@ -113,15 +114,24 @@ class DeviceReceive {
|
||||
}
|
||||
|
||||
// Add last seen timestamp
|
||||
const now = Date.now();
|
||||
switch (settings.get().advanced.last_seen) {
|
||||
case 'ISO_8601':
|
||||
payload.last_seen = new Date().toISOString();
|
||||
payload.last_seen = new Date(now).toISOString();
|
||||
break;
|
||||
case 'epoch':
|
||||
payload.last_seen = Date.now();
|
||||
payload.last_seen = now;
|
||||
break;
|
||||
}
|
||||
|
||||
if (settings.get().advanced.elapsed) {
|
||||
if (this.elapsed[device.ieeeAddr]) {
|
||||
payload.elapsed = now - this.elapsed[device.ieeeAddr];
|
||||
}
|
||||
|
||||
this.elapsed[device.ieeeAddr] = now;
|
||||
}
|
||||
|
||||
this.publishDeviceState(device, payload, cache);
|
||||
};
|
||||
|
||||
|
@ -39,6 +39,9 @@ const defaults = {
|
||||
*/
|
||||
last_seen: 'disable',
|
||||
|
||||
// Optional: Add an elapsed attribute to MQTT messages, contains milliseconds since the previous msg
|
||||
elapsed: false,
|
||||
|
||||
/**
|
||||
* https://github.com/Koenkk/zigbee2mqtt/issues/685#issuecomment-449112250
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user