cmroche/OctoPrint-HomeAssistant

[Request] Sensor: Material used

Opened this issue · 2 comments

I would really love if octoprint could send HA the amount of material used (grams, cm, etc) as sensors to home assistant. I'd love to be able to send myself a notification with the total cost of a print once it finishes, and be able to more easily keep track of filament usage.

Thanks for the suggestion.

To be honest, I'm not sure if I will really be able to get that information, but I'll take a look through the update messages to see what information is provided.

This used to be sent, but recently disappeared somehow. I had these template sensors in Home-Assistant to show them on my dashboard:

      filament_menge:
        friendly_name: "Filament Menge"
        unit_of_measurement: "m"
        value_template: >
          {% if states.sensor.octoprint_print_estimated_time.state != 'None' %}
            {{ (state_attr('sensor.octoprint_print_estimated_time', 'filament'))['tool0']['length'] | round(1) | default(0) }}
          {%else%}
            {{"0"}}
          {% endif %}

      filament_volumen:
        friendly_name: "Filament Volumen"
        unit_of_measurement: "g"
        value_template: >
          {% if states.sensor.octoprint_print_estimated_time.state != 'None' %}
            {{ (state_attr('sensor.octoprint_print_estimated_time', 'filament'))['tool0']['volume'] | round(1) | default(0) }}
          {%else%}
            {{"0"}}
          {% endif %}

      gcode_grosse:
        friendly_name: "Gcode Größe"
        unit_of_measurement: "MB"
        value_template: >
          {% if states.sensor.octoprint_print_estimated_time.state != 'None' %}
            {{ ((state_attr('sensor.octoprint_print_estimated_time', 'file'))['size'] | float /1000000) | round(3) | default(0) }}
          {%else%}
            {{"0"}}
          {% endif %}

My guess is that the used values came from this topic: octoprint/progress/printing
The file and filament 'nodes' are still there in the JSON. However, the filament node is now empty and contents from both nodes aren't exposed in HA anymore.