Prusa Mini 3D Printer Info

I have a Prusa Mini 3D Printer that give out details via HTTP
htttp://[ip address of the mini]/api/telemetry
Format is Json
For example:
{"temp_nozzle":214,"temp_bed":60,"material":"PLA","pos_z_mm":4.44,"printing_speed":100,"flow_factor":95,"progress":95,"print_dur":" 59m 50s","time_est":"120","project_name":"myfile.gcode"}

There is an OpenHab integration already:

Just throwing this out there, just in case you are not aware of it. You can achieve this with OctoPrint:

And, there is and Integration for OctoPrint with in Home Assistant.

4 Likes

Yes I have Otcoprint installed but not tried it out yet with the printer.

I think you should give it a go, you wont be disappointed.

I just created custom component for myself. I haven’t tested it outside my ha instance, but should work without problems.

3 Likes

I’m currently planning for my mini to arrive. I’ve used your json output above to create a Node-Red json to mqtt converter. I want to use the output with multiple devices via mqtt. If you use Node-Red give this a try.

[
    {
        "id": "18ee8d84.34c782",
        "type": "inject",
        "z": "ea3945d9.c8d4a8",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 140,
        "y": 1280,
        "wires": [
            [
                "c2072069.25f55"
            ]
        ]
    },
    {
        "id": "c2072069.25f55",
        "type": "http request",
        "z": "ea3945d9.c8d4a8",
        "name": "",
        "method": "GET",
        "ret": "obj",
        "paytoqs": "ignore",
        "url": "htttp://[ip address of the mini]/api/telemetry",
        "tls": "",
        "persist": false,
        "proxy": "",
        "authType": "",
        "x": 330,
        "y": 1280,
        "wires": [
            [
                "5a65e0b0.3fba7"
            ]
        ]
    },
    {
        "id": "5a65e0b0.3fba7",
        "type": "function",
        "z": "ea3945d9.c8d4a8",
        "name": "",
        "func": "if (msg.payload.project_name) {\n    var mqttTopicPrefix = \"prusa-connect/\"\n    var msgs = [];\n\n    for (const [key, value] of Object.entries(msg.payload)) {\n        msgs.push({topic: mqttTopicPrefix+key, payload: value});\n    }\n    return [msgs]\n}",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 500,
        "y": 1280,
        "wires": [
            [
                "1fa2852d.6479cb"
            ]
        ]
    },
    {
        "id": "1fa2852d.6479cb",
        "type": "mqtt out",
        "z": "ea3945d9.c8d4a8",
        "name": "",
        "topic": "",
        "qos": "",
        "retain": "",
        "broker": "837c761e.10e788",
        "x": 690,
        "y": 1280,
        "wires": []
    },
    {
        "id": "837c761e.10e788",
        "type": "mqtt-broker",
        "name": "mosquitto",
        "broker": "myMqttBroker",
        "port": "1883",
        "clientid": "Node-RED",
        "usetls": false,
        "compatmode": true,
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "willTopic": "",
        "willQos": "0",
        "willPayload": ""
    }
]

Or using a rest sensor

platform: rest
name: "prusa-connect"
resource: http://[ip address of the mini]/api/telemetry
value_template: '{{ value_json.progress }}'
unit_of_measurement: "%"
scan_interval: 30
json_attributes:
      - "temp_nozzle"
      - "temp_bed"
      - "material"
      - "pos_z_mm"
      - "printing_speed"
      - "flow_factor"
      - "progress"
      - "print_dur"
      - "time_est"
      - "project_name"

platform: template
sensors:
  prusa_connect_progress:
    friendly_name: "Print Progress"
    value_template: '{{ states.sensor.prusa_connect.attributes["progress"] }}'
    unit_of_measurement: "%"
    icon_template: mdi:printer-3d
  prusa_connect_temp_nozzle:
    friendly_name: "Nozzle Temperature"
    value_template: '{{ states.sensor.prusa_connect.attributes["temp_nozzle"] }}'
    unit_of_measurement: "°C"
    device_class: temperature
    icon_template: mdi:printer-3d-nozzle
  prusa_connect_temp_bed:
    friendly_name: "Heatbed"
    value_template: '{{ states.sensor.prusa_connect.attributes["temp_bed"] }}'
    unit_of_measurement: "°C"
    device_class: temperature
  prusa_connect_material:
    friendly_name: "Material"
    value_template: '{{ states.sensor.prusa_connect.attributes["material"] }}'
    icon_template: mdi:wall
  prusa_connect_pos_z_mm:
    friendly_name: "Z-Height"
    value_template: '{{ states.sensor.prusa_connect.attributes["pos_z_mm"] }}'
    unit_of_measurement: "mm"
    icon_template: mdi:tape-measure
  prusa_connect_printing_speed:
    friendly_name: "Printing Speed"
    value_template: '{{ states.sensor.prusa_connect.attributes["printing_speed"] }}'
    icon_template: mdi:speedometer
    unit_of_measurement: "%"
  prusa_connect_flow_factor:
    friendly_name: "Printing Flow"
    value_template: '{{ states.sensor.prusa_connect.attributes["flow_factor"] }}'
    icon_template: mdi:water
  prusa_connect_print_dur:
    friendly_name: "Printing Time"
    value_template: '{{ states.sensor.prusa_connect.attributes["print_dur"] }}'
    icon_template: mdi:timer-sand
  prusa_connect_time_est:
    friendly_name: "Estimated End"
    value_template: '{{ states.sensor.prusa_connect.attributes["time_est"] }}'
    icon_template: mdi:timelapse
  prusa_connect_project_name:
    friendly_name: "Project"
    value_template: '{{ states.sensor.prusa_connect.attributes["project_name"] }}'
    icon_template: mdi:file
3 Likes

Remove the extra ‘t’ in your htttp, save someone else a few seconds troubleshooting

1 Like

Thanks for the heads up!

No problem, thank you for your template. Your template saved me some time; I found the api page on my Prusa Mini and started my own rest sensor, then I thought, let’s see if anyone else already did this and low and behold the search function works.

I made a few tweaks:

This is probably the most useful to everyone:

    prusa_connect_time_done:
      friendly_name: "Estimated Completion Time"
      value_template: "{{ (as_timestamp(now()) + states('sensor.prusa_connect_time_est') | float) | timestamp_custom('%H:%M')}}"
      icon_template: mdi:calendar-clock
2 Likes

Thank you! This is exactly what I was looking for.

One more sensor that I use to trigger a notification upon print completion:

prusa_connect_status:
  friendly_name: "Printer Status"
  value_template: >-
    {% if states.sensor.prusa_connect.attributes["time_est"] is defined %}
      printing
    {% else %}
      idle
    {% endif %}
  icon_template: mdi:printer-3d

I would add a condition of nozzle <50C also since the fan is on until 50C.
Maybe if idle and >50C then ‘cooling’

A more usable countdown timer:
In hours and minutes left, which to me is easier to mentally compute.

    prusa_connect_time_countdown:
      friendly_name: "Estimated Completion Countdown"
      value_template: "{{ states('sensor.prusa_connect_time_est') | float | timestamp_custom('%H hr %M min', false)}}"
      icon_template: mdi:calendar-clock

I have not ever done a print >24 hrs so I’m not adding ‘days’ yet to the countdown.
I will work on an idle status like @allmyhinges posted added the cooldown. I like his idea and will utilize it.
I also will attempt to utilize the availability_template; I have not been sucessful too far but I might use the ping sensor to determine true/false for the template.

Another thought is to use the icon template to change icon based on status.

availability_template seems to be working for me:

        prusa_connect_status:
            friendly_name: "Printer Status"
            value_template: >-
                {% if states.sensor.prusa_connect.attributes["time_est"] is defined %}
                    printing
                {% else %}
                    idle
                {% endif %}
            icon_template: mdi:printer-3d
            availability_template: '{{ not is_state("sensor.prusa_connect", "unavailable") }}'

added this line to all my prusa connect sensors, and they all get grayed out and show up as “unavailable” whenever /api/telemetry endpoint becomes unavailable.

availability_template: '{{ not is_state("sensor.prusa_connect", "unavailable") }}'

It works with a little quirk; if the printer is off and HA is restarted it is unknown; but if I turn on printer it works with printer on or off. I expected it to be ‘unavailable’ if it was unavailable but that only works if printer is ever on. I can live with it just weird.

On a side note I add ‘Fan On’, I did not say cooling since I found that if you manually heat up nozzle it meets the same condition; so:

    prusa_connect_status:
      friendly_name: "Printer Status"
      value_template: >-
        {% if states.sensor.prusa_connect.attributes["time_est"] is defined %}
          Printing
        {% elif states.sensor.prusa_connect.attributes["temp_nozzle"] >= 50 %}
          Nozzle Fan On
        {% else %}
          Idle
        {% endif %}
      icon_template: mdi:printer-3d
      availability_template: '{{ not is_state("sensor.prusa_connect", "unavailable") }}'

Yeah, I noticed that too. Looks like there’s logic in components/rest/sensor.py that mandates that the REST endpoint return some data while HA is starting up, otherwise it’s treated as “unknown”… I can’t yet wrap my head around why it’s done this way… oh well.

I think I have all the possibilities covered now. This should cover any option except moving axis.
I have cooling twice since idle is 3W and the fan is only 1W for a total of 4W, due to that close tolerance I kept the 50C.

     prusa_connect_status:
       friendly_name: "Printer Status"
       value_template: >-
         {% if states.sensor.prusa_connect.attributes["time_est"] is defined %}
           Printing
         {% elif states('sensor.shelly_shsw_pm_xxxxxx_current_consumption') | float >= 50 %}
           Warming
         {% elif states('sensor.shelly_shsw_pm_xxxxxx_current_consumption') | float >= 35 %}
           Maintaining Temperature
         {% elif states('sensor.shelly_shsw_pm_xxxxxx_current_consumption') | float >= 4 %}
           Cooling
         {% elif states.sensor.prusa_connect.attributes["temp_nozzle"] >= 50 %}
           Cooling
         {% else %}
           Idle
         {% endif %}
       icon_template: mdi:printer-3d
       availability_template: '{{ not is_state("sensor.prusa_connect", "unavailable") }}'

Values are not completely arbitrary.
What I have measured on my Prusa Mini:
Idle 3W
Heat Up 170W (max)
Cooldown 4W
At temperature and maintaining 35W
I may end up adjusting the values a little, but from my testing they appear ok.

Does any one see anything I may have missed?

1 Like

I need to say thank you for your work. It’s awesome and works for me perfectelly.
Here is my lovelace setup.

2 Likes