A flow to identify inactive sensors (values) / unavailable devices

I’ve tried to search through different topics without luck.
Is there any way to create a flow that notifies if a sensor value hasn’t changed/updated in, say 24 hours?

I basically want a notification if a sensor (eg. Aqara or Sonoff temp.) hasn’t changed.

I created this flow to identify unavailable devices, but I haven’t since I just created it, I haven’t had an alert yet.

I’m aware of this topic where a script has been used, but I’m not sure if it works and how to implement it?

Hej Jesper

You can use this importable flow (use the Device Capabilities app for it);
Including a how-to and script:

You can even import it right away using the app configuration, and pick “Templates”:

Hi Peter,

Thanks for helping out.
I’m not sure what to put here when importing the flow?

Can you help me out?
I’m an absolut noob in homey script and also at importing flows :smiley:
UPDATE: Never mind - I figured it out :slight_smile:
Thaks again :smiley:

@Peter_Kawa now I have this issue instead :confused:

Just hit “Update Text” and when you see code appear, hit the link “Homey API Playground”
This screen pops up, but first fully clear the input field with the default examples, and then CTRL + V (or use paste with the mouse menu)
Scroll back up, and hit the blue “Run” button.

When it succeeded, go back to the previous screen, it should show a link with the created flow:

I still get this error :confused:

image

Read the howto again. This card is a dummy card, which has to be replaced by the real Homeyscript card by you.

Oh, the card bottom left can be deleted (little error on my side).

Arh sorry for my incompetence :smiley:

One final little quirk now is that it returns the following headline “Devices without updates for NaN hrs / NaN days

Will this solve itself or am I doing something wrong?

Thanks again for helping out :slight_smile:

1 Like

NaN = Not a Number
Did you use the right Homeyscript card?

You have to choose the HomeyScript Flowcard* “Run Code with Argument and return Text-tag” and insert 43200 in the Argument section:
Bildschirmfoto 2023-08-02 um 16.27.29
Bildschirmfoto 2023-08-02 um 16.30.11
Then it should work.

*there is a little mistake in @Peter_Kawa 's video

Thank you both.
I needed to set the argument like you said @petomei
Thank you @Peter_Kawa for you contribution as well. I know you’re a very active member in the community - great work!

1 Like

The vid is from a similar “card swap”, and there’s no argument used. I thought “get the picture” would suffice.
Should I make a vid for the specific flow you think?

I also tested the homeyscript card without entering the seconds in the argument field, and it just returned all sensors, not NaN… not sure what was different

But I’m glad it works now, Jesper! @Yestond

Is there any way to only show certain censors like motion and temperature. Right now Chromecast values and other non-relevant values are part of the updates as well?

This thread has some usefull suggestions

Yes you can adjust the code starting at line 10 - ish

    // 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;



You can change it to something like this:

    // Exclude by app names
    // (find correct app names via https://tools.developer.homey.app/tools/devices and look for "Driver")
    if (device.driverUri.match('appNameYouDontWant|OtherAppNameYouDontWant')) continue;
    // Include by app names
    if (!device.driverUri.match('appNameYouWant|OtherAppNameYouWant')) continue;
    // Exclude by (parts of) device name
    if (device.name.match('nameOfSensorYouDontWantToCheck|nameOfOtherSensorYouDontWantToCheck')) continue;
    // Include by (parts of) device name
    if (!device.name.match('nameOfSensorYouWantToCheck|nameOfOtherSensorYouWantToCheck')) continue;



They should be excluded afaik, not included …
When I comment out (=disable) the “if (device.driverUri…” line, they all appear here, and I don´t want that:

    // Exclude by app names
    // (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;

I would like the script to include say after 24h (86400) but NOT after 48h to produce a syslog entry every day with unique devices.

Struggled with the
if (! capabilityObj?.lastUpdated || (Date.now() - new Date(capabilityObj?.lastUpdated) > INVALIDATE_AFTER * 1000)) { count++; }

to add another constraint for also exclude doubled time without success…

Any suggestions?

Also would like to throw an error if no devices match criteria, and NOT produce a empty log entry.

@robertklep

Perfect @Peter_Kawa. That did the trick. Thank you again :wink:

1 Like

The Device capability app has a card to retrive latest change for a device and its capability. The value will be in millisec so compare it to 2436001000. I am doing this for my important devices, works great.

Leaning towards Device Capabilities and ‘Duration till now’ result tag. This way there’s only one minimum duration instead of multiple LastUpdated records.

But how to call the ‘Retreive Insights’ THEN flowcard from a Homeyscript?

const { result: response }  = await Homey.flow.runFlowCardAction({
  uri: 'homey:app:nl.qluster-it.DeviceCapabilities',
  id: 'homey:app:nl.qluster-it.DeviceCapabilities:action_capability_log',
  args: {
    device: 'Motion Sensor 1',
    capability: 'Motion alarm',
    numberof: 0,
  },
});
log(response);

Hi, I used this flow and it works, only issue I have is that every device is being listed as no communication in last 12 hours. For example though, I see some devices have communicated with homey in that time. Does anyone have any ideas. Is there a way to check the last communication time for an individual device?