"Time on" tracker

Does anyone know of an app which can provide "time on" data for a switch please?

I'd really like to track time on per day, month etc, and be able to read the figures into webcore.

Well...there's the one that Bruce wrote. The code is here and the thread is:

@kewashi did some tweaking to add some features and then I added a little to his.

So...take your pick.

1 Like

Cheers, but that doesn't seem to give the daily/monthly figures.

@nh.schottfam

I robbed something similar from the webcore forum a few weeks ago, thank you.

If this could be adapted a little to also include a live counter as a seperate variable, this would be ace.

The issue with this (not that I mentioned in the first post, sorry), is that there's no way of viewing the 'current' time on - if a switch is on for hours, it doesn't update until it's switched off, or it ticks over midnight.

Also, the fact that this relies on the Piston definitely being able to run at midnight is potentially an issue.

But I think I can solve that part by making use of an 'expiry' variable. So if this say, doesn't run at midnight because the hub is mid-reboot, it should catch up with itself on the next cycle.

Here's my messy solution to my own Piston :

Does this make sense?

As I said, I think I can adapt the expiry section, but I failed to come up with a live counter (I tried some.komd of every-minute loop and failed miserably).

Best I can think of for historical stuff would be to send device data to something like influxdb and then extract the data from there, where that kind of analysis could be easier to achieve. Otherwise you will (I expect) be forever worried about making sure schedules run to manage variables and having to handle key points in time, is the hub running, etc.

To be honest, I would have agreed if it weren't for the fact that the 'expiry' method works ace.

I'm not in the position in terms of time, cash, and energy to learn/add more points of failure.

I'm positive this is achievable with webcore. Perhaps an app would be far cleaner, employing the same logic, but....

....can't program, I'm useless at it.

you can use a fuel stream for this if you wanted.

Not directly, but you could leverage the variable function for that. No matter what avenue you take, the end result will have to count time in the "on" state and write that to a variable. Then it'll do something with it at the end of each day.

You can either figure this all out yourself, or, use the app, then write an RM rule to grab the variable value at the end of each day and compare it to the last value to get the difference. So, let's call the variable 'useTimeSwitch1' that you set in the table. You would then create another variable called dayStartSwitch1, dayUseSwitch1, weekUseSwitch1, and monthUseSwitch1.

Trigger: 
Time is 00:00:01 a.m.

Action:
Set "dayUseSwitch1" to ("useTimeSwitch1" - "dayStartSwitch1")
Set "weekUseSwitch1" to ("weekUseSwitch1" + "dayUseSwitch1")
Set "monthUseSwitch1" to ("monthUseSwitch1" + "dayUseSwitch1")
Set "dayStartSwitch1" to "useTimeSwitch1"

Then you'd need a rule to reset the weekly/monthly variables at the right time.

Trigger:
Cron schedule: 05 0 0 ? * SUN (00:00:05 am on Sunday)

Action:
Set "weekUseSwitch1" to 0
Trigger:
Cron schedule: 03 0 0 1 * * (00:00:03 am on the first of the month)

Actions:
Set "monthUseSwitch1" to 0

Something along those lines.

Cheers lads, I'll look into the suggestions.

Many thanks for the input.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.