Octoprint setup, UI, scripts and automations

I found a shop here selling it but they have 20 days delivery, so I’m guessing their stock is questionable.

I can call them on Monday and ask I’d they can get it and ship it to you?

Is there a possibility to add the start stop printer, choose file etc commands to the official integration. Thank you

1 Like

Pretty happy with my setup :smile:

2 Likes

Very nice! could you give us some info on your hardware and sensors?

There are definitely better ways to do it now when I look back at my setup but this happens when you start adding features as you build and use stuff you have lying around. I would also upload some pics but I just busted my mobile phone’s screen and waiting for replacement. I will try to upload some at the later date.

So I’m running 4 ESPhome boards. Three of them built in my enclosure and one separated.

Board 1 - Esphome flashed D1Mini driving two 140mm independent fans (for climate control) connected to D1mini via simple transistor board. Exhaust fan has carbon and hepa filter installed. Additionally board is driving spot light which is basically two 5v led usb/thumb lights in small enclosure so I can illuminate the area for the pi cam. I also connected two buttons with leds to Dmini for the control panel I have on the front of the enclosure.

Board 2 - Esphome flashed Arilux basic led driver connected to rgb led strip for the whole enclosure illumination. I used additional gpios for driving the hall sensor installed in the door for the enclosure to light up when door is opened. I also have button with led for the front panel.

Board 3 - Esphome flashed Sonoff basic to shut down the printer and octopi with the relay. It also has button with led for the front panel.

Board 4 - Its a separated device I made for my desk. Its a esp32 board esphome flashed which has sensirion sps30 air quality sensor connected to it.The board also has small oled screen to display sensors data. The board also tracks two BLE temp/humidity sensors in my two filament dry boxes. I use the device with rotary encoder to see and adjust home thermostat but that is not octoprint related.

As I had one extra deconz connect temp/humidity/pressure sensor I use it inside the enclosure for the enclosure climate control.

Did I mention I love ESPhome :slight_smile:

It all sounds a bit messy but really isn’t. If I started working on this now I would definitely use less boards but maybe for enclosure 2.0 I will. For now my setup works great.

nice! The REST call for shutting down octoprint solved one of my issues with my setup.
I have a homematic smart switch with power monitoring which I used to hard shut down the printer after the nozzle was cooled below 30°. I have added the REST API call to shut down the octoprint raspi and after 20 seconds I shut down the whole setup.
I tried to keep the interface clean and simple because I mainly use the infos on the phone, on the desktop I use octoprint directly. Don’t mind the background - I use animated background and this looks funky on some screens :slight_smile:

1 Like

Very Nice !! Do you want to share the code for this ?

Here you are :slight_smile:
I have tweaked it a bit again.
Btw.: the colors change depending on the state. I have a scheme there for all of my devices/sensors:
white - off
blue - on/operational/standby
green/yellow/red - working states depending on state (eg temperature)

cards:
  - cards:
      - entity: sensor.ender_3_pro_current_state
        name: Status
        aspect_ratio: 1/1
        show_state: true
        state:
          - value: Operational
            color: blue
          - value: Printing
            color: green
        type: 'custom:button-card'
      - type: button
        tap_action:
          action: toggle
        entity: switch.0001d3c99c8439
        name: 'ON'
        icon: 'mdi:power-on'
      - entity: script.3d_printer_shutdown
        hold_action:
          action: more-info
        icon: 'mdi:power-off'
        show_icon: true
        show_name: true
        tap_action:
          action: toggle
        type: button
        name: 'OFF'
      - entity: sensor.ender_3_pro_job_percentage
        max: 100
        min: 0
        name: Fortschritt
        type: gauge
    type: horizontal-stack
  - cards:
      - entity: sensor.ender_3_pro_actual_tool0_temp
        show_state: true
        name: Nozzle
        icon: 'mdi:printer-3d-nozzle-outline'
        state:
          - value: 0
            color: white
          - value: 190
            operator: <=
            color: blue
          - value: 250
            operator: '>='
            color: red
          - operator: default
            color: green
        type: 'custom:button-card'
      - entity: sensor.ender_3_pro_actual_bed_temp
        show_state: true
        name: Bed
        icon: 'mdi:radiator'
        state:
          - value: 0
            color: white
          - value: 50
            operator: <=
            color: blue
          - value: 75
            operator: '>='
            color: red
          - operator: default
            color: green
        type: 'custom:button-card'
      - entity: sensor.3d_printer_power
        show_state: true
        name: aktuell
        state:
          - value: 5
            operator: <=
            color: white
          - value: 20
            operator: <=
            color: green
          - operator: default
            color: yellow
        type: 'custom:button-card'
      - entity: sensor.3d_printer_energy_since_switch_restart
        show_state: true
        name: gesamt
        type: 'custom:button-card'
    type: horizontal-stack
  - aspect_ratio: 50%
    camera_image: camera.octoprint
    entity: camera.octoprint
    type: picture-entity
    show_state: false
    show_name: false
  - cards:
      - entity: sensor.ender_3_pro_time_elapsed_format
        name: Druckzeit bisher
        type: entity
        icon: 'mdi:clock-start'
      - entity: sensor.ender_3_pro_time_remaining_format
        name: Druckzeit verbleibend
        type: entity
        icon: 'mdi:clock-end'
    type: horizontal-stack
  - cards:
      - animate: true
        color_thresholds:
          - color: green
            value: 20
          - color: yellow
            value: 100
          - color: red
            value: 200
        entities:
          - entity: sensor.3d_printer_power
            name: Verbrauch
        font_size: 75
        hour24: true
        hours_to_show: 168
        labels: true
        labels_secondary: true
        line_color: blue
        line_width: 3
        lower_bound: 0
        name: Leistung letzte Woche
        icon: 'mdi:chart-line'
        points_per_hour: 2
        show:
          extrema: true
          labels: true
          points: hover
          state: false
          fill: true
        type: 'custom:mini-graph-card'
        upper_bound: 350
    type: horizontal-stack
type: vertical-stack

4 Likes

Thanks for the code !!

1 Like

Does this actually trigger on 3dprinter fumes like from PLA? I’ve played with adding a air quality sensor too, but those are quite expensive and I don’t want to waste money on something that doesn’t sense printer fumes. This could of course be used as a smoke detector if something goes really south and turn off power for the printer.

Sps30 only shows amount of particles in the air so its not the whole story. Ideally I would also need VOC sensor just cover for harmful gasses. Still particle sensor gives me idea what is going on.

I dont think that printing Pla occasionally cause much issue. My sensor goes so much higher when I solder for example. Still when I did not have enclosure plus filters I could easily smell pla print going on even from the other room. Now with enclosure and two filters I cannot smell a thing.

Btw sensors are not that expensive. I paid for my sps30 just under £30.

Are any of these sensors suitable for a living room?
Have you implemented any, or have any suggestions?

Also what are the steps to “repair” the air quality? open the windows? run the AC?
I have a fireplace that we occasionally use and sometimes i have some heavy smokers over, how could i monitor that?

Edit: well i’m going out of subject in my own thread :blush: Any resources i could follow?

First there is bunch of different sensors you could use. I would say you could use any of them in your living room. I decided to use sps30 because of price, wide range of particle sensing and easy implementation via ESPHome. See https://esphome.io/index.html#sensor-components for the list of all sensors you could use. This is how my sensor device looks like:

As to the subject about air quality. According to what I saw how my sensor reacts ventilation has a big impact on lowering particles. Probably best would be to completely exhaust stuff from enclosure to outside but I do not have the option to run ducts in my room. Second best probably is filtration IMO and this is massive subject I’m not that advanced in. I started printing less than year ago and trying to read studies about how harmful printing actually is. There is not much info unfortunately so I’m using my common sense mostly :slight_smile:

I know - I can see spikes on a xiaomi air purifier in the next room when I do small solder work in my office :wink: . But at least the xiaomi doesn’t show when I’m printing. So I think the odors the printer emits are different particle size than the sensor (guess it is quite similar to the sps30) registers. The room gets ventilated regularly and is not permanently occupied, so I guess it is no problem.

edit: got it to work :slight_smile:

@krash could you describe lite more how you got the stream from OctoPrint to work?
I have a USB camera connected to my OctoPrint, I can see the stream in OctoPrint. But how can I get the stream to work in Home Assistant.

Thanx for sharing your config

You need to add camera to your config file. Something like this:

camera:
  - platform: mjpeg
    name: OctoPrint
    still_image_url: http://192.168.0.100/webcam/?action=snapshot
    mjpeg_url: http://192.168.0.100/webcam/?action=stream

Exactly as @wasyl00 above:

camera:
  - platform: mjpeg
    name: OctoPrint
    still_image_url: http://10.0.0.69/webcam/?action=snapshot
    mjpeg_url: http://10.0.0.69/webcam/?action=stream

Question, Where to put the time correction code?

Anywhere, under a sensor: tag.

If you keep your sensors inside your configuration.yaml you can put it as an extra sensor under there (ignore the sensor: line in my code)

If your configuration has a sensor: !include sensors.yaml line in it and you have a separate sensors file, drop it in there, again ignoring the first line.
You can also create a new sensors.yaml file and move all your sensors there.

If you are using packages (look it up, I can’t link it rn, I’m on mobile) then you will need to paste the whole code (with the first sensor: line) in your package file and include packages as stated in the documentation.

The whole procedure is described here:

Edit: Changed script into sensors, i missunderstood at first.

Ok I have placed the entire script into scripts.yaml.
Does this apply to all my octoprint instances? I am running multiple octoprints.
I am very new to HA + yaml :slight_smile:
This is what I have placed in scripts.yaml

sensor: #fix time display
 - platform: template
   sensors:
     octoprint_time_elapsed_format:
       friendly_name: 'Printing Time Elapsed'
       value_template: >-
         {% set etime = states.sensor.octoprint_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_time_remaining_format:
       friendly_name: 'Printing Time Remaining'
       value_template: >-
         {% set rtime = states.sensor.octoprint_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 -%}