[APP][Pro] Device Capabilities - Enhance the capabilities of devices

Sorry for the inconvenience.
I just checked, and the updated version is different.
Now I don’t understand how the 3 homeyscript cards and that script ended up with your flows after the import. When did you imported the TEF? Not recently?

I just imported the TEF twice, to make sure, and it is the one I expect; there’s one Homeyscript card in it, and this is te code in it:

// Sensor.Check, to check on sensor last update time. Argument: inactive time (in seconds):

const INVALIDATE_AFTER = (args[0]); // Example 86400sec./3600 = 24hrs

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)) {
    
    if (device.capabilitiesObj.measure_temperature || device.capabilitiesObj.alarm_contact || device.capabilitiesObj.alarm_motion ) { 

      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 + "\n   (zone: " + device.zoneName + ")" );
  }
}

// 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: \n" + invalidatedDevices.join('\n') + "\n\nflow Sensors Check"
          },
        });

  console.log("Devices without updates for " + INVALIDATE_AFTER / 3600 + "hrs: \n" + invalidatedDevices.join('\n'));
  return("Devices without updates for " + INVALIDATE_AFTER / 3600 + "hrs: \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\n\nflow Sensors Check"
          },
        });

  console.log("Devices without updates for " + INVALIDATE_AFTER / 3600 + "hrs: None" );
  return invalidatedDevices.length != 0;
}

// Original script by Robert Klep  
// https://community.homey.app/t/a-script-to-check-sensor-last-update/63142/9

I used build in template…yesterday. :wink: Let me check if anything change when using the TEF code directly.

1 Like

That’s odd :upside_down_face: The template extracts the TEF code from that topic post, it’s the same TEF.
But anyways, now you should be able to run the right code :wink:

2 Likes

It works now, thank you - I like tough the time stamp included in the previous version / notifications, will check if I’m able to add this myself.

2 Likes

YW! Yes, the previous version returned all of your sensors with a timestamp for you to check, the current version only returns the ‘faulty’ sensors.
But, I’ve tried some things, and this works, but at this time only for one sensor capability. I can’t get my head around how to use a wildcard for that.

In this case, I would like to wildcard the capabilities measure_temperature , alarm_sensor and alarm_contact

  ////  invalidatedDevices.push("- " + device.name + "\n   (zone: " + device.zoneName + ")" ); Original line

  // test with timestamps
  invalidatedDevices.push("- " + device.name + " - " + device.capabilitiesObj?.measure_temperature?.lastUpdated?.substring(0,16) + "\n   (zone: " + device.zoneName + ")" ); // WORKS, but only for one SENSORTYPE


Screenshot from 2023-01-09 19-22-52
`

2 Likes

Hm, thank you, honestly I would be not able to figure that condition myself … it’s a pity it doesn’t work for others sensors. Peter, would you mind to share a condition, how to exclude specific devices names from check ? That’s possibly the only / last thing missing :wink:

1 Like

The IF-card “variable has changed” doesn’t trigger the flow. I’m not sure why, because I can see the variable changing in the virtual device.

1 Like

Which card do you mean?

Can you share a screenshot?

1 Like

How do you change/set the value?

1 Like

The last card: do nothing, change that to: trigger flowcards.

Ahhhh… thank you :innocent: just a question: why does it differ from Homey’s logic?

1 Like

What do you mean?

Why would you change the value without triggering an IF-card that should trigger when the value has changed?

1 Like

If I explain it well:
That way you can be in control over which THEN cards, to which a value is set, can trigger the common WHEN card or not.

Personally I would like to be “and trigger flowcards” the default Then card option, instead of “and do nothing”. Or, make the default option set-able in the app settings.

1 Like

Because you might only want to have it triggered when changing through the API, Homey App or Web App.

Perhaps i can buildin a option to change the default, but because the option was buildin later, i build it like this to not break existing flows at that time.

Thanks for the explanation. Something like the old virtual devices to “turn them on without trigger”. Default trigger would indeed be better in my opinion. Thanks Arie!

1 Like

Hi @Arie_J_Godschalk,
with the actually Homey TestFlight app for iOS devices v6.11.12 (1039) it’s not possible to create a new AVD. It’s not possible to change the name of the AVD and then save it. The problem is that the keyboard isn’t available.
I guess it’s Homey app related, but I just wanted to inform you about this issue.

I will inform Athom.

1 Like

Just release to Live:

  • Resolved: Settings/Repairscreen didn’t show correctly since new homey update.
  • Resolved: Templates didn’t load anymore because of a change in the Forum.
3 Likes