I have a 3D printer that unfortunately isn’t OctoPrint compatible. I currently have some sensors available exposed via an api to use, but I am missing a ‘estimated time remaining’ sensor. So I would like to make one.
I have ‘sensor.printer_percentage_completed’ and ‘sensor.printer_minutes_elapsed_from_start_time’. Would it be possible to calculate estimated minutes remaining using these 2 values? If so could anybody help with a template.
I understand that this would be 100% accurate but a rough estimated mins remaining would be great.
{% set printer_percentage_completed = 25 %}
{% set printer_minutes_elapsed_from_start_time = 1 %}
{% if printer_percentage_completed >0 %}
Total time: {{ printer_minutes_elapsed_from_start_time / (printer_percentage_completed/100) | float }}
Remaining time: {{ printer_minutes_elapsed_from_start_time * (100/printer_percentage_completed - 1) | float }}
{% else %}
Total time: {{ -1 }}
{% endif %}
I’ve set it to -1 if percentage is zero, just to avoid division by zero errors. You should prefix printer_precentage_completed and printer_minutes_elapsed_from_start_time by sensor, it’s just so I could test it.
What you probably want to do is create an Input Datetime - Home Assistant (home-assistant.io) and use an automation to set the value of this. For this you will also have to convert the minutes to format H:M:S.
Edit: Sorry, you wanted remaining time. I’ve modified the reply to account for this.