I have a Prusa Mini, so my filament selections are based on that; however, you can modify and add any type of filament as desired.
I have a 5kg load cell to get the weight of the filament. I subtract the weight of the stand (~120g) and the weight of an empty spool (~200g) from the weight before it goes to HA.
I give the length in both meters and in feet. These are estimates based on average densities of various types of filament.
### Filament Weight
- platform: mqtt
name: "Prusa Filament Weight"
state_topic: "filament_3d/Weight"
json_attributes_topic: "filament_3d/Weight"
value_template: "{{ value_json }}"
state_class: measurement
#device_class:
unit_of_measurement: 'g'
icon: mdi:weight
- platform: mqtt
name: "Prusa Filament Percent"
state_topic: "filament_3d/Percent"
json_attributes_topic: "filament_3d/Percent"
value_template: "{{ value_json }}"
state_class: measurement
#device_class:
unit_of_measurement: '%'
icon: mdi:ferris-wheel
prusa_filament_length_metric:
friendly_name: "Printer Filament Length"
value_template: >-
{% if states.sensor.prusa_connect.attributes["material"] == "PLA" %}
{{(states('sensor.prusa_filament_weight') | float / 2.98) | round(2)}}
{% elif states.sensor.prusa_connect.attributes["material"] == "PETG" %}
{{(states('sensor.prusa_filament_weight') | float / 3.05) | round(2)}}
{% elif states.sensor.prusa_connect.attributes["material"] == "ASA" %}
{{(states('sensor.prusa_filament_weight') | float / 2.52) | round(2)}}
{% elif states.sensor.prusa_connect.attributes["material"] == "PC" %}
{{(states('sensor.prusa_filament_weight') | float / 3.13) | round(2)}}
{% elif states.sensor.prusa_connect.attributes["material"] == "PVB" %}
{{(states('sensor.prusa_filament_weight') | float / 2.64) | round(2)}}
{% elif states.sensor.prusa_connect.attributes["material"] == "ABS" %}
{{(states('sensor.prusa_filament_weight') | float / 2.50) | round(2)}}
{% elif states.sensor.prusa_connect.attributes["material"] == "HIPS" %}
{{(states('sensor.prusa_filament_weight') | float / 2.48) | round(2)}}
{% elif states.sensor.prusa_connect.attributes["material"] == "PP" %}
{{(states('sensor.prusa_filament_weight') | float / 2.16) | round(2)}}
{% elif states.sensor.prusa_connect.attributes["material"] == "FLEX" %}
{{(states('sensor.prusa_filament_weight') | float / 2.91) | round(2)}}
{% elif states.sensor.prusa_connect.attributes["material"] == "---" %}
0
{% else %}
0
{% endif %}
unit_of_measurement: 'm'
icon_template: mdi:ruler
availability_template: '{{ not is_state("sensor.prusa_connect", "unavailable") }}'
prusa_filament_length_imperial:
friendly_name: "Printer Filament Length"
value_template: >-
{% if states.sensor.prusa_connect.attributes["material"] == "PLA" %}
{{(states('sensor.prusa_filament_weight') | float / 2.98 * 3.28084) | round(2)}}
{% elif states.sensor.prusa_connect.attributes["material"] == "PETG" %}
{{(states('sensor.prusa_filament_weight') | float / 3.05 * 3.28084) | round(2)}}
{% elif states.sensor.prusa_connect.attributes["material"] == "ASA" %}
{{(states('sensor.prusa_filament_weight') | float / 2.52 * 3.28084) | round(2)}}
{% elif states.sensor.prusa_connect.attributes["material"] == "PC" %}
{{(states('sensor.prusa_filament_weight') | float / 3.13 * 3.28084) | round(2)}}
{% elif states.sensor.prusa_connect.attributes["material"] == "PVB" %}
{{(states('sensor.prusa_filament_weight') | float / 2.64 * 3.28084) | round(2)}}
{% elif states.sensor.prusa_connect.attributes["material"] == "ABS" %}
{{(states('sensor.prusa_filament_weight') | float / 2.50 * 3.28084) | round(2)}}
{% elif states.sensor.prusa_connect.attributes["material"] == "HIPS" %}
{{(states('sensor.prusa_filament_weight') | float / 2.48 * 3.28084) | round(2)}}
{% elif states.sensor.prusa_connect.attributes["material"] == "PP" %}
{{(states('sensor.prusa_filament_weight') | float / 2.16 * 3.28084) | round(2)}}
{% elif states.sensor.prusa_connect.attributes["material"] == "FLEX" %}
{{(states('sensor.prusa_filament_weight') | float / 2.91 * 3.28084) | round(2)}}
{% elif states.sensor.prusa_connect.attributes["material"] == "---" %}
0
{% else %}
0
{% endif %}
unit_of_measurement: 'ft'
icon_template: mdi:ruler
availability_template: '{{ not is_state("sensor.prusa_connect", "unavailable") }}'