Count how long lights are on?


#1

1) Give a description of the problem
Don’t have any idea how

2) What is the expected behavior?
I want a piston that will keep track of how long a light spends at a certain %

For example, my porch light turns on at 30% at certain times until you open the doors then it goes to 80% for a couple minutes.

I want the piston to record like… 12 hours at 30%, 12 minutes at 80%

Or something like that. I’ll figure out how to deal with the output and such I just want to be able to count.

Am i crazy?


#2

I’d probably look into sending event to IFTTT and make a recipe to log to google doc each and every variation in intensity associated with date and time. Then it’d be standard excel fun and graphs.

Make sure you link webcore and IFTTT in settings and IIRC; you’ll want to use IFTTT webhooks for that.

I’ll look tomorrow for more details as I’m about to go to sleep. Keep me posted!


#3

Can you use the $now variable to log the events in which you’re interested to variables and then calculate the difference between the variables. Maybe use an if level changes to 30% statement to write {$now} to a variable and then an if level changes to 80% to write {$now} to another variable.

I’m doing something similar to write the time my furnace kicks into heating mode and then write the time it changes to idle. I was writing these values to a fuel stream but now I use the Simple Event Logger SmartApp to write to a Google spreadsheet. I then use a macro to calculate the amount of time the furnace was in heating mode and the amount of time it was idle. I use this data to chart the two events so I have an idea as to how often and how long the furnace is running so I have an idea as to how much natural gas I’m using.


#4

So I know how to get it to mark the events on any level change and on and off. the trick is how do I create time based on that. Maybe I can start with just how long the light was on unrelated to level… Maybe when it goes off, I can log when the last time it was off was, and that should give me the time it was on.

Right?


#5

This is a great idea if you want to keep track of the value over time. Ady has an excellent piston for tracking power usage over the course of the day, week, and month that uses an approach contained entirely within webCoRE.

The basic idea is to use two triggers - when the brightness changes to your target you set a local variable dimStartTime = $time. Then when the brightness leaves that target value or range you set a local variable that keeps track of the total over time dimDuration = dimDuration + $now - dimStartTime.

You can then set up a timer to daily, weekly, or whatever makes sense reset that dimDuration back to zero. Tracking over the course of a week or month takes quite a bit more effort, but the basic running-sum-then-clear approach is pretty simple.

The dimDuration value is going to be the number of milliseconds that the bulb was at that brightness. You can display it in a format like “12:04:02” or “12 hours 4 minutes and 2 seconds” with the formatDuration function


#6

awesome! Thanks!!!


#7

Ho lee fuk, as they would say on KTVU… That piston is a piece of art, reminding me again how mortal I am lol.

If this board had signature mine would be “Disclaimer: whatever solution I suggested, although it might work, someone did immensely better” :blush:


#8

I already have it working! Albeit only for the lights on at the moment. I have to figure out how I will average out light level and such…