Last active
May 18, 2024 16:56
-
-
Save x86-39/981776fe24601af5a790ba6863b6bffc to your computer and use it in GitHub Desktop.
Home Assistant Klipper (Moonraker) integrations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Replace 192.168.1.1 with your Moonraker IP | |
# I suffix "_ender3" in these, feel free to replace that too | |
sensor: | |
- platform: rest | |
name: klipper_ender3 | |
resource: "http://192.168.1.1:7125/printer/objects/query?heater_bed&extruder&print_stats&toolhead&display_status&virtual_sdcard&gcode_move&webhooks&temperature_sensor mcu_temp&temperature_sensor pi_temp&filament_switch_sensor Filament" | |
json_attributes_path: "$.result.status" | |
json_attributes: | |
- heater_bed | |
- extruder | |
- print_stats | |
- toolhead | |
- display_status | |
- virtual_sdcard | |
- gcode_move | |
- webhooks | |
- temperature_sensor mcu_temp | |
- temperature_sensor pi_temp | |
- "filament_switch_sensor Filament" | |
value_template: >- | |
{{ 'OK' if ('result' in value_json) else None }} | |
force_update: true | |
scan_interval: 1 | |
- platform: rest | |
scan_interval: 5 | |
resource_template: "http://192.168.1.1:7125/server/files/metadata?filename={{ states(('sensor.klipper_ender3_current_print')) }}" | |
name: klipper_ender3_file_metadata | |
json_attributes_path: "$.result" | |
json_attributes: | |
- layer_height | |
- object_height | |
- thumbnails | |
value_template: "OK" | |
# A generic camera entity can use this with the URL `http://192.168.1.1:7125/server/files/gcodes/{{ states.sensor.klipper_ender3_preview_path.attributes["relative_path"] }}` | |
- platform: rest | |
scan_interval: 15 | |
name: klipper_ender3_preview_path | |
resource_template: "http://192.168.1.1:7125/server/files/metadata?filename={{ states(('sensor.klipper_ender3_current_print')) }}" | |
json_attributes_path: "$.result.thumbnails.[1]" # Use the second preview. I configure PrusaSlicer to use "32x32, 900x900", so this preview will be 900x900. | |
json_attributes: | |
- relative_path | |
- width | |
- height | |
- size | |
value_template: "OK" | |
- platform: template | |
sensors: | |
klipper_ender3_state: | |
friendly_name: "Printer State" | |
value_template: >- | |
{{ states.sensor.klipper_ender3.attributes['print_stats']['state'] if states('sensor.klipper_ender3') != 'unknown' else None }} | |
icon_template: > | |
{% set val = states.sensor.klipper_ender3.attributes["print_stats"]["state"] %} | |
{% if val == 'standby' %} | |
mdi:sleep | |
{% elif val == 'error' %} | |
mdi:alert-circle-outline | |
{% elif val == 'printing' %} | |
mdi:printer-3d-nozzle-outline | |
{% elif val == 'paused' %} | |
mdi:pause-circle-outline | |
{% elif val == 'complete' %} | |
mdi:printer-3d | |
{% else %} | |
mdi:help-circle-outline | |
{% endif %} | |
klipper_ender3_current_print: | |
friendly_name: "Current Print" | |
value_template: >- | |
{{ states.sensor.klipper_ender3.attributes['print_stats']['filename'] if states('sensor.klipper_ender3') != 'unknown' else None }} | |
klipper_ender3_current_progress: | |
friendly_name: "Progress" | |
unit_of_measurement: "%" | |
icon_template: mdi:cube-send | |
value_template: >- | |
{{ (states.sensor.klipper_ender3.attributes['display_status']['progress'] * 100) | round(1) if states('sensor.klipper_ender3') != 'unknown' else None }} | |
klipper_ender3_print_time: | |
friendly_name: "Time Elapsed" | |
icon_template: mdi:clock-start | |
value_template: >- | |
{{ states.sensor.klipper_ender3.attributes['print_stats']['print_duration'] | timestamp_custom("%H:%M:%S", 0) if states('sensor.klipper_ender3') != 'unknown' else None }} | |
klipper_ender3_time_remaining: | |
friendly_name: "Time Remaining" | |
icon_template: mdi:clock-end | |
value_template: >- | |
{{ (((states.sensor.klipper_ender3.attributes['print_stats']['print_duration'] / states.sensor.klipper_ender3.attributes['display_status']['progress'] - states.sensor.klipper_ender3.attributes['print_stats']['print_duration']) if states.sensor.klipper_ender3.attributes['display_status']['progress'] > 0 else 0)) | timestamp_custom("%H:%M:%S", 0) if states('sensor.klipper_ender3') != 'unknown' else None }} | |
klipper_ender3_eta: | |
friendly_name: "ETA" | |
icon_template: mdi:clock-outline | |
value_template: >- | |
{{ (as_timestamp(now()) + 2 * 60 * 60 + ((states.sensor.klipper_ender3.attributes['print_stats']['print_duration'] / states.sensor.klipper_ender3.attributes['display_status']['progress'] - states.sensor.klipper_ender3.attributes['print_stats']['print_duration']) if states.sensor.klipper_ender3.attributes['display_status']['progress'] > 0 else 0)) | timestamp_custom("%H:%M:%S", 0) if states('sensor.klipper_ender3') != 'unknown' else None }} | |
klipper_ender3_hotend_temp: | |
icon_template: mdi:thermometer | |
value_template: >- | |
{{ [(states.sensor.klipper_ender3.attributes['extruder']['temperature'] | float | round(1) | string), " / ", (states.sensor.klipper_ender3.attributes['extruder']['target'] | float | round(1) | string)] | join if states('sensor.klipper_ender3') != 'unknown' else None }} | |
klipper_ender3_bed_temp: | |
icon_template: mdi:thermometer | |
value_template: >- | |
{{ [(states.sensor.klipper_ender3.attributes['heater_bed']['temperature'] | float | round(1) | string), " / ", (states.sensor.klipper_ender3.attributes['heater_bed']['target'] | float | round(1) | string)] | join if states('sensor.klipper_ender3') != 'unknown' else None }} | |
klipper_ender3_mcu_pi_temp: | |
icon_template: mdi:thermometer | |
value_template: >- | |
{{ [(states.sensor.klipper_ender3.attributes['temperature_sensor mcu_temp']['temperature'] | float | round(1) | string), " / ", (states.sensor.klipper_ender3.attributes['temperature_sensor pi_temp']['temperature'] | float | round(1) | string)] | join if states('sensor.klipper_ender3') != 'unknown' else None }} | |
klipper_ender3_current_height: | |
friendly_name: "Current Height" | |
value_template: '{{ states.sensor.klipper_ender3.attributes["gcode_move"]["gcode_position"][2] | float | round(2) }}' | |
unit_of_measurement: "mm" | |
icon_template: mdi:arrow-collapse-down | |
klipper_ender3_state_message: | |
friendly_name: "State Message" | |
value_template: '{{ states.sensor.klipper_ender3.attributes["webhooks"]["state_message"] }}' | |
klipper_ender3_height_progress: | |
friendly_name: "Height Progress" | |
value_template: >- | |
{{ [(states.sensor.klipper_ender3.attributes["gcode_move"]["gcode_position"][2] | float | round(2) | string), " / ", (states.sensor.klipper_ender3_file_metadata.attributes["object_height"] | float | string)] | join if states('sensor.klipper_ender3') != 'unknown' else None }} | |
icon_template: mdi:arrow-expand-vertical | |
klipper_ender3_layer_progress: | |
friendly_name: "Layer Progress" | |
value_template: >- | |
{{ [(states("sensor.klipper_ender3_current_height")|float / states("sensor.3d_printer_layer_height")|float)|round(0), " / ", (states("sensor.3d_printer_object_height")|float / states("sensor.3d_printer_layer_height")|float)|round(0)] | join if states('sensor.klipper_ender3') != 'unknown' else None }} | |
icon_template: mdi:layers-triple-outline | |
klipper_ender3_printer_layer_height: | |
friendly_name: "Layer Height" | |
value_template: '{{ states.sensor.klipper_ender3_file_metadata.attributes["layer_height"] | float }}' | |
unit_of_measurement: "mm" | |
icon_template: mdi:arrow-collapse-vertical | |
klipper_ender3_object_height: | |
friendly_name: "Object Height" | |
value_template: '{{ states.sensor.klipper_ender3_file_metadata.attributes["object_height"] | float }}' | |
unit_of_measurement: "mm" | |
icon_template: mdi:arrow-expand-vertical | |
klipper_ender3_current_layer: | |
friendly_name: "Current Layer" | |
value_template: '{{ (states("sensor.3d_printer_current_height")|float / states("sensor.3d_printer_layer_height")|float)|round(0) }}' | |
klipper_ender3_total_layers: | |
friendly_name: "Total Layers" | |
value_template: '{{ (states("sensor.3d_printer_object_height")|float / states("sensor.3d_printer_layer_height")|float)|round(0) }}' | |
rest_command: | |
klipper_ender3_emergency_stop: | |
url: "http://192.168.1.1:7125/printer/emergency_stop" | |
method: post | |
klipper_ender3_firmware_restart: | |
url: "http://192.168.1.1:7125/printer/firmware_restart" | |
method: post | |
klipper_ender3_cancel: | |
url: "http://192.168.1.1:7125/printer/print/cancel" | |
method: post | |
klipper_ender3_pause: | |
url: "http://192.168.1.1:7125/printer/print/pause" | |
method: post | |
klipper_ender3_resume: | |
url: "http://192.168.1.1:7125/printer/print/resume" | |
method: post |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment