Octoprint setup, UI, scripts and automations

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

Can you share how you did the Preheat PLA/PETG buttons please? :slight_smile:


Edit:
Nevermind, I found them in the other thread, shell commands :slight_smile:

octoprint_connect: "curl -s http://x.x.x.x/api/connection -d '{\"command\":\"connect\"}' -H 'Content-Type: application/json' -H 'X-Api-Key: XXXX'"

octoprint_pwr_off: "curl -s http://x.x.x.x/api/printer/command -d '{\"command\":\"M81\"}' -H 'Content-Type: application/json' -H 'X-Api-Key: XXXX'"
octoprint_pwr_on: "curl -s http://x.x.x.x/api/printer/command -d '{\"command\":\"M80\"}' -H 'Content-Type: application/json' -H 'X-Api-Key: XXXX'"

octoprint_cancel: "curl -s http://x.x.x.x/api/job -d '{\"command\":\"cancel\"}' -H 'Content-Type: application/json' -H 'X-Api-Key: XXXX'"

octoprint_pause_resume: "curl -s http://x.x.x.x/api/job -d '{\"command\":\"pause\",\"action\":{\"toggle\"}}' -H 'Content-Type: application/json' -H 'X-Api-Key: XXXX'"
octoprint_pause: "curl -s http://x.x.x.x/api/printer/command -d '{\"command\":\"M601\"}' -H 'Content-Type: application/json' -H 'X-Api-Key: XXXX'"
octoprint_resume: "curl -s http://x.x.x.x/api/printer/command -d '{\"command\":\"M602\"}' -H 'Content-Type: application/json' -H 'X-Api-Key: XXXX'"

octoprint_change_filament: "curl -s http://x.x.x.x/api/printer/command -d '{\"command\":\"M600\"}' -H 'Content-Type: application/json' -H 'X-Api-Key: XXXX'"

octoprint_autohome: "curl -s http://x.x.x.x/api/printer/command -d '{\"command\":\"G28 W\"}' -H 'Content-Type: application/json' -H 'X-Api-Key: XXXX'"

octoprint_preheat_bed_pla: "curl -s http://x.x.x.x/api/printer/bed -d '{\"command\":\"target\",\"target\":70}' -H 'Content-Type: application/json' -H 'X-Api-Key: XXXX'"
octoprint_preheat_tool_pla: "curl -s http://x.x.x.x/api/printer/tool -d '{\"command\":\"target\",\"targets\":{\"tool0\":210}}' -H 'Content-Type: application/json' -H 'X-Api-Key: XXXX'"

octoprint_preheat_bed_petg: "curl -s http://x.x.x.x/api/printer/bed -d '{\"command\":\"target\",\"target\":80}' -H 'Content-Type: application/json' -H 'X-Api-Key: XXXX'"
octoprint_preheat_tool_petg: "curl -s http://x.x.x.x/api/printer/tool -d '{\"command\":\"target\",\"targets\":{\"tool0\":240}}' -H 'Content-Type: application/json' -H 'X-Api-Key: XXXX'"

octoprint_preheat_bed_off: "curl -s http://x.x.x.x/api/printer/bed -d '{\"command\":\"target\",\"target\":0}' -H 'Content-Type: application/json' -H 'X-Api-Key: XXXX'"
octoprint_preheat_tool_off: "curl -s http://x.x.x.x/api/printer/tool -d '{\"command\":\"target\",\"targets\":{\"tool0\":0}}' -H 'Content-Type: application/json' -H 'X-Api-Key: XXXX'"

octoprint_speed_200pc: "curl -s http://x.x.x.x/api/printer/command -d '{\"command\":\"M220 S200\"}' -H 'Content-Type: application/json' -H 'X-Api-Key: XXXX'"
octoprint_speed_100pc: "curl -s http://x.x.x.x/api/printer/command -d '{\"command\":\"M220 S100\"}' -H 'Content-Type: application/json' -H 'X-Api-Key: XXXX'"
octoprint_speed_80pc: "curl -s http://x.x.x.x/api/printer/command -d '{\"command\":\"M220 S80\"}' -H 'Content-Type: application/json' -H 'X-Api-Key: XXXX'"

Yep, shell commands in config file. Then create scripts to run these and then run scripts with buttons.

Got it working, thanks :slight_smile:

Nice work! Can you share your sensor/config from the “File size” and “Filament length” ?

- platform: rest
  resource: 'http://x.x.x.x/api/job'
  name: "STL File Size API"
  value_template: '{{ value_json.job.file.size | float / 1000000 }}'
  headers:
    X-Api-Key: xxx
  unit_of_measurement: 'MB' 
    
- platform: rest
  resource: 'http://x.x.x.x/api/job'
  name: "STL Filament Length API"
  value_template: '{{ value_json.job.filament.tool0.length | float / 1000 }}'
  headers:
    X-Api-Key: xxx
  unit_of_measurement: 'm' 

- platform: template
  sensors:
    stl_filament_length:
      friendly_name: "STL Filament Length"
      unit_of_measurement: 'm'
      value_template: "{{ states('sensor.stl_filament_length_api') | round(1) }}"
      
- platform: template
  sensors:
    stl_file_size:
      friendly_name: "STL File Size"
      unit_of_measurement: 'MB'
      value_template: "{{ states('sensor.stl_file_size_api') | round(1) }}"
1 Like

Hey I’ve been trying to work out the best way to do this. I have an automation that triggers when a print has finished, but since the big OctoPrint integration update, the start and end print time sensors immediately become unavailable at the end of the print:


I used to just invoke the start time sensor to get a total print time length in the automation, so as I could get the total print time sent to me in the notification I’m sent, but now that sensor has already gone offline by the time the automation is running.
Anyone worked out the simplest way of doing this with the new sensors?

I have noticed that the completion sensor remains at 100% after print is finished.

I check the progress percentage (>99.9) and state (finishing)
Seems to work fine.
Have 1 automation for start, 25/50/75% and completion notifications.
If someone wants, I can post the YAML (on my phone now)

Just sharing these sensors I use with the DisplayLayerProgress plugin:

- platform: rest
  scan_interval: 10
  name: octoprint_layer_progress
  resource: https://YOUR_IP/plugin/DisplayLayerProgress/values
  verify_ssl: false
  headers:
    User-Agent: Home Assistant
    X-Api-Key: YOUR_APIKEY
  json_attributes:
    - currentFilename
    - layer
  value_template: "{{ value_json.layer['current'] }}"
- platform: template
  sensors:
    octoprint_filename_current:
      value_template: "{{ state_attr('sensor.octoprint_layer_progress', 'currentFilename') }}"
    octoprint_layer_current:
      value_template: "{{ state_attr('sensor.octoprint_layer_progress', 'layer')['current'] | int }}"
    octoprint_layer_total:
      value_template: "{{ state_attr('sensor.octoprint_layer_progress', 'layer')['total'] | int }}"
2 Likes

If you have the YAML for this I’m interressing

thanks

Here you go. An automation for progress notifications.

alias: Octoprint progress update notification - vyper printer
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.octoprint_print_progress
    above: '24.9'
  - platform: numeric_state
    entity_id: sensor.octoprint_print_progress
    above: '49.9'
  - platform: numeric_state
    entity_id: sensor.octoprint_print_progress
    above: '74.9'
  - platform: numeric_state
    entity_id: sensor.octoprint_print_progress
    above: '99.9'
  - platform: state
    entity_id: sensor.octoprint_print_status
    to: Printing
    for:
      hours: 0
      minutes: 0
      seconds: 15
condition: []
action:
  - choose:
      - conditions:
          - condition: numeric_state
            entity_id: sensor.octoprint_print_progress
            above: '99.9'
          - condition: state
            entity_id: sensor.octoprint_print_status
            state: Finishing
        sequence:
          - device_id: 555867a415f511eb9d5495568acb0c74
            domain: mobile_app
            type: notify
            title: Vyper - Print has completed
            message: >-
              Print '{{ states('sensor.octoprint_print_file') }}' has finished
              after {{ states('sensor.octoprint_print_time') }}. Go check it
              out!
      - conditions:
          - condition: numeric_state
            entity_id: sensor.octoprint_print_progress
            below: '1'
          - condition: state
            entity_id: sensor.octoprint_print_status
            state: Printing
        sequence:
          - device_id: 555867a415f511eb9d5495568acb0c74
            domain: mobile_app
            type: notify
            title: Vyper - Print has started
            message: >-
              Print '{{ states('sensor.octoprint_print_file') }}' has started,
              ETA is {{ states('sensor.octoprint_print_estimated_time') }}.
    default:
      - condition: state
        entity_id: sensor.octoprint_print_status
        state: Printing
      - device_id: 555867a415f511eb9d5495568acb0c74
        domain: mobile_app
        type: notify
        title: >-
          Vyper - Print at {{ states('sensor.octoprint_print_progress')  | int
          }}%
        message: >-
          Still {{ states('sensor.octoprint_print_time_left') }} left to print
          '{{ states('sensor.octoprint_print_file') }}'.
mode: single

3 Likes

Fantastic - thanks for sharing. I’m new to Octoprint and a Home Assistant newbie, so this really helps me get started

Can anybody help me where to begin?
I want similar like this


Do i need add something in config.yaml or just creat lovelace card? I have just installed octoprint plugin and what to do next i dont have any clue.

Very useful. Thanks for documenting it!

I tried the remote rest shutdown command but got this error

{“error”:“The method is not allowed for the requested URL.”}