Octoprint show clock finish time (2021.11.10+)

Background: Using sensor sensor.octoprint_estimated_finish_time, I can see in Lovelace that my print will complete (for example) “in 47 minutes”. For planning and coordination with errands, social life, etc., I like to know the clock time of print completion at a quick glance. While I could manually calculate the clock time myself (current time of day plus estimated complete time) I prefer to have the system do this for me!

I added a template sensor to dynamically take care of the math. This change requires editing your configuration.yaml and restarting HA. Note that this method works on HA 2011.11.0+ due to the fact that the octoprint integration available sensors has changed. If anyone is interested in setting up this same sensor in HA versions below 2011.11.0 let me know and I’ll also share that config.

  1. Add the template sensor to your Home Assistant configuration YAML by choosing the applicable method:
  • If you store all config data within configuration.yaml (default) add the following to your sensor section:
sensor:
  - platform: template
    octoprint_clock_finish_time:
      friendly_name: 'Octoprint Clock Finish Time'
      value_template: >
        {% if not is_state('sensor.octoprint_current_state', 'Operational') %}
          {{ as_timestamp(states('sensor.octoprint_estimated_finish_time')) | timestamp_custom('%H:%M')}}
        {% else %}
          N/A
        {% endif %}	  
      icon_template: mdi:clock-check-outline


  • If you split up your configuration and you have a line in your config similar to mine (sensor: !include sensors.yaml) then the YAML will be set up a bit differently:
  - platform: template
    sensors:
      octoprint_clock_finish_time:
        friendly_name: 'Octoprint Clock Finish Time'
        value_template: >
          {% if not is_state('sensor.octoprint_current_state', 'Operational') %}
            {{ as_timestamp(states('sensor.octoprint_estimated_finish_time')) | timestamp_custom('%H:%M')}}
          {% else %}
            N/A
          {% endif %}	  
        icon_template: mdi:clock-check-outline

Whenever the printer status is not “Operational” (which is the idle status in my case) this sensor will return the calculated completion time otherwise it will return “N/A”.


Note: In my setup I am currently using sensor.octoprint_current_state as the conditional, but you could instead use the new “Printing” binary sensor (binary_sensor.octoprint_printing) which returns a state of “on” or “off”. I’m likely to make the switch to the binary sensor after some testing.

  1. Restart Home Assistant so that your newly created sensor is available in Lovelace.

  2. On your dashboard, add the sensor to a card. If your printer is idle according to the conditional that you chose, the value should read “N/A” and while printing it will display the estimated clock time of completion.


    Clock Finish Time sensor display during idle:
    image


    Clock Finish Time sensor display during print:
    image


Regards,
Chris

4 Likes

Hello

thanks for your config, can you also post the other sensor estimated finish time please?

regards

No problem. Prior to 2011.11.0 (when sensor.octoprint_time_remaining was still available) my sensors.yaml contained these entries:

      octoprint_time_remaining_format:
        friendly_name: 'MK3s-02 Time Remaining'
        value_template: "{{ states('sensor.octoprint_time_remaining') | int | timestamp_custom('%H:%M:%S', 0) }}"
        icon_template: mdi:clock-end
     octoprint_finish_time_format:
        friendly_name: 'MK3s-02 Finish Time'
        value_template: >
          {% if not is_state('sensor.octoprint_current_state', 'Operational') %}
            {{ ((now().strftime('%s') | int) + (states.sensor.octoprint_time_remaining.state) | int) | timestamp_custom('%H:%M', false)}}
          {% else %}
            N/A
          {% endif %}	  


In HA < 2011.11.0, this is what my card looked like using sensor.octoprint_time_remaining_format and sensor.octoprint_finish_time_format:

image

1 Like