Add time with datetime (time to finish the printer job in octoprint)

Hello,

I looking for to add the time remaining to the datetime to have the date and time which my printer job will finish.

I try with this syntax, but it doesn’t work. Could you help me ?

{{ (now().timestamp() + as_timestamp(states.sensor.cr10_time_remaining) ) | timestamp_custom('%H:%M:%S', true) }}

What does this give in the developer tools template editor:

{{states.sensor.cr10_time_remaining}}

You can find the two results (with and without state) :

So there’s your problem then.

I would like to the date time which the printer job will finish. Example : job finish : 7 sept 20:12. And not in 52334 seconds.
I hope you understand me :wink:

Your time remaining sensor contains a time in seconds (when you correctly add .state). Add that to now().timestamp to get the time the job will finish in seconds then format it however you want.

Even better than using states.sensor.cr10_time_remaining.state would be to use states('sensor.cr10_time_remaining') as per the warning in the templating docs.

I agree with you, but, when I try the add these two value, I have an error and I don’t know why :


or

:thinking:

Because you are not adding what I told you to. The time remaining is already in seconds you can not (and do not need to) convert it to a timestamp. You just need to convert it from a string to a number and add it.

{{ (now().timestamp() + states('sensor.cr10_time_remaining')|int ) | timestamp_custom('%H:%M:%S', true) }}
1 Like

Thank a lot !

1 Like