App: Device Tracker, Multiple Device On/Off Times, On Counts, Notifier, Battery Levels, Switches, Contacts, Temperatures, Power, etc.. With variables access

Device Time Tracker Timer, on Counter, Max/Min time/values, and more.

  • Track the time a device is On/Active and count how many times it was On/Off. Also track total Cumulative time in hours or days.
  • Options to store these On times, cumulative times and On counts into Hub variables for using in Rule Machine or Viewing on Dashboard.
  • Set up Timer/Count or variable reset schedules or do it remotely with a hub variable.
  • Set a push notification when a device on time has elapsed
  • Supported tracking times and on counts capability's:
    .....Contact Open Or Contact Closed (Doors, Windows, tilt sensors etc...Max/Min active times, active counts, total time)
    .....Switch On (Outlets, Wall switches, Relays, etc...Max/Min active times, active counts, total time)
    .....Power (can tracking above or below a threshold, active counter, Max/Min values)
    .....Temperature (tracking above or below a threshold, active counter, Max/Min values)
    .....Humidity (tracking above or below a threshold, active counter, Max/Min values)
    .....Voltage (tracking above or below a threshold, active counter, Max/Min values)
    .....Thermostat (heating or cooling modes, Max/Min active times, active counts, total time)
    .....Battery levels (Max/Min, set low level notifications, last update time, how long between changes)
    .....Motion Sensors (Max/Min active times, active counts, total time)

Switch Example

Power Example

Battery Example

Attaching variables has its own table and notifications per device

-Basic Uses Case:

  • Monitoring devices total On time or number of times On, in app table or dashboard.
  • Use the total time something was On or how many time went On to trigger a rule to do something else like send notification or activate/deactivate the device or another.
  • Track total time a Power, Temperature, or Voltage device stays above or below a threshold for monitoring or taking action in Rule Machine via attached variable.
  • Track Device battery levels, last time changed, notifications when low threshold is reached.
  • Get a notification when a device has run for a set time, on counts, etc..

Grab code here:

-How to add to your Hub

  1. Copy and paste both the parent and child "DeviceTimeActiveTracker" apps into you Developers Tools / Apps Code. To do this go to the Apps code page and hit "New App", paste and save. You must add and save both Parent and child Apps code.
  2. On "Apps" page click "Add User App" and click the parent app. It will open and you create your first child app, hit done. Create another child app if needed. Can make a table of multiple devices of same capability.

Further capabilities upon request if its not to crazy.
Ver 1.4.5: Nov09-2023, Add battery last reporting, add humidity and motion
Ver 1.4.0: Aug25-2023, Battery Level tracking and notifier
Ver 1.3.0: June09-2023, Add push notifications
Ver 1.2.2: May09-2023, Formatting, Max/Mins, Thermostats, Last On time....
Ver 1.1.7: May02-2023, Add temperature and Voltage capability. Bug fix with Power.
Ver 1.1.3: Apr27-2023, a few more options and improvements
Ver 1.1.0: Apr15-2023, Variable can be saved as integer for rule machine use, reset when on option, bug fixes.
Ver 1.0.3: Apr12-2023, added auto user configurable variable updating.
Ver 1.0.2: Apr07-2023, added power monitoring.

12 Likes

Probably doable if things don't get reset, I would need to think about how to add it.

6 Likes

That was quick! Great work.

Thanks for this.
It will be great if the table can be expanded/renamed to include the following perhaps:
Current Active Time, Previous Day Active Time, Weekly Active Time, Monthly Active Time

Also, not sure why the time is messed up for Bathroom Light1?

My Lights usage table

I've seen those crazy times on occasion. Tracking down the issue is on going, difficult since it doesn't happen all the time. Will think about how to add days, weeks, etc..

3 Likes

Watching with interest!

Cheers,

Thanks for great app!

How about tracking a device based on the Power monitoring capability? For example, many electronic devices draw a small amount of power when they are in 'standby' mode. I don't want to track that as active time. But if the power goes above a threshold (a few watts typically) then I want to track that as 'active' time until it drops back down to the 'standby' power level

OK, Power monitoring added. Track time a device is using power above a entered threshold. Copy and paste Parent and Child app code from github link above.

2 Likes

I just tried to add & run your app & get this error msg. I copied both Parent/Child code from your GitHub repo. (Raw) into Hubitat. Thoughts as to what the fix is?

I just uninstalled mine and re-installed from Github and no issue.
-From Apps page: Deleted all old "Device Time tracker" and "Device Time tracker child "apps
-From Apps Code page: Deleted all old "Device Time tracker" and "Device Time tracker child "apps
-Copy and paste both new Github "Device Time tracker" and "Device Time tracker child "apps to Apps code page
-From apps added user App, click on "Device time Tracker"
-Use app, child will automatically be created.

Thank you @kampto ,
I was looking for this functionality. I have previously created my own set of rules in RM to measure and present my Watering valves and Boiler OPEN times.
I will try and replace them with your app as it seems more orginized and easy to use.
Thanks again.

Hi @kampto ,
I am trying to use this app to keep track for how long (since last reset) a valve or a boiler were ON.
In order to present this info on a dashboard I understand I need to create a string hub variable and connect it in the app to the relevant device I am tracking.
I can see the variable gets refreshed when I click refresh on the app screen or when the device changes status (from ON to OFF for example).
As the valve or boiler might be ON for a long time before it closes and I might be interested in seeing real live data, is it possible to add a refresh command every a defined period (say allow refresh every X minutes). Iassume this can be done using RM (refresh command) but I think it will be logical to add it to the app setup.
What say you?
Edit - thinking it through I think the requirement is only needed while the device is active.

A while back I tried to figure out how to get the variable to refresh periodically or on state change without going into the app and hitting refresh. Its something I want also. But was unsuccessful. Will think about it some more.
Maybe someone with more code skills can provide some insight!

Thanks you for that.
I think @thebearmay might be able to help here.
@thebearmay, hope you will not find ut rude of me asking for your help.

For a refresh on state change you'll want to subscribe to the event for an attribute, and then trigger the update

subscribe(device, attributeName, handlerMethod)
...
def handlerMethod(evt) {
///refresh logic
}

For a regular update based on time

runIn(numSeconds, handlerMethod) 
...
def handlerMethod() {
///refresh logic
}
2 Likes

Here are your methods for status changes:

void onHandler(evt) {
	state.lights[evt.device.id].start = now()
        }

void offHandler(evt) {
	state.lights[evt.device.id].total += now() - state.lights[evt.device.id].start
	String thisVar = state.lights[evt.device.id].var
	if(thisVar) {
		int total = state.lights[evt.device.id].total / 1000
		int hours = total / 3600
		total = total % 3600
		int mins = total / 60
		int secs = total % 60
		setGlobalVar(thisVar, "$hours:${mins < 10 ? "0" : ""}$mins:${secs < 10 ? "0" : ""}$secs")
	}
}

The variable is only updated once the offHandler method is called. That would be when the light is turned off, contact closed, etc.. You'll need a refresh method like @thebearmay hinted to, that will refresh the "on" time and update the variable periodically.

You actually already have the logic in the button handler:

    else if (btn == "refresh") state.lights.each {k, v ->
		def dev = lights.find{"$it.id" == k}
        
        if (capabilitySelect == "1" && dev.currentSwitch == "on") {
        	state.lights[k].total += now() - state.lights[k].start
			state.lights[k].start = now()
		    }
        else if (capabilitySelect == "2" && dev.currentContact == "open") {
        	state.lights[k].total += now() - state.lights[k].start
			state.lights[k].start = now()
		    }
       else if (capabilitySelect == "3" && dev.currentContact == "closed") {
        	state.lights[k].total += now() - state.lights[k].start
			state.lights[k].start = now()
		    }
       else if (capabilitySelect == "4" && dev.currentPower >= powerThreshold) {
        	state.lights[k].total += now() - state.lights[k].start
			state.lights[k].start = now()
		    } 
       endif
       }
1 Like

I will mess around with it tonight and see if it can get done.

2 Likes

Who needs ChatGPT when you have this great community help? :clap::clap::clap:

1 Like

Variable refresh is added now, figured out where I went wrong previous try. Copy paste the updated child app code. You might have to delete existing child apps and re-make for it to work. You can see the refresh in the logs.

2 Likes