ok, i've just had a crash course on timers and this is what i've found.
Firstly despite the documentation not mentioning it, it does support the member keys `hours:, minutes:, seconds:` so you can do exactly what you are doing and it should work so we're into the wonderful world of template conversions and how objects convert in real time.
The second thing to mention is that the template test tool isn't the best in that it's an interactive line by line interpreter, it doesn't always resolve as you would expect when it appears to work here - largely depending on how it is interpreted by the real time object when doing the conversion in your code.
I've written a timer and used a number to set it just as you did and it works fine - so I am sure that your syntax is correct. What must not be correct is the contents of the number or the type or the step doesn't match the type which is upsetting the conversion, whatever it is, it is upsetting the interpreter used when the template resolves the hours: {{ }}
So I suspect this might work as it relies on a type conversion being handled outside of the template and then simply resolves a variable in the template and doesn't have to face the complexity of converting a number. (The default=0 just forces the return of 0 if the number is unavailable so that it doesn't generate an error if the number isn't available ~ startup for example).
Code: Select all
action: timer.start
metadata: {}
data:
duration:
hours: "{% set myVar=states('number.fd_timerduration')|round(2,default=0) %}{{ myVar }}"
But I also think modifying your number template to convert the result of the template with a final round(2) might also fix this - if you are specifying a step make sure it is '0.01' i.e. 2 decimal places (i'm assuming you want that for accuracy), obviously if you want it to 1 decimal place then keep the round(s) at 1.
Code: Select all
{# Read target end time in decimal hours #}
{% set EndHours = states('number.fd_windowstarttime') %}
{# Read target begin time in decimal hours #}
{% set BeginHours = states('number.fd_timenowasdh') %}
{# Calculated timer duration in decimal hours #}
{% set myDuration = (((EndHours | float ) - (BeginHours | float)) | round(2)) %}
{# Adjust if duration is negative #}
{% if myDuration < 0 %}
{% set myDuration = (myDuration + 24) %}
{% endif %}
{{ myDuration|round(2) }}