Octoprint RestFull switch

I see.
I thought that you found someway to control the Relays connected to octoprint,thank you

Hello Antonio.
Y try the command and receive a “bad request”

pi@octopi:~ $ curl -s http://192.168.1.47/api/connection -d '{\"command\":\"connect\"}' -H 'Content-Type: application/json' -H 'X-Api-Key: FE8DF4627D134DC9A8712773AC817A5D'
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>400 Bad Request</title>
<h1>Bad Request</h1>
<p>The browser (or proxy) sent a request that this server could not understand.</p>

I use  OctoPrint 1.3.11 running on OctoPi 0.16.0

can you help me?   thanks.

Hello!

This is my current working shell command:

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

I am not sure if you are trying to execute it using SSH inside your OctoPrint server or from another system.

This shell script works just fine by calling it from many scripts inside HA.

Here you might find some useful information, she made that video yesterday: https://www.youtube.com/watch?v=r2f3F-KmwK0

Thanks.

thanks Antonio. I run in SSh connection .

Where do you paste this code in HA ? I understand you

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

Hello Ariel.

This is a shell command: https://www.home-assistant.io/components/shell_command/

You can create them an call as service on any script/automation you like.

thank by your Help ! now work fine , I send commands “M80” and “M81” to power ON my PSU ATX:

shell_command:
  octoprint_connect: "curl -s http://192.168.1.47/api/connection -d '{\"command\":\"connect\"}' -H 'Content-Type: application/json' -H 'X-Api-Key: FE8Dxxxxx4DC9A8712773AC817A5D'"
  octoprint_pwr_off: "curl -s http://192.168.1.47/api/printer/command -d '{\"command\":\"M81\"}' -H 'Content-Type: application/json' -H 'X-Api-Key: FE8Dxxxxx4DC9A8712773AC817A5D'"
  octoprint_pwr_on: "curl -s http://192.168.1.47/api/printer/command -d '{\"command\":\"M80\"}' -H 'Content-Type: application/json' -H 'X-Api-Key: FE8Dxxxxx4DC9A8712773AC817A5D'"

I need now shutdown when the printer are inactive 10 minutes , but in automation only work whit state change, and if not finish a print , don’t detect a state change and the automation not execute.
this is the automation:

- id: '1566304481281'
  alias: Apagar impresora inactiva
  trigger:
  - entity_id: binary_sensor.arielus_a1_printing
    for: 00:10:00
    platform: state
    to: 'off'
  condition: []
  action:
  - service: shell_command.octoprint_pwr_off

Any idea ?

Obrigado !!
un saludo

Hello! I am glad I could help.

I did not get that: you need your printer to be turned off after 10 minutes of inactivity after a print is done or anytime it is not printing?

Sorry for resurrecting this old thread… @Schneider can you get pausing and resuming print working this way? It’d be great to have some of these functions integrated to the octoprint component… Wish I had the skills!

Hello!

Sorry for the delay.

You can always send M commands to the printer by using this shell command:

  octoprint_disable_motors: "curl -s http://192.168.20.90/api/printer/command -d '{\"command\":\"M84\"}' -H 'Content-Type: application/json' -H 'X-Api-Key: 2BA5F32FDB884F528964F137A56A44FD'"

Just replace the M84 command on the example above with the pause/resume M command. You can search online for all commands available.

Good luck!

Thanks @Schneider I shall have a look and post back!

In your experience, is it better to run M commands or to use Octoprint commands?

octoprint_preheat_bed: "curl -s http://192.168.1.69/api/printer/bed -d '{\"command\":\"target\",\"target\":60}' -H 'Content-Type: application/json' -H 'X-Api-Key: 2BF5F70FDB884F528464F137A26544FD'"

Vs

octoprint_disable_motors: "curl -s http://192.168.20.90/api/printer/command -d '{\"command\":\"M84\"}' -H 'Content-Type: application/json' -H 'X-Api-Key: 2BA5F32FDB884F528964F137A56A44FD'"

Also, have you tried G commands as well?

Here are some commands (untested) that are relevant to my use case:

shell_command:
  octoprint_connect: "curl -s http://192.168.1.47/api/connection -d '{\"command\":\"connect\"}' -H 'Content-Type: application/json' -H 'X-Api-Key: FE8Dxxxxx4DC9A8712773AC817A5D'"
  octoprint_pwr_off: "curl -s http://192.168.1.47/api/printer/command -d '{\"command\":\"M81\"}' -H 'Content-Type: application/json' -H 'X-Api-Key: FE8Dxxxxx4DC9A8712773AC817A5D'"
  octoprint_pwr_on: "curl -s http://192.168.1.47/api/printer/command -d '{\"command\":\"M80\"}' -H 'Content-Type: application/json' -H 'X-Api-Key: FE8Dxxxxx4DC9A8712773AC817A5D'"
  octoprint_cancel: "curl -s http://192.168.1.47/api/job -d '{\"command\":\"cancel\"}' -H 'Content-Type: application/json' -H 'X-Api-Key: FE8Dxxxxx4DC9A8712773AC817A5D'"
  octoprint_pause_resume: "curl -s http://192.168.1.47/api/job -d '{\"command\":\"pause\",\"action\":{\"toggle\"}}' -H 'Content-Type: application/json' -H 'X-Api-Key: FE8Dxxxxx4DC9A8712773AC817A5D'"
  octoprint_change_filament: "curl -s http://192.168.1.47/api/printer/command -d '{\"command\":\"M600\"}' -H 'Content-Type: application/json' -H 'X-Api-Key: FE8Dxxxxx4DC9A8712773AC817A5D'"
  octoprint_preheat_bed: "curl -s http://192.168.1.47/api/printer/bed -d '{\"command\":\"target\",\"target\":60}' -H 'Content-Type: application/json' -H 'X-Api-Key: FE8Dxxxxx4DC9A8712773AC817A5D'"
  octoprint_preheat_tool: "curl -s http://192.168.1.47/api/printer/tool -d '{\"command\":\"target\",\"targets\":{\"tool0\":210}}' -H 'Content-Type: application/json' -H 'X-Api-Key: FE8Dxxxxx4DC9A8712773AC817A5D'"

These would help with printing while away from home and remotely monitoring the jobs.
Does anyone think any other command would be relevant?

1 Like

Hello @monkey-house!

Nice work, this will be useful for many people here.

I think all Octoprint commands are sending M commands on the background, not sure.

No, I have never used G commands, will learn what they are.

Thanks!

Hey @Schneider
Thanks. Am testing more commands…
Before realising that the on off commands do not work with my printer (Prusa), I played around with the command line switch. This could be a way to get a switch printer on and off without using a wifi relay…

1 Like

Here are the commands that are tested and working on my printer (Prusa):

shell_command:
  prusa2_change_filament: "curl -s http://x.x.x.x/api/printer/command -d '{\"command\":\"M600\"}' -H 'Content-Type: application/json' -H 'X-Api-Key: XXX'"
  prusa2_autohome: "curl -s http://x.x.x.x/api/printer/command -d '{\"command\":\"G28 W\"}' -H 'Content-Type: application/json' -H 'X-Api-Key: XXX'"
  prusa2_pause: "curl -s http://x.x.x.x/api/printer/command -d '{\"command\":\"M601\"}' -H 'Content-Type: application/json' -H 'X-Api-Key: XXX'"
  prusa2_resume: "curl -s http://x.x.x.x/api/printer/command -d '{\"command\":\"M602\"}' -H 'Content-Type: application/json' -H 'X-Api-Key: XXX'"
  prusa2_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: XXX'"
  prusa2_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: XXX'"
  prusa2_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: XXX'"
  prusa2_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: XXX'"
  prusa2_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: XXX'"
  prusa2_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: XXX'"
  prusa2_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: XXX'"
  prusa2_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: XXX'"
  prusa2_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: XXX'"

And the ones I could not get to work:

  # prusa2_pause_resume: "curl -s http://x.x.x.x/api/job -d '{\"command\":\"pause\"}' -H 'Content-Type: application/json' -H 'X-Api-Key: XXX'"
  # prusa2_cancel: "curl -s http://x.x.x.x/api/job -d '{\"command\":\"cancel\"}' -H 'Content-Type: application/json' -H 'X-Api-Key: XXX'"
  # prusa2_pause: "curl -s http://x.x.x.x/api/printer/command -d '{\"command\":{\"G4 S60\"}}' -H 'Content-Type: application/json' -H 'X-Api-Key: XXX'"
  # prusa2_fan_full: "curl -s http://x.x.x.x/api/printer/command -d '{\"command\":{\"M106\"}}' -H 'Content-Type: application/json' -H 'X-Api-Key: XXX'"
  # prusa2_fan_off: "curl -s http://x.x.x.x/api/printer/command -d '{\"command\":{\"M107\"}}' -H 'Content-Type: application/json' -H 'X-Api-Key: XXX'"
  # octoprint_pwr_off: "curl -s http://192.168.1.47/api/printer/command -d '{\"command\":\"M81\"}' -H 'Content-Type: application/json' -H 'X-Api-Key: FE8Dxxxxx4DC9A8712773AC817A5D'"
  # octoprint_pwr_on: "curl -s http://192.168.1.47/api/printer/command -d '{\"command\":\"M80\"}' -H 'Content-Type: application/json' -H 'X-Api-Key: FE8Dxxxxx4DC9A8712773AC817A5D'"

Hope the first batch helps some, but it’d be great if others have a look at the ones that don’t work. All but the last two should work on my printer according to documentation…

Here ist my config…

#######################################################################################################################          
### Octoprint Schalter ###
##########################
switch:

  - platform: command_line
    scan_interval: 5
    switches:
      connection_octoprint:
        friendly_name: "Octoprint Verbindung"
        command_on: "curl http://192.168.1.111:5000/api/connection -d '{\"command\":\"connect\"}' -H 'Content-Type: application/json' -H 'X-Api-Key: < your API Key >'"
        command_off: "curl http://192.168.1.111:5000/api/connection -d '{\"command\":\"disconnect\"}' -H 'Content-Type: application/json' -H 'X-Api-Key: < your API Key >'"
        command_state: "curl http://192.168.1.111:5000/api/printer"
        value_template: "{{ '\"ready\": true' in value }}"
        
  - platform: command_line
    scan_interval: 5
    switches:
      octoprint_cancel:
        friendly_name: "Octoprint ABBRUCH"
        command_on: "curl http://192.168.1.111:5000/api/job -d '{\"command\":\"cancel\"}' -H 'Content-Type: application/json' -H 'X-Api-Key: < your API Key >'"
        command_state: "curl http://192.168.1.111:5000/api/printer"
        value_template: "{{ '\"cancelling\": true' in value }}"
        
  - platform: command_line
    scan_interval: 5
    switches:
      pause_octoprint:
        friendly_name: "Octoprint PAUSE"
        command_on: "curl http://192.168.1.111:5000/api/job -d '{\"command\":\"pause\",\"action\":\"pause\"}' -H 'Content-Type: application/json' -H 'X-Api-Key: < your API Key >'"
        command_off: "curl http://192.168.1.111:5000/api/job -d '{\"command\":\"pause\",\"action\":\"resume\"}' -H 'Content-Type: application/json' -H 'X-Api-Key: < your API Key >'"
        command_state: "curl http://192.168.1.111:5000/api/printer"
        value_template: "{{ '\"paused\": true' in value }}"
    
### Steuerung von Octoprint ###
  - platform: command_line
    switches:
      x_y_home:           
        #X Y HOME
        command_on: "curl http://192.168.1.111:5000/api/printer/printhead -d '{\"command\":\"home\",\"axes\":[\"x\",\"y\"]}' -H 'Content-Type: application/json' -H 'X-Api-Key: < your API Key >'"
        command_off: "curl http://192.168.1.111:5000/api/printer/printhead -d '{\"command\":\"home\",\"axes\":[\"x\",\"y\"]}' -H 'Content-Type: application/json' -H 'X-Api-Key: < your API Key >'"
  
  - platform: command_line
    switches:
      z_home:
        #Z HOME
        command_on: "curl http://192.168.1.111:5000/api/printer/printhead -d '{\"command\":\"home\",\"axes\":[\"z\"]}' -H 'Content-Type: application/json' -H 'X-Api-Key: < your API Key >'"
        command_off: "curl http://192.168.1.111:5000/api/printer/printhead -d '{\"command\":\"home\",\"axes\":[\"z\"]}' -H 'Content-Type: application/json' -H 'X-Api-Key: < your API Key >'"

  - platform: command_line
    switches:
      z_oben:
       #Z oben 10mm
        command_on: "curl http://192.168.1.111:5000/api/printer/printhead -d '{\"command\":\"jog\",\"z\":10}' -H 'Content-Type: application/json' -H 'X-Api-Key: < your API Key >'"
        command_off: "curl http://192.168.1.111:5000/api/printer/printhead -d '{\"command\":\"jog\",\"z\":10}' -H 'Content-Type: application/json' -H 'X-Api-Key: < your API Key >'"

  - platform: command_line
    switches:
      z_unten:    
        #Z unten 10mm
        command_on: "curl http://192.168.1.111:5000/api/printer/printhead -d '{\"command\":\"jog\",\"z\":-10}' -H 'Content-Type: application/json' -H 'X-Api-Key: < your API Key >'"
        command_off: "curl http://192.168.1.111:5000/api/printer/printhead -d '{\"command\":\"jog\",\"z\":-10}' -H 'Content-Type: application/json' -H 'X-Api-Key: < your API Key >'"
  
  - platform: command_line
    switches:
      y_vorne:
        #Y vorne 10mm
        command_on: "curl http://192.168.1.111:5000/api/printer/printhead -d '{\"command\":\"jog\",\"y\":10}' -H 'Content-Type: application/json' -H 'X-Api-Key: < your API Key >'"
        command_off: "curl http://192.168.1.111:5000/api/printer/printhead -d '{\"command\":\"jog\",\"y\":10}' -H 'Content-Type: application/json' -H 'X-Api-Key: < your API Key >'"                
  
  - platform: command_line
    switches:
      y_hinten:    
        #Y hinten 10mm
        command_on: "curl http://192.168.1.111:5000/api/printer/printhead -d '{\"command\":\"jog\",\"y\":-10}' -H 'Content-Type: application/json' -H 'X-Api-Key: < your API Key >'"
        command_off: "curl http://192.168.1.111:5000/api/printer/printhead -d '{\"command\":\"jog\",\"y\":-10}' -H 'Content-Type: application/json' -H 'X-Api-Key: < your API Key >'"
  
  - platform: command_line
    switches:
      x_rechts:
        #X rechts 10mm
        command_on: "curl http://192.168.1.111:5000/api/printer/printhead -d '{\"command\":\"jog\",\"x\":10}' -H 'Content-Type: application/json' -H 'X-Api-Key: < your API Key >'"
        command_off: "curl http://192.168.1.111:5000/api/printer/printhead -d '{\"command\":\"jog\",\"x\":10}' -H 'Content-Type: application/json' -H 'X-Api-Key: < your API Key >'"
 
  - platform: command_line
    switches:
      x_links:    
        #x links 10mm
        command_on: "curl http://192.168.1.111:5000/api/printer/printhead -d '{\"command\":\"jog\",\"x\":-10}' -H 'Content-Type: application/json' -H 'X-Api-Key: < your API Key >'"
        command_off: "curl http://192.168.1.111:5000/api/printer/printhead -d '{\"command\":\"jog\",\"x\":-10}' -H 'Content-Type: application/json' -H 'X-Api-Key: < your API Key >'"
        
  - platform: command_line
    switches:
      druckbett_60:
        #DRUCKBETT auf 60°
        command_on: "curl http://192.168.1.111:5000/api/printer/bed -d '{\"command\":\"target\",\"target\":60}' -H 'Content-Type: application/json' -H 'X-Api-Key: < your API Key >'"
        command_off: "curl http://192.168.1.111:5000/api/printer/bed -d '{\"command\":\"target\",\"target\":0}' -H 'Content-Type: application/json' -H 'X-Api-Key: < your API Key >'"
  
  - platform: command_line
    switches:
      nozzle_200:
        #NOZZLE AUF 200°
        command_on: "curl http://192.168.1.111:5000/api/printer/tool -d '{\"command\":\"target\",\"targets\":{\"tool0\":200}}' -H 'Content-Type: application/json' -H 'X-Api-Key: < your API Key >'"        
        command_off: "curl http://192.168.1.111:5000/api/printer/tool -d '{\"command\":\"target\",\"targets\":{\"tool0\":0}}' -H 'Content-Type: application/json' -H 'X-Api-Key: < your API Key >'"

I have taken switches because there are always problems in docker container from homeassistant with shell_commands

here my lovelace view:

9 Likes

Wow, that’s great. Love the panel and using attributes for temperatures. Clever stuff! A few questions:

  1. Can you share your yaml for the lovelace panel? I will do the switch for the frontend soon and this may help.
  2. Are you using command line sensors for the sensors? Care to share the code for that too?

no problem, I’m always happy if I help anyone!

lovelace:

##################################################################################################################################################################
### Octoprint  ###
### 3D Drucker ###
##################
  - icon: mdi:printer-3d
    panel: false
    cards:    
      - type: conditional
        conditions:
          - entity: timer.druckercooldown
            state: "active"
        card:
          type: "custom:button-card"
          entity: timer.druckercooldown
          layout: icon_state_name2nd
          show_state: true
          show_name: true
          show_label: true
          name: Ender 3 COOLDOWN
          styles:
            grid:
              - grid-template-areas: '"n i" "s i" "l i"'
              - grid-template-columns: 1fr 40%
            card:
              - font-size: 15px
            label:
              - font-size: 8px
            state:
              - text-transform: uppercase
              - font-size: 25px
              - font-weight: bold   

      - type: custom:vertical-stack-in-card
        cards:
        - type: horizontal-stack
          cards:
            - type: "custom:button-card"
              entity: switch.4ch1_3d_drucker
              size: 40%
              name: Ender 3
              show_last_changed: false
              lock:
               enabled: true
               duration: 3
               unlock: hold
              style:
                - font-size: 12px
                - font-weight: bold             
              color: rgb(0, 255, 0)
              state:
                - value: "off"
                  color: rgb(255, 0, 0)
            - type: "custom:button-card"
              entity: switch.connection_octoprint
              size: 40%
              name: Verbindung
              show_last_changed: false
              lock:
               enabled: true
               duration: 3
               unlock: hold
              style:
                - font-size: 12px
                - font-weight: bold             
              color: rgb(0, 255, 0)
              state:
                - value: "off"
                  color: rgb(255, 0, 0)
                  icon: mdi:lan-disconnect
        - type: horizontal-stack
          cards:
            - type: "custom:button-card"
              entity: switch.pause_octoprint
              size: 40%
              name: PAUSE
              show_last_changed: false
              lock:
               enabled: true
               duration: 3
               unlock: hold
              style:
                - font-size: 12px
                - font-weight: bold             
              color: rgb(0, 255, 0)
              icon: mdi:pause-octagon-outline
              state:
                - value: "off"
                  color: rgb(255, 0, 0)
                  icon: mdi:pause-octagon-outline
            - type: "custom:button-card"
              entity: switch.octoprint_cancel
              size: 40%
              name: STOPP
              show_last_changed: false
              lock:
               enabled: true
               duration: 3
               unlock: hold
              style:
                - font-size: 12px
                - font-weight: bold             
              color: rgb(0, 255, 0)
              icon: mdi:cancel
              state:
                - value: "off"
                  color: rgb(255, 0, 0)
                  icon: mdi:cancel
            - type: "custom:button-card"
              entity: switch.filament
              size: 40%
              name: Filament
              show_last_changed: false
              lock:
               enabled: true
               duration: 3
               unlock: hold
              style:
                - font-size: 12px
                - font-weight: bold             
              color: rgb(0, 255, 0)
              icon: mdi:movie-roll
              state:
                - value: "off"
                  color: rgb(255, 0, 0)
                  icon: mdi:restart-off
                - value: "unavailable"
                  color: rgb(255, 0, 0)
                  icon: mdi:restart-off
        - type: custom:vertical-stack-in-card  
          cards:      
          - type: horizontal-stack
            cards:
            - type: "custom:button-card"
              color_type: blank-card
            - type: custom:button-card
              entity: switch.y_vorne
              icon: mdi:arrow-up-bold-outline
              color: rgb(28, 128, 199)
              lock:
               enabled: true
               duration: 3
               unlock: hold
            - type: "custom:button-card"
              color_type: blank-card
            - type: custom:button-card
              entity: switch.z_oben
              icon: mdi:arrow-up-bold-outline
              color: rgb(28, 128, 199)
              lock:
               enabled: true
               duration: 3
               unlock: hold            
          - type: horizontal-stack
            cards:
            - type: custom:button-card
              entity: switch.x_links
              icon: mdi:arrow-left-bold-outline
              color: rgb(28, 128, 199)
              lock:
               enabled: true
               duration: 3
               unlock: hold
            - type: custom:button-card
              entity: switch.x_y_home
              icon: mdi:home
              color: rgb(28, 128, 199)
              lock:
               enabled: true
               duration: 3
               unlock: hold            
            - type: custom:button-card
              entity: switch.x_rechts
              icon: mdi:arrow-right-bold-outline
              color: rgb(28, 128, 199)
              lock:
               enabled: true
               duration: 3
               unlock: hold
            - type: custom:button-card
              entity: switch.z_home
              icon: mdi:home
              color: rgb(28, 128, 199)
              lock:
               enabled: true
               duration: 3
               unlock: hold            
          - type: horizontal-stack
            cards: 
            - type: "custom:button-card"
              color_type: blank-card          
            - type: custom:button-card
              entity: switch.y_hinten
              icon: mdi:arrow-down-bold-outline
              color: rgb(28, 128, 199)
              lock:
               enabled: true
               duration: 3
               unlock: hold
            - type: "custom:button-card"
              color_type: blank-card           
            - type: custom:button-card
              entity: switch.z_unten
              icon: mdi:arrow-down-bold-outline
              color: rgb(28, 128, 199)
              lock:
               enabled: true
               duration: 3
               unlock: hold        
          - type: vertical-stack
            cards:
            - type: "custom:text-divider-row"
              text: Vorheizen
          - type: horizontal-stack
            cards:
            - type: custom:button-card
              entity: switch.nozzle_200
              icon: mdi:printer-3d-nozzle-outline
              color: rgb(28, 128, 199)
              name: 'Nozzle 200°C'
              lock:
                enabled: true
                duration: 3
                unlock: hold
                exemptions: []
            - type: custom:button-card
              entity: switch.druckbett_60
              icon: mdi:codepen
              color: rgb(28, 128, 199)
              name: 'Druckbett 60°C'
              lock:
               enabled: true
               duration: 3
               unlock: hold 

            
      - type: custom:vertical-stack-in-card
        cards:
          - type: horizontal-stack
            cards:
            - type: gauge
              unit: '%' 
              min: 0
              max: 100        
              entity: sensor.octoprint_creality_3d_ender_3_job_percentage
            - type: custom:button-card
              entity: sensor.ender_3_zustand
              show_entity_picture: true
              show_state: false
              show_name: false
              tap_action:
                action: navigate
                navigation_path: http://192.168.1.111:8123/octoprint
                
          - type: entities
            entities:
              - sensor.stl_datei
              - sensor.stl_grosse
              - sensor.filament_kosten
              - sensor.filament_menge 
              - type: divider              
              - type: weblink
                name: "OctoPrint Server GUI"
                url: http://192.168.1.111:5000
              - type: divider         
              - sensor.octoprint_creality_3d_ender_3_current_state
              - binary_sensor.octoprint_creality_3d_ender_3_printing
              - binary_sensor.octoprint_creality_3d_ender_3_printing_error
             # - sensor.octoprint_creality_3d_ender_3_job_percentage
              - type: "custom:secondaryinfo-entity-row"
                entity: sensor.octoprint_creality_3d_ender_3_actual_tool0_temp
                secondary_info: "Soll Temperatur: [[ sensor.octoprint_creality_3d_ender_3_target_tool0_temp.state ]] °C"
             # - sensor.octoprint_creality_3d_ender_3_actual_tool0_temp
             # - sensor.octoprint_creality_3d_ender_3_target_tool0_temp
              - type: "custom:secondaryinfo-entity-row"
                entity: sensor.octoprint_creality_3d_ender_3_actual_bed_temp
                secondary_info: "Soll Temperatur: [[ sensor.octoprint_creality_3d_ender_3_target_bed_temp.state ]] °C"
            #  - sensor.octoprint_creality_3d_ender_3_actual_bed_temp
            #  - sensor.octoprint_creality_3d_ender_3_target_bed_temp
            #  - sensor.octoprint_creality_3d_ender_3_time_elapsed
              - sensor.octoprint_creality_3d_ender_3_time_elapsed_format
            #  - sensor.octoprint_creality_3d_ender_3_time_remaining
              - sensor.octoprint_creality_3d_ender_3_time_remaining_format
              
      
      - type: custom:vertical-stack-in-card
        cards:
          - type: picture-glance
            title: "3D Drucker Kamera"
            entities:
              - camera.3d_drucker
            camera_image: camera.3d_drucker
            camera_view: live
            
          - type: entities
            #title: Automatisierungen
            show_header_toggle: false
            entities:
              - type: custom:text-divider-row
                text: Automatisierungen
              - automation.3d_drucker_start
              - automation.3d_druckvorgang_abgeschlossen
              - type: "custom:secondaryinfo-entity-row"
                entity: automation.3d_drucker_pause_filamentende
                secondary_info: "Filament Schalter: [[ switch.filament.state ]]"
            #title: Scripte
              - type: custom:text-divider-row
                text: Scripte
              - script.1547744301742
              - script.1547752003201
              - type: divider

Sensor:

########################################################################
#### OCTOPRINT ZEITUMRECHNUNG! ####
###################################
  - platform: template
    sensors:
      octoprint_creality_3d_ender_3_time_elapsed_format:
        friendly_name: 'Vergangene Druckzeit'
        value_template: >-
          {% set etime = states.sensor.octoprint_creality_3d_ender_3_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_creality_3d_ender_3_time_remaining_format:
        friendly_name: 'Voraussichtliche Druckzeit'
        value_template: >-
          {% set rtime = states.sensor.octoprint_creality_3d_ender_3_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 -%}
            {%- if minutes == 1 -%}
              1 minute
            {%- else -%}
              {{ minutes }} minutes
            {%- endif -%}
          {%- endif -%}

### Druckzustand ###
  - platform: template
    sensors:
      ender_3_zustand:
        value_template: '{{ states.sensor.octoprint_creality_3d_ender_3_current_state.state }}'
        entity_id: sensor.octoprint_creality_3d_ender_3_current_state
        friendly_name: 'Ender 3'
        entity_picture_template: >
          {% set state = states('sensor.octoprint_creality_3d_ender_3_current_state') %}
          {{ '/local/icons/3d_drucker/{}.gif'.format(state) }}

Print state template is animated with the different states! (Druckzustand)

and then the sensors for STL file etc …

#######################################################################        
### OCTOPRINT ###
#################
  - platform: rest
    resource: 'http://192.168.1.111:5000/api/job'
    name: "STL Datei"
    value_template: '{{value_json.job.file.display}}'
    
  - platform: rest
    resource: 'http://192.168.1.111:5000/api/job'
    name: "Filament Menge API"
    value_template: '{{ value_json.job.filament.tool0.length | float / 1000 }}'
    unit_of_measurement: 'm'
  
  - platform: rest
    resource: 'http://192.168.1.111:5000/api/job'
    name: "STL Grosse API"
    value_template: '{{ value_json.job.file.size | float / 1000000 }}'
    unit_of_measurement: 'MB' 
  
  - platform: template
    sensors:
      filament_menge:
        friendly_name: "Filament Menge"
        unit_of_measurement: 'm'
        value_template: "{{ states('sensor.filament_menge_api') | round(1) }}"
        
  - platform: template
    sensors:
      stl_grosse:
        friendly_name: "STL Größe"
        unit_of_measurement: 'MB'
        value_template: "{{ states('sensor.stl_grosse_api') | round(1) }}"
        
  - platform: template ### 1kg = 18€ und ca.345m Filament = 0.052€
    sensors:
      filament_kosten:
        friendly_name: "Filament Kosten"
        unit_of_measurement: '€'
        value_template: "{{ states('sensor.filament_menge_api') | multiply(0.052) | round(1) }}"

i hope i have nothing forget :wink:
Happy Fun!

Regards…

edit:

Timer:

  druckercooldown:
    name: 'Cool Down' 
    duration: '00:02:00'
9 Likes

Great work @Johann_Edelmuller … I’m going t o have to spend some time this weekend and add to my Octoprint page! Just the things I have been going to dig into.

Thank you

Tried to use the sensor for the STL filename. I get unknown for the state. There are no errors that I see. I’m not very familiar with the Rest platform so I can’t seem to trouble shoot what the issue is. I basically copied your code for the the “STL Datei” and changed the IP to match my Octoprint IP. I use the Octoprint component and get info thru that with no issues.

What am I missing? Does the Rest resource need the API key? or user/password?

Please Post your json with

curl http://192.168.1.111:5000/api/job

And Test this

value_template: ‘{{value_json.job.file.name}}’