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.