The current value of this sensor is 07:33 Restzeit, and the sensor will update accordingly (meaning it works as expected).
Question
How can I add this to something like {{ now().hour}}:{{ now().minute }} to display notin how much time the print will be done, butwhen? I believe I’d know the solution if this was decimal math, but this is hours and minutes, so I have no clue how to add this.
Can you please help me out? This should currently display something like 22:33 (it’s about 3pm and about 7h33m are left).
No, go back to finity’s EPIC time manipulation thread.
You want timestamp of now() (which will return the current second since 1970/01/01 00:00:00) then add to it the number of seconds in the future you need
Thank you. I tried {{ as_timestamp(states.sensor.prusa_mk3s_time_remaining.state) + now().timestamp() | timestamp_format("%H:%M") }} and {{ as_timestamp(states.sensor.prusa_mk3s_time_remaining.state) + as_timestamp(states.sensor.time.state) | timestamp_format("%H:%M") }}, but both return Error rendering template: TemplateAssertionError: no filter named 'timestamp_format'.
When I directly copy and paste your solution, I get Error rendering template: TemplateSyntaxError: unexpected char '"' at 102, but I assume this is because of a missing " after "%H:%M…?
Thank you. This {{ as_timestamp(states.sensor.prusa_mk3s_time_remaining.state) + now().timestamp() | timestamp_custom("%H:%M") }} will return something like (my output is in German) unknown error while rendering template (Unbekannter Fehler beim Rendern der Vorlage).
@Mutt I got this {{ states('sensor.prusa_mk3s_time_remaining') | float + now().timestamp() }} working; however, no matter what I pipe it to (for example | timestamp_custom('%R', false') or | timestamp_custom("%H:%M) , I will not get any valid output. Do you know what I need to pipe it to?
sensor.prusa_mk3s_time_remaining is currently 23690. I have this {{ states('sensor.prusa_mk3s_time_remaining') | int + now().timestamp()}}, which will output 1589747254.681977.
No matter if I pipe it to timestamp_custom("%H:%M", false) or "%R", false, or (without actually knowing what it does, took it from the other thread) | timestamp_custom('%I:%M %p', false) , I get a render error.
{{ 1589747254.681977 | float | timestamp_custom("%R", false) }}does work (will display 20:27). This is equal to the output from before, but if I pipe that to the timestamp_custom command, it will throw an error.
I’m sure someone else knows but I’m guessing:
I believe this time will re-evaluate every second or something.
Maybe if you make this a input.datetime and have an automation set it every 10 minutes or so will be a little lighter on the system.
But that is purely a guess. But since it uses now() it probably evaluates quite often.
Thank you. I will try implementing this tomorrow. If I understand correctly, octoprint will not submit the remaining seconds every second, but it’s still a good idea to query this only so often instead of all the time
I actually don’t think that will matter.
Since it uses now() the finish time will update every second anyways.
Lets assume the finish time is 11:20:55 then the next second HA will evaluate with a new now() time and output 11:20:56 and so on.
Then after some time the printer will give it a new time which will (if everything is perfect) roll the time back to 11:20:55 again.
Assumix x is the timestamp
If you use x//60*60 it will truncate it to the nearest (round down) minute
Then you could just set the update to 1/minute by specifying entity id: sensor.time
(though I think I’d add 30 secs before the truncation for a correct round)
now() (except in some VERY rare circumstances) will NOT update a template.