Flow to Monitor devices and notify if not being live

Hello everyone!

I wanted to share a solution I’ve developed for monitoring devices/sensors connectivity in my smart home setup. The problem I faced was not knowing if a sensor was working and sending up-to-date information. I’m sure everyone has had the problem with devices showing “last update 5 months ago” without knowing it.

This advanced flow has a time-based trigger, a HomeyScript, and sends notifications to my phone. Based on the criticality of the sensors/devices being monitored, I adjust the runtime on the flow trigger and what devices to monitor.

I have seen other solutions to the same problem on this forum, but I have found them a bit complicated to implement. If anyone else is in the same situation as me, feel free to test this flow and give feedback/further develop it to make it better.

#######
How to use the flow

Step1, Create the script
While using your computer, log in to your Homey portal and press “Web app”. In the left-side banner, click “HomeyScript”. Then click “+ New HomeyScript” and paste in the code from this

GitHub repo:
https://github.com/2re1million/homeydevicemonitor/blob/main/homeyDeviceMonitor.js

Step 2, Configure the script to suit you needs

One way to use the script is to:
(best if you have a few devices you want to monitor closely)

  • Edit line 20 (const SHOW_ALL_DEVICES) from false to true

  • Run the script in the editor, and copy the ID name of each individual device you want to monitor.

  • Paste the ID into the DEVICE_IDS_TO_SHOW inside the square brackets. (Remember that each ID needs quotation marks before and after the name. Use a comma between each ID.)

  • Set line 20 back to false after.

  • Example: const DEVICE_IDS_TO_SHOW = [“34sdf4-3433-332432-3sdfd”, “dsfs3d-3433-332432-3sdfd”, “55yytf4-3433-332432-3sdfd”];

The other option:
(best if there are many devices you want to monitor)

  • Add the class(es) you want to monitor to the “DEVICE_CLASSES_TO_SHOW” in line 25. (All of your lights for example.)
  • Different classes: [‘sensor’, ‘light’, ‘other’, ‘speaker’, ‘thermostat’, ‘socket’, ‘tv’, ‘blinds’, ‘remote’]
  • If there are some devices you don’t want to monitor, just add their device ID to the “DEVICE_IDS_TO_IGNORE” square brackets.
  • (You get the ID by running the script once with “SHOW_ALL_DEVICES” set to true and running it once)

Then ADJUST the time you want to be notified by.

Editing line 30, const MAX_TIME_SINCE_UPDATE = 48;

Critical devices should have a short time, e.g., 8 hours.
Non-critical devices might be multiple days, 48 or more.

Very important
Sometimes the output of the code in the editor is Error. This is most likely because there are no faulty devices. The script outputs an error if there are no sensors found (to stop the notification from being sent to your phone. I don’t want a notification multiple times a day saying my devices work as intended) :upside_down_face:

Step 3, Create a new “Advanced Flow” and set it up like this

It’s a time-based trigger card.
Then the code card is: HomeyScript with “Run Script”. Select your new code from the list of javascript files.

Then the notification card with you as a user.

I have also used the app “PaperTrails Log” to give some more information in the output, but this is not necessary at all.

Step 4)

Best practices should be to set up twice-a-day monitoring with few hours for critical devices…

For example, I have one flow, that checks, twice a day that the “water heater” and garage “dehumidifier” have been up and running for the last 8 hours.

Then I have a different flow with a weekly trigger to see if all devices with class sensors and lights have been running for the last 60 hours.

1 Like

Not to be an ass, but just FYI here’s a similar, less extended, script:

1 Like

Hi!

Thanks for the script, I set it up, but ran into a problem.
When I run the script, I get the output as shown in the picture.

Device “Snelk. Tafel” is an Ikea shortcut button (older style) which I use daily, although the script says it has been offline for 3 weeks.
Device “Wasmachine” is a socket which has been unplugged for some time, but I bought my (first) Homey two months ago, so 664 months seems a bit much… (I’m 372 months old :sweat_smile:)

Do you know what is happening here?

Script output:

Summary

=== Snelk. Tafel ===
Device Class: remote
Device ID: 01b871…
Batterij alarm: null (Last updated: 3 weeks ago)

=== PC Robbert ===
Device Class: socket
Device ID: 60cfe…
Aangezet: true (Last updated: 1 month ago)
Vermogen: null (Last updated: Never)
Accuniveau: 79 (Last updated: 1 month ago)

=== SP240 ===
Device Class: socket
Device ID: 66212…
Aangezet: true (Last updated: 1 month ago)
Energie: 0 (Last updated: 1 month ago)
Vermogen: 1 (Last updated: 1 month ago)
Stroom: 0.01 (Last updated: 1 month ago)
Voltage: 0 (Last updated: 1 month ago)

=== Wasmachine ===
Device Class: socket
Device ID: b5319a…
Aangezet: null (Last updated: Never)

=== Bewegingssensor ===
Device Class: sensor
Device ID: c51b…
Bewegingsalarm: false (Last updated: 2 days ago)

=== Achterdeur ===
Device Class: sensor
Device ID: dc7366…
Contact alarm: false (Last updated: 8 hours ago)
Accuniveau: 100 (Last updated: 1 month ago)

Device listing complete. 6 devices with issues found.

Total Devices Checked: 6

Devices with Issues: 6

———————————————————
:white_check_mark: Script Success

:leftwards_arrow_with_hook: Returned: true

Hi Robert, welcome.

To which post you’re replying to?

When you responded to my post:

I suggest to discuss script issues in the topic of the script I linked to.

I’m over 664 months old :rofl::rofl:
In Homey language, 664 months means, when no last seen value is found, it just returns 1-1-1970 as value.
(No clue who came up with that date).

Also, last_seen timestamp is not always the real last seen moment

Hi Peter,

I responded to 2re1million’s post, but thanks for your reply!
The date 1-1-1970 did ring a bell for me, that is the starting point for unix-time.
Unix time is measured in seconds after 1-1-1970. So I suppose when no last seen value is found, it returns “0”, which translates to 1-1-1970.
I think I’ll have to add that device to the ignore list then…

(Fun fact: If you change the time and date on an iPhone to 1-1-1970, it’ll brick the iPhone, because you are essentially setting the time to 0, and the OS can’t handle that")

1 Like

Ah yes, duh, the 0 in unix time!
It wouldn’t pop up in my head just then :sweat_smile:

That issue was solved 8 years ago already :stuck_out_tongue:

Hi !

The script is designed to look for the “last update” feedback from various devices and then pick the latest update to either send a notification or not.

It appears that your “Snelk. Tafel” is not generating a feedback signal from the device when being used/turned on/off. As a result, the script only relies on the feedback from “Battery alert,” which might only send signals when the battery is low or under certain conditions.

Since you use this device almost daily, you will quickly notice when it is not working. Therefore, you might want to add the device to the ignore list. :wink:

Note to self: The script works best with live feedback sensors, such as temperature sensors, etc.:stuck_out_tongue:

=== Snelk. Tafel ===
Device Class: remote
Device ID: 01b871…
Batterij alarm: null (Last updated: 3 weeks ago)