and this is the error that refound the control of configuration
Invalid config for [timer]: offset 00:{{ states.input_number.stairs_light.state | int }} should be format 'HH:MM' or 'HH:MM:SS' for dictionary value @ data['timer']['stairs_light_timer']['duration']. Got '00:{{ states.input_number.stairs_light.state | int }}'
Yeah i’m not sure that’s going to work indeed. And from the docs it doesn’t look like you can set a timer’s value programmatically…
The other way round would be to create an automation that runs every sec (potentially a resource killer) which has a condition to check whether the time since you initiated a virtual timer (input_boolean) is more than the tdureation set by your slider.
Maybe even have an automation that activates that previous automation when you turn the input_boolean on and one that turns the automation off when the input_boolean is turned off?
As mentioned above, you can’t use a template to set the initial timer duration. However, you can use a template to set the timer’s duration when you start it using the timer.start service. E.g.:
Also note that the entity_id of your “slider” is input_number.slider, not input_number.stairs_light. The value of the name: parameter is the entity’s friendly_name, not its object_id (where the object_id is the part of the entity_id after the dot.)
What happens if you start a timer based on that code then while the timer is running you then change the time input_number value?
I assume it captures the timer duration value at the instant the timer was started and keeps it until the timer times out based on the original value? Then the next time the timer start is called it then loads new input_number duration value?
it would yes. If you wanted to adjust the timer while it’s running you’d need to cancel/pause the timer, then restart it with the new value, so probably another automation.
You could even make it one step “more complicated” by restarting the timer with the actual time left to run based on new timer value and what has already elapsed. Let us know if you want assistance with this.
I was just wondering because I have a random number generator and I was going to use it to set a timer for presence simulation.
Based on this thread it inspired me to try to work out the template to convert the number generated to a string for use in the timer value.
The problem was that the random number generator generates integers and if the integer is less than 10 it is only a single digit. But the time requires the format ‘00:00:00’. So i had to work out a way to stick the extra digit to the beginning if it was less than 10. Here is what I came up with:
for a potential “cleaner” way to do it, you could generate a random number of seconds then convert that to a time format? Not sure it’s cleaner, but may be simpler?
This will convert 120 (seconds) into 02:00 as a string {{120| timestamp_custom('%M:%S')}}
Replace 120 with your random entity
@pnbruckner I know you’re really good with such templates. Do you know why when adding hours to the above I get 1h 2min instead of 0h 2min? (in case @finity wants hours too)
Replace MIN_SEC and MAX_SEC with the minimum and maximum time you want in seconds. E.g., if you want from 5 sec to 10 min, use range(5,10*60+1).... The reason for the +1 is because the highest number range outputs is one less than the second argument.
the yaml link is a good one,but was more looking at where you find out how to convert formats, like where did you find the tip for %X is a shortcut for `%H:%M:%S’.
Thanks
Oh. Well, I have to admit I saw someone else use %X. But you’ll find it if you go to the Templates page in the frontend and click on Home Assistant template extensions. If you scroll down to where it defines the timestamp_custom filter, there’s a link to Python format options. Towards the end of the list is %X.
I should probably mention at this point, it says %X is “Locale’s appropriate time representation.” I suppose there may be locales where %X isn’t the same as %H:%M:%S, so your mileage may vary.