I had the need to see the currently printing model in Home Assistant. I achieved this by using SuperSlicer to embed previews into the gcode, and scraping the image from an Octoprint plugin to a camera entity, which refreshes automatically and accepts templates.
I originally separated the url into a separate entity due to iterative learning process, but you could use this as a basis for a different setup.
First, the image name is extracted from the mqtt messages sent by Octoprint’s MQTT plugin. PrusaslicerThumbnail plugin will make thumbnails that match the gcode file name. This is the sensor, which was handy to keep separate.
- platform: mqtt state_topic: "octoPrint/progress/printing" value_template: "http://octoprint.ip.address:5000/plugin/prusaslicerthumbnails/thumbnail/{{(value_json.path)|regex_replace(find='gcode', replace='png', ignorecase=True)}}" force_update: true name: 'octoprint_filename_convert'
Here’s the camera – note the placeholder image in HA’s www folder, ensuring an image is displayed in Lovelace after a HA restart:
- platform: generic name: octoprint_preview_camera still_image_url: > {% if is_state('sensor.octoprint_filename_convert','unknown') %} https://127.0.0.1:8123/local/octo-placeholder.png {% else %} {{ states('sensor.octoprint_filename_convert') }} {% endif %} scan_interval: 5 content_type: image/png
Known limitation: Capital letters in gcode file names will break this if using Klipper’s virtual SD.
Update: Doing this with Moonraker based UIs is a bit more involved, as described here