# The Flow Exchange(r) - Exchange Your Flows with Others!

**URL:** <https://community.homey.app/t/the-flow-exchange-r-exchange-your-flows-with-others/68981>\
**Category:** Flows\
**Tags:** app, tools, advancedflow, device-capabilities, avd\
**Created:** [September 16, 2022, 7:36pm UTC](https://community.homey.app/t/the-flow-exchange-r-exchange-your-flows-with-others/68981 "2022-09-16T19:36:49Z")\
**Posts on this page:** 1\
**Showing post:** 13

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [September 23, 2022, 12:15pm UTC](https://community.homey.app/t/the-flow-exchange-r-exchange-your-flows-with-others/68981/13 "2022-09-23T12:15:39Z")

</div>

# 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.

 ![Screenshot from 2023-07-20 16-00-33](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/4/8/480a42453bde95e0d0ef315dcec574a58d57b90c.png)

### Apps used:

- [HomeyScript](https://homey.app/a/com.athom.homeyscript/)
- (optional) [Simple (Sys) Log](https://homey.app/a/nl.nielsdeklerk.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):  
 ![Peek 2022-09-23 16-02](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/4/1/41ad2e9830042cc9421bbf1380e0318d369f8b19.gif)

#### The script used here (latest version: check [here](https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/25)):

> **Click to view the script**
>
> ```auto
> // Version 0.3b 
> // Script checks devices based on the last updated time against a threshold
> // Focuses on temperature sensors and specified device classes
> 
> const NotReportingThreshold = 0.8; // 0.8 hours, which is 48 minutes
> const thresholdInMillis = NotReportingThreshold * 3600000; // Convert hours to milliseconds
> 
> let DevicesNotReporting = [];
> let devices = await Homey.devices.getDevices();
> let notReportingCount = 0; // Variable to keep track of the count
> 
> // Function to format date as "dd-mm-yyyy, hh:mm:ss"
> function formatDate(date) {
> if (!date) return "Unknown"; // Return 'Unknown' if date is null or invalid
> 
> const day = date.getDate().toString().padStart(2, '0');
> const month = (date.getMonth() + 1).toString().padStart(2, '0'); // Months are 0-indexed
> const year = date.getFullYear().toString();
> const hours = date.getHours().toString().padStart(2, '0');
> const minutes = date.getMinutes().toString().padStart(2, '0');
> const seconds = date.getSeconds().toString().padStart(2, '0');
> 
> return `${day}-${month}-${year}, ${hours}:${minutes}:${seconds}`;
> }
> 
> for (const device of Object.values(devices)) {
> // Exclude Virtual Devices and specific apps
> if (device.driverUri && device.driverUri.match('vdevice|nl.qluster-it.DeviceCapabilities|nl.fellownet.chronograph|net.i-dev.betterlogic|com.swttt.devicegroups|com.gruijter.callmebot|com.netscan')) continue; 
> 
> // Include by regex device name, focusing on temperature-related devices
> if (!device.name || !device.name.match(/temperature/i)) continue;
> 
> // Exclude devices based on specific name patterns (if necessary, uncomment and modify)
> // if (device.name.match(/Flood|TVOC|Netatmo Rain|Motion|Flora|Rear gate Vibration Sensor|Vibration Sensor Attic Doors/i)) continue;
> 
> // Include devices based on device class
> if (!device.class || !device.class.match(/sensor|button|remote|socket|lights/i)) continue;
> 
> let IsReporting = false;
> let lastUpdated = null;
> 
> for (const capability of Object.values(device.capabilitiesObj)) {
> if (!capability.lastUpdated) continue; // Skip capabilities without lastUpdated info
> let timeSinceReport = Date.now() - new Date(capability.lastUpdated).getTime();
> if (timeSinceReport < thresholdInMillis) {
> IsReporting = true;
> break;
> }
> // Track the most recent update
> if (!lastUpdated || new Date(capability.lastUpdated) > new Date(lastUpdated)) {
> lastUpdated = new Date(capability.lastUpdated);
> }
> }
> 
> if (!IsReporting) {
> let deviceInfo = `${device.name} (${formatDate(lastUpdated)} - ${device.class}) (NOK)`;
> DevicesNotReporting.push(deviceInfo);
> console.log('NOK:', deviceInfo);
> 
> // Increment the count
> notReportingCount++;
> } else {
> let deviceInfo = `${device.name} (${formatDate(lastUpdated)} - ${device.class}) (OK)`;
> console.log('OK:', deviceInfo);
> }
> }
> 
> // Output for script AND card
> await tag('InvalidatedDevices', DevicesNotReporting.join('\n'));
> await tag('notReportingCount', notReportingCount);
> 
> // Define a return value
> const myTag = `Not Reporting Count: ${notReportingCount}\nDevices Not Reporting:\n${DevicesNotReporting.join('\n')}`;
> 
> // Return the defined value
> return myTag;
> 
> // Original script by Robert Klep
> // https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/9
> 
> ```

Output example:

 ![signal-2023-07-20-160427_002](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/e/d/ed765620ad4c75cf553fe4371d0f3aa7f79500f5.jpeg)

TEF:

```auto
[tef:FLOWS:"H4sIAAAAAAACA+1Y62/bthb/V1gNWOzb0Nb7VfReBEmGBe1thyZdP8RZwJdsNTJlUFTStMr/vkNKTu0k3Vxg2O6HayCORR6eF3/npS9O6+RfnJgGQUACgf00JTh0swwTt6C4CDI3ILEbsSQ0dNLJnV+EFgq9IjfEubvbd7RZZ/VyQvQCvuFP3DZMlSu9PvCzWTrtl+CArCayFFXDxVUl1NWkqudrytNyuaoEGp3eNmP0GtaNAOLk51+cErY5Y77v0QBHQZzhkHkEk4L4OE3D1HVj7hWecPZ7TkI2tWrQ4UKwK1hjRoTnMqAqUuwGzMUhZQyOBjEOU5/EacJDn6aG7pOTu/vOrZN7LvyvgZ21Kl8SSeZC5UzVEngalXS5FJfiE2G6unWsMxytyjlQwVMDmjuMJG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wfbrKzNHPPXyrZ8iTiRMKZe2zbrsVx9PnfZVHQydDBC/68gpzOBjJ07L+4l3cw30mwp8BlsBPBaE2X7FTPW+tZ1yJvw4gNEzoykO04JhQoMYiyzxPD9J4pQnT7/asVMX6s35g9czvr/rGHh3d3H3O34Agok0FQAA":/tef]

```

---

_[View the full topic](https://community.homey.app/t/the-flow-exchange-r-exchange-your-flows-with-others/68981)._
