Testing Day2:
So far, I'm having fun seeing all the data I can play with. A couple thoughts, questions and suggestions....
To sync device start time with clock time: Could you add a plugin action to sync start time with clock time? Or maybe under "Edit Device Settings" an option to change the start time of the device? I'm guessing I could schedule a "Reset Counter" action to occur at midnight which would sync start time with clock time from here out?
For current and future mathematical states (average, daily high, daily low, change from previous period (hour, day, week, month), etc), I would include a description of the math in the plugin's documentation. i.e., Average Daily This Month = total count this month / day of month as a whole number. (numbers after the decimal are dropped off, no rounding, so 16.898 = 16) or whatever the formula is.
For a single day view, my preference would be to have previous 24 hours and current 24hour period displayed. It's 11am here, so on the yesterday row in the 11am column, I would have the hourMinus23 state. For 11am today I would have the hour11 state in the 11am column. Noon today "hour12" should be "0"
It looks like the hour times, "hour00, hour01, hour03, etc.," are overwritten as that hour arrives? It's 11am here, and I have yesterday's numbers in the hour12 state. So,
hour12" is roughly = hourMinus23. (+/- based on the difference of the device's start time). Personally, I would sync start time with clock time, then set all hourXX times to "0" at midnight. Another thought is either the ability to run an action prior to resetting the hourly numbers for the day or an imbedded script to dump hourly numbers for the day into a CSV file. The benefit of dumping it into a file is for additional math, graphing, looking for trends (peak times of pulses over multiple days, etc.). Like, Dave's sump pump runs more between 4-6pm every day. My network goes offline more often around 2am, etc. A script I just wrote up to dump daily numbers (by the hour) should work with your plugin how it's currently written if I run the script just before midnight. (apologies for ugly scripting, I'm not a programmer at all, but I can copy/paste the hell out of stuff).
- Code: Select all
import datetime
import os.path
from os import system
csvFilePath = "/Users/williammoore/Dropbox/Indigo/PulseMotion.csv"
csvHeaders = "Day,Date,0000,0100,0200,0300,0400,0500,0600,0700,0800,0900,1000,1100,1200,1300,1400,1500,1600,1700,1800,1900,2000,2100,2200,2300" + "\n"
THIS_SCRIPT = 'Log PulseMotion Data to CSV file'
DAY = '{date:%a}'.format(date=datetime.datetime.now())
DATE = '{date:%Y-%m-%d}'.format(date=datetime.datetime.now())
PulseDevice = indigo.devices[1005199723]
hour00 = str(PulseDevice.states["hour00"])
hour01 = str(PulseDevice.states["hour01"])
hour02 = str(PulseDevice.states["hour02"])
hour03 = str(PulseDevice.states["hour03"])
hour04 = str(PulseDevice.states["hour04"])
hour05 = str(PulseDevice.states["hour05"])
hour06 = str(PulseDevice.states["hour06"])
hour07 = str(PulseDevice.states["hour07"])
hour08 = str(PulseDevice.states["hour08"])
hour09 = str(PulseDevice.states["hour09"])
hour10 = str(PulseDevice.states["hour10"])
hour11 = str(PulseDevice.states["hour11"])
hour12 = str(PulseDevice.states["hour12"])
hour13 = str(PulseDevice.states["hour13"])
hour14 = str(PulseDevice.states["hour14"])
hour15 = str(PulseDevice.states["hour15"])
hour16 = str(PulseDevice.states["hour16"])
hour17 = str(PulseDevice.states["hour17"])
hour18 = str(PulseDevice.states["hour18"])
hour19 = str(PulseDevice.states["hour19"])
hour20 = str(PulseDevice.states["hour20"])
hour21 = str(PulseDevice.states["hour21"])
hour22 = str(PulseDevice.states["hour22"])
hour23 = str(PulseDevice.states["hour23"])
# Check and see if the file exists. If not, create and write the headers.
if not os.path.isfile(csvFilePath):
csvFile = open(csvFilePath, "a")
csvFile.write(csvHeaders)
# Write new values to the file.
csvFile = open(csvFilePath, "a")
element = DAY + "," + DATE + "," + hour00 + "," + hour01 + "," + hour02 + "," + hour03 + "," + hour04 + "," + hour05 + "," + hour06 + "," + hour07 + "," + hour08 + "," + hour09 + "," + hour10 + "," + hour11 + "," + hour12 + "," + hour13 + "," + hour14 + "," + hour15 + "," + hour16 + "," + hour17 + "," + hour18 + "," + hour19 + "," + hour20 + "," + hour21 + "," + hour22 + "," + hour23 + "\n"
csvFile.write(element)
# Close the file.
csvFile.close()
I would probably want to do a similar CSV file data dump on a periodic basis (once per week to see day-by-day pulses), (once per month to see weekly totals)