Sensor (or any device) Connection Check.
Sometimes, you’ll discover a sensor or other device doesn’t report it’s status or value anymore, but it does NOT notify you of being offline…
Well, this flow checks the, most recent update time of your sensors.
You can run the flow every day, twice a day, just add or remove a time triggercard.
The ‘inactive time’ can be edited as well (24hrs as default) and you can choose to not send notifications when all sensors did report inside the ‘inactive timer’ timeframe.
Apps used:
- HomeyScript
- (optional) Simple (Sys) Log
- For now, in the imported flow, you’ll have to replace the ‘dummy’ DeviceCapabilities cards with HomeyScript THEN card “
Run 'CODE' _with ARGUMENT_, and return 'TEXT-TAG'
”.
But first copy the script inside them:
-
- use CTRL+A and then CTRL+C,
-
- to paste it later on, use CTRL+A and then CTRL+V in the HomeyScript card.
A how-to screenvid (of a similar flowcard):
- to paste it later on, use CTRL+A and then CTRL+V in the HomeyScript card.
The script used here:
Click to view
// Check last_update status. Argument: inactive time (in seconds):
const INVALIDATE_AFTER = args[0]; // xmpl: 86400 = 1 day (24h)
const invalidatedDevices = [];
for (const device of Object.values(await Homey.devices.getDevices())) {
if (! device.capabilitiesObj) continue;
let count = 0;
for (const capabilityObj of Object.values(device.capabilitiesObj)) {
// Exclude by app names virtual devices and other app devices
// (find correct app names via https://tools.developer.homey.app/tools/devices and look for "Driver")
if (device.driverUri.match('vdevice|DeviceCapabilities|chronograph|betterlogic|devicegroups|callmebot|netscan' )) continue;
// Exclude by (parts of) device name
if (device.name.match('^se|^pr|TST|z_|z |z. |IR|rris|eboo|rada|KNM|Timeline|#1|#0|ESP|esp|TV C|TV S|iffu|Unav|Wekk|OUD|OLD|Peter|Custom|Afval|LEDs')) continue;
if (! capabilityObj?.lastUpdated || (Date.now() - new Date(capabilityObj?.lastUpdated) > INVALIDATE_AFTER * 1000)) {
count++;
}
}
if (count && count === Object.keys(device.capabilitiesObj).length) {
invalidatedDevices.push(device.name);
}
}
// When there are matching sensors
if ( invalidatedDevices.length != 0 ) {
// Create / update HomeyScript variable
await tag('InvalidatedDevices', invalidatedDevices.join(', \n'));
// Send Timeline notification
Homey.flow.runFlowCardAction({
uri: 'homey:manager:notifications',
id: 'create_notification',
args: {
text: "\nDevices without updates for " + INVALIDATE_AFTER / 3600 + " hrs / " + INVALIDATE_AFTER / 3600 / 24 + " days:\n" + invalidatedDevices.join(', \n')
},
});
console.log("Devices without updates for " + INVALIDATE_AFTER / 3600 + " hrs / " + INVALIDATE_AFTER / 3600 / 24 + " days: \n" + invalidatedDevices.join(', \n'));
}
return("Devices without updates for " + INVALIDATE_AFTER / 3600 + " hrs / " + INVALIDATE_AFTER / 3600 / 24 + " days: \n" + invalidatedDevices.join(', \n'));
// When there's no matching sensor
if ( invalidatedDevices.length == 0 ) {
// just report "None"
// Create / update HomeyScript variable
await tag('InvalidatedDevices', 'None');
// Send Timeline notification
Homey.flow.runFlowCardAction({
uri: 'homey:manager:notifications',
id: 'create_notification',
args: {
text: "\nDevices without updates for " + INVALIDATE_AFTER / 3600 + "hrs: None"
},
});
console.log("Devices without updates for " + INVALIDATE_AFTER / 3600 + "hrs: None" );
}
return ("Devices without updates for " + INVALIDATE_AFTER / 3600 + "hrs / " + INVALIDATE_AFTER / 3600 / 24 + " days: None" );
// Original script by Robert Klep
// https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/9
Output:
TEF:
[tef:FLOWS:"H4sIAAAAAAACA+1Y62/bthb/V1gNWOzb0Nb7VfReBEmGBe1thyZdP8RZwJdsNTJlUFTStMr/vkNKTu0k3Vxg2O6HayCORR6eF3/npS9O6+RfnJgGQUACgf00JTh0swwTt6C4CDI3ILEbsSQ0dNLJnV+EFgq9IjfEubvbd7RZZ/VyQvQCvuFP3DZMlSu9PvCzWTrtl+CArCayFFXDxVUl1NWkqudrytNyuaoEGp3eNmP0GtaNAOLk51+cErY5Y77v0QBHQZzhkHkEk4L4OE3D1HVj7hWecPZ7TkI2tWrQ4UKwK1hjRoTnMqAqUuwGzMUhZQyOBjEOU5/EacJDn6aG7pOTu/vOrZN7LvyvgZ21Kl8SSeZC5UzVEngalXS5FJfiE2G6unW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