Octoprint setup, UI, scripts and automations

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.”}