Advanced templating - Need help to calculate what time job are finished based on start time and

Hi all,

I’ve integrated OctoPrint to HA, using the MQTT route.
I have the sensor sensor.octoprint_print_estimated_time which tell me the estimated total print time. I also have the binary sensor binary_sensor.octoprint_printing.

I would like to get the time of day the job are finished based on the timestamp from the moment the binary_sensor goes from off to on and use the sensor for estimated print time, in 24 hr format.

Can that be done? It is far outside my template skills…
If somebody got a solution and a recipe for me - I will be very happy!

what are the units

Hi @petro

You were in the back of my mind …hehe :stuck_out_tongue_winking_eye:

could it ever take days?
if not

template:
- sensor:
  - unique_id: octoprint_end_time
    name: Octoprint End Time
    device_class: timestamp
    state: >
      {% set t = states('sensor.octoprint_print_estimated_time') %}
      {% if t not in ['unknown', 'unavailable'] %}
        {% set h, m, s = t.split(":") | map('int', 0) %}
        {{ now() + timedelta(hours=h, minutes=m, seconds=s) }}
      {% else %}
        none
      {% endif %}

@petro you’re a god damn hero! Do you eat, sleep and drink templates? :rofl: :stuck_out_tongue_winking_eye:

First, I realized that we needed to use the remaining time sensor, otherwise it would keep extending the time all the time. Agree? Then it became like this:

template:
  - sensor:
    - name: Octoprint Ferdig
      unique_id: octoprint_print_time_left
      device_class: timestamp
      state: >
        {% set t = states('sensor.octoprint_print_time_left') %}
        {% if t not in ['unknown', 'unavailable'] %}
          {% set h, m, s = t.split(":") | map('int', 0) %}
          {{ now() + timedelta(hours=h, minutes=m, seconds=s) }}
        {% else %}
          none
        {% endif %}

Though, not exactly as I wanted it. I want it to show the time of day (as an example, like at 22:04:34).

This is now the sensor in DevTools:

This is how it shows on Dashboard: