Octoprint setup, UI, scripts and automations

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

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)