Octoprint setup, UI, scripts and automations

Apologies, for some reason I wrote the above post wrong, give me a sec, ill correct it.
Everything i say about script, should be sensor.

To create two sensor you will need to use the code twice:

sensors:
     octoprint_1_time_elapsed_format:
...
     octoprint_1_time_remaining_format:
...
     octoprint_2_time_elapsed_format:
...
     octoprint_2_time_remaining_format:
...

Inside there, you will need to substitute any instance of my names with each of your printers’
In the code states.sensor.octoprint_time_remaining.state you should change the middle part according to your printers’ names for each sensor.

Thanks!, I got it working :slight_smile:

Only the remaining time script did not work.
Instead I took the elapsed time script and used that.

If you wan to try and fix the remaining time, paste your code and entities, maybe we can spot some error and fix it.

This is what I have running as a script for 1 printer.

Running in sensors.yaml

  - platform: template
    sensors:
      octoprint_ender3_links_time_elapsed_format:
        friendly_name: 'Printing Time Elapsed'
        value_template: >-
          {% set etime = states.sensor.ender3_links_time_elapsed.state | int %}
          {% set seconds = etime % 60 %}
          {% set minutes = ((etime % 3600) / 60) | int %}
          {% set hours = ((etime % 86400) / 3600) | int %}
          {% set days = (etime / 86400) | int %}
          {%- if days > 0 -%}
            {%- if days == 1 -%}
              1 day
            {%- else -%}
              {{ days }} days
            {%- endif -%}
            {{ ', ' }}
          {%- endif -%}
          {%- if hours > 0 -%}
            {%- if hours == 1 -%}
              1 hour
            {%- else -%}
              {{ hours }} hours
            {%- endif -%}
            {{ ', ' }}
          {%- endif -%}
          {%- if minutes > 0 -%}
            {%- if minutes == 1 -%}
              1 minute
            {%- else -%}
              {{ minutes }} minutes
            {%- endif -%}
          {%- endif -%}
          
          
      octoprint_ender3_links_time_remaining_format:
        friendly_name: 'Printing Time Remaining'
        value_template: >-
          {% set etime = states.sensor.ender3_links_time_remaining.state | int %}
          {% set seconds = etime % 60 %}
          {% set minutes = ((etime % 3600) / 60) | int %}
          {% set hours = ((etime % 86400) / 3600) | int %}
          {% set days = (etime / 86400) | int %}
          {%- if days > 0 -%}
            {%- if days == 1 -%}
              1 day
            {%- else -%}
              {{ days }} days
            {%- endif -%}
            {{ ', ' }}
          {%- endif -%}
          {%- if hours > 0 -%}
            {%- if hours == 1 -%}
              1 hour
            {%- else -%}
              {{ hours }} hours
            {%- endif -%}
            {{ ', ' }}
          {%- endif -%}
          {%- if minutes > 0 -%}
            {%- if minutes == 1 -%}
              1 minute
            {%- else -%}
              {{ minutes }} minutes
            {%- endif -%}
          {%- endif -%} 

This is not working

 - platform: template
   sensors:
     octoprint_ender3_links_time_elapsed_format:
       friendly_name: 'Printing Time Elapsed'
       value_template: >-
         {% set etime = states.sensor.octoprint_ender3_links_time_elapsed.state | int %}
         {% set seconds = etime % 60 %}
         {% set minutes = ((etime % 3600) / 60) | int %}
         {% set hours = ((etime % 86400) / 3600) | int %}
         {% set days = (etime / 86400) | int %}
         {%- if days > 0 -%}
           {%- if days == 1 -%}
             1 day
           {%- else -%}
             {{ days }} days
           {%- endif -%}
           {{ ', ' }}
         {%- endif -%}
         {%- if hours > 0 -%}
           {%- if hours == 1 -%}
             1 hour
           {%- else -%}
             {{ hours }} hours
           {%- endif -%}
           {{ ', ' }}
         {%- endif -%}
         {%- if minutes > 0 -%}
           {%- if minutes == 1 -%}
             1 minute
           {%- else -%}
             {{ minutes }} minutes
           {%- endif -%}
         {%- endif -%}

     octoprint_ender3_links_time_remaining_format:
       friendly_name: 'Printing Time Remaining'
       value_template: >-
         {% set rtime = states.sensor.octoprint_ender3_links_time_remaining.state | int %}
         {% set seconds = rtime % 60 %}
         {% set minutes = ((rtime % 3600) / 60) | int %}
         {% set hours = ((rtime % 86400) / 3600) | int %}
         {% set days = (rtime / 86400) | int %}
         {%- if days > 0 -%}
           {%- if days == 1 -%}
             1 day
           {%- else -%}
             {{ days }} days
           {%- endif -%}
           {{ ', ' }}
         {%- endif -%}
         {%- if hours > 0 -%}
           {%- if hours == 1 -%}
             1 hour
           {%- else -%}
             {{ hours }} hours
           {%- endif -%}
           {{ ', ' }}
         {%- endif -%}
         {%- if minutes > 0 -%}

Ok, from what see at first glance

  • You dont need to enter this part of the code twice.
- platform: template
   sensors: 

You just enter it once and then declare the names of the different sensors you make, kind of like this:

- platform: template
   sensors: 
     sensor1:
     sensor2:
     sensor3:
  • The second thing i notice, is that the two blocks of code seems idential to me.
    You need to give them a different name, and in the states.sensor.ender3_links_time_elapsed.state part, you need to enter the name of your second printer (assuming ender3_links is the name of the first one)

Really nice setup. I’ve copied a part of your setup. Last week this lovelace card was released for octoprint and it looks really nice dangreco/threedy: Home Assistant card for 3D printer status and management. (github.com)

ah yes, saw it on reddit, it’s very nice :slight_smile:

This is my setup:

Hi, that card looks indeed very nice but I am unable to find the file threedy-card.js on Gitihub. Can you either post a link or provide me with a copy of the card?

You need to go to releases: Releases · dangreco/threedy (github.com)

Thanks a lot for the link. I found it and got it to work. It looks really nice :slight_smile:

Would you be willing to share your code? Specifically how you can get that much control over your printer through home assistant. Looks awesome!

1 Like
shell_command:
octoprint_nozzle_temperature: "curl -s http://youripoctoprint/api/printer/command -d '{\"command\":\"M109 S{{ states('input_number.nozzle_temperature') }}\"}' -H 'Content-Type: application/json' -H 'X-Api-Key: your api key'"

input_number:
  nozzle_temperature:
    unit_of_measurement: '°C'
    mode: box  
    min: 0
    max: 250
    name: Temperatura Nozzle

script:
  octoprint_nozzle_temperature:
    sequence:
      service: shell_command.octoprint_nozzle_temperature

here is an example of how I make the commands, in the octoprint api page you will find all the references you need

3 Likes

more shell commands in this thread:

1 Like

There’s a great plugin for OctoPrint which communicates with Home Assistant via MQTT.
It updates faster than the native HA integration and also exposes a switch for connecting/disconnecting which I found way easier to use than making a shell command.

3 Likes

My latest Octoprint tab:

2 Likes

Am i wrong or in the first post there are no config for the power consumption graphs and camera.octoprint?

You will find them within the next to last code section near the end of the post.

      - entities:
          - entity: sensor.d_link_plug_current_power_w
            name: Current Power
          - entity: sensor.d_link_plug_total_consumption
            name: Total Power
            color: gray
            y_axis: secondary
        hours_to_show: 24
        color_thresholds:
          - value: 50
            color: green
          - value: 100
            color: orange
          - value: 150
            color: red
        line_width: 3
        show:
          labels: true
          legend: false
          labels_secondary: true

and

      - aspect_ratio: 50%
        camera_image: camera.octoprint
        entity: camera.octoprint
        image: 'http://octopi.local/webcam/?action=snapshot'
        show_name: false
        show_state: false
        type: picture-entity

Do you use Add-ons in OctoPrint to get info into HA?
Or are you getting the other sensors into HA a different way?

I just made a filament scale and have the Filament Scale add-on working to display the info in OctoPrint, however, with the OctoPrint integration in HA I don’t get any of the add-on info.

Will the MQTT in OctoPrint send out the info for the add-ons?

I made my filament scale using ESPHome so it does not depend on Octoprint. Its better IMO as it works even when the Octoprint is switched off

1 Like