[SOLVED]Timer Readout Question

Posted on
Sat Dec 07, 2013 8:06 pm
SpencerJRoberts offline
User avatar
Posts: 248
Joined: Dec 09, 2012
Location: Mountain View, CA

[SOLVED]Timer Readout Question

I was wondering if there's an easy way to display a more customized readout of a timer on a control page. In this particular case, I wanted to see the minutes left on a timer but only if it was active. Unfortunately, the timer will read 0 if it is inactive. I hacked around this by creating a variable for the time I want to display and getting the minutes left with the following python code (searching for the right text in the device description readout):

Code: Select all
import re

timerReadout = str(indigo.devices[1922573880]) # "Thermostat Override Timer (Downstairs)"
minLeftMatch = re.search(r'timeLeftMinutes : (\d*)', timerReadout)

timeLeft1 = str(minLeftMatch.group())[-1]
timeLeft2 = str(minLeftMatch.group())[-2]
timeLeft = '(' + timeLeft2 + timeLeft1 + ')'
indigo.variable.updateValue(371374721, timeLeft)


I guess my question is, is there an easier way to get different properties of the timer in python? I couldn't find any properties for timer devices in the documentation. The above works fine, but it would be great to just do this instead:

Code: Select all
minLeft = indigo.devices[1922573880].timeLeftMinutes


This brings up another feature request: The ability to trigger hiding/unhiding control page elements (another possible solution to this particular case).

As always, keep up the awesome work Matt and Jay!

Posted on
Sat Dec 07, 2013 10:01 pm
jheddings offline
User avatar
Posts: 108
Joined: Dec 01, 2013
Location: Denver, CO

Re: Timer Readout Question

Have you tried using the "Long Timer Status" variable of the timer on the control page? That seems to match the 'state' variable shown by the client. It doesn't answer the question of using the Python script to update the variable, but maybe gets you closer to your goal.

Posted on
Sat Dec 07, 2013 10:04 pm
SpencerJRoberts offline
User avatar
Posts: 248
Joined: Dec 09, 2012
Location: Mountain View, CA

Re: Timer Readout Question

jheddings wrote:
Have you tried using the "Long Timer Status" variable of the timer on the control page? That seems to match the 'state' variable shown by the client. It doesn't answer the question of using the Python script to update the variable, but maybe gets you closer to your goal.


The long timer status is way more info than I want. Mostly I want to be able to grab bits of the status as desired, maybe sometimes I just want minutes, maybe sometimes I want minutes:seconds, etc. Like I said, the solution I have now works it's just cumbersome :mrgreen:

Posted on
Sun Dec 08, 2013 11:46 am
matt (support) offline
Site Admin
User avatar
Posts: 18674
Joined: Jan 27, 2003
Location: Texas

Re: Timer Readout Question

Try this instead:

Code: Select all
minLeft = int(indigo.devices[1922573880].states["timeLeftMinutes"])

Image

Posted on
Sun Dec 08, 2013 12:51 pm
SpencerJRoberts offline
User avatar
Posts: 248
Joined: Dec 09, 2012
Location: Mountain View, CA

Re: Timer Readout Question

matt (support) wrote:
Try this instead:

Code: Select all
minLeft = int(indigo.devices[1922573880].states["timeLeftMinutes"])


Ah, so glad it was just me missing it! Thanks Matt

Posted on
Fri Jul 04, 2014 1:00 pm
CraigM offline
Posts: 517
Joined: Oct 28, 2007

Re: Timer Readout Question

matt (support) wrote:
Try this instead:

Code: Select all
minLeft = int(indigo.devices[1922573880].states["timeLeftMinutes"])


Matt,
I have been looking for something similar too. How would I get just the HR:MIN:SEC countdown readout on a CP when active, and nothing 'blank' when inactive?

Also, where/how do you put the Python code to get it to display on the CP?

Thanks

Posted on
Fri Jul 04, 2014 2:22 pm
jay (support) offline
Site Admin
User avatar
Posts: 14775
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Timer Readout Question

CraigM wrote:
I have been looking for something similar too. How would I get just the HR:MIN:SEC countdown readout on a CP when active, and nothing 'blank' when inactive?


You can create your own formatting based on the amount of time left via script if you don't like the longStatusString state display (which is "Active/Paused with D:HH:MM:SS left" if it's active or paused and "Inactive" if it's expired). For the format you're looking for, you'll need a script to format the string the way you want it.

CraigM wrote:
Also, where/how do you put the Python code to get it to display on the CP?


Once the script creates the format string, then you'll want to insert the string into a variable. The variable is what you'll want to display on the control page. The script will need to run every second while the timer is active. When it becomes inactive the script would set the variable value to nothing. You can do that in a variety of ways - I think I'd just create a trigger that fires every time the longStatusString state changes - that way it'll pick up not only the seconds decrementing, but also if the timer pauses or becomes inactive - so it's just a single trigger rather than one to watch the seconds change and a different one watching the status change,

Here's a Python script that's pretty close:

Code: Select all
timer = indigo.devices[1604521627] # Timer device ID goes here
variable = indigo.variables[1159031693] # Variable ID goes here

# set the default value that we're going to write to the variable - empty string
timerValueString = ""

# if the timer is active or paused, then create the formatted string
if timer.states["timerStatus"] != "inactive":
   from datetime import datetime, timedelta

   # create a datetime object using the seconds left in the timer
   sec = timedelta(seconds=int(timer.states["timeLeftSeconds"]))
   d = datetime(1,1,1) + sec
   
   # create the format string using standard python integer formatting
   timerValueString = "%02i:%02i:%02i" % (d.hour, d.minute, d.second)

# set the variable to the format string (which will be blank if the timer
# is inactive.
indigo.variable.updateValue(variable, timerValueString)


You'll probably want to set the trigger to not show executions in the event log since it'll add one line per execution and your log will fill up pretty quickly when the timer is running.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Jul 04, 2014 3:07 pm
CraigM offline
Posts: 517
Joined: Oct 28, 2007

Re: [SOLVED]Timer Readout Question

Perfect, works great :D

Thanks as always

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest