-
Notifications
You must be signed in to change notification settings - Fork 0
/
moonraker.yaml
214 lines (207 loc) · 9.52 KB
/
moonraker.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# https://github.com/denkyem/home-assistant-moonraker/blob/main/moonraker.yaml
# https://github.com/thehiddentruth/home-assistant-moonraker/blob/main/moonraker.yaml
# Get current job data
rest:
scan_interval: 5
resource_template: "http://<moonraker-ip>:7125/server/files/metadata?filename={{ states(('sensor.3d_printer_current_print')) }}"
sensor:
- name: printer_3d_file_metadata
json_attributes_path: "$.result"
json_attributes:
- layer_height
- object_height
- thumbnails
value_template: "OK"
# Get thumbnail from server (works with subdirectories)
camera:
- platform: generic
name: 3d_printer_thumbernail
still_image_url: http://<moonraker-ip>/server/files/gcodes/{{ states(('sensor.3d_printer_current_print')) | regex_findall_index('(.*/)*') }}{{ states('sensor.3d_printer_object_thumbnails') }}
verify_ssl: false
# Actions
rest_command:
3d_printer_emergency_stop:
url: "http://<moonraker-ip>:7125/printer/emergency_stop"
method: post
3d_printer_firmware_restart:
url: "http://<moonraker-ip>:7125/printer/firmware_restart"
method: post
3d_printer_cancel:
url: "http://<moonraker-ip>:7125/printer/print/cancel"
method: post
3d_printer_pause:
url: "http://<moonraker-ip>:7125/printer/print/pause"
method: post
3d_printer_resume:
url: "http://<moonraker-ip>:7125/printer/print/resume"
method: post
sensor:
# Basic printer sensor info
- platform: rest
name: printer_3d_sensor
resource: "http://<moonraker-ip>:7125/printer/objects/query?heater_bed&extruder&print_stats&toolhead&display_status&virtual_sdcard&gcode_move&filament_switch_sensor Filament"
json_attributes_path: "$.result.status"
json_attributes:
- heater_bed
- extruder
- print_stats
- toolhead
- display_status
- virtual_sdcard
- gcode_move
- "filament_switch_sensor Filament"
value_template: >-
{{ 'OK' if ('result' in value_json) else None }}
force_update: true
scan_interval: 1
# Adding an API key is only necessary while using the [authorization] component
# and if Home Assistant is not a trusted client
#headers:
# x-api-key: 123456789abcdefghijklmno
# Basic printer info
- platform: rest
name: printer_3d_info
scan_interval: 1
resource_template: http://<moonraker-ip>:7125/printer/info
json_attributes_path: "$.result"
json_attributes:
- state_message
- state
- software_version
- hostname
- cpu_info
value_template: >-
{{ 'OK' if ('result' in value_json) else None }}
# Build sensors for requested data
- platform: template
sensors:
3d_printer_hotend_target:
friendly_name: "Hotend Target"
value_template: '{{ states.sensor.printer_3d_sensor.attributes["extruder"]["target"] | float | round(1) }}'
device_class: temperature
unit_of_measurement: "°C"
icon_template: mdi:thermometer
3d_printer_hotend_actual:
friendly_name: "Hotend Actual"
value_template: '{{ states.sensor.printer_3d_sensor.attributes["extruder"]["temperature"] | float | round(1) }}'
device_class: temperature
unit_of_measurement: "°C"
icon_template: mdi:thermometer
3d_printer_hotend_power:
friendly_name: "Hotend Power"
value_template: '{{ ((states.sensor.printer_3d_sensor.attributes["extruder"]["power"] | float) * 100) | round(0) }}'
device_class: temperature
unit_of_measurement: "%"
icon_template: mdi:flash
3d_printer_bed_target:
friendly_name: "Bed Target"
value_template: '{{ states.sensor.printer_3d_sensor.attributes["heater_bed"]["target"] | float | round(1) }}'
device_class: temperature
unit_of_measurement: "°C"
icon_template: mdi:thermometer
3d_printer_bed_actual:
friendly_name: "Bed Actual"
value_template: '{{ states.sensor.printer_3d_sensor.attributes["heater_bed"]["temperature"] | float | round(1) }}'
device_class: temperature
unit_of_measurement: "°C"
icon_template: mdi:thermometer
3d_printer_bed_power:
friendly_name: "Bed Power"
value_template: '{{ ((states.sensor.printer_3d_sensor.attributes["heater_bed"]["power"] | float) * 100) | round(0) }}'
device_class: temperature
unit_of_measurement: "%"
icon_template: mdi:flash
3d_printer_state:
friendly_name: "Printer State"
value_template: '{{ states.sensor.printer_3d_sensor.attributes["print_stats"]["state"] }}'
icon_template: >-
{% set val = states.sensor.printer_3d_sensor.attributes["print_stats"]["state"] %}
{% if val == 'standby' %}
mdi:sleep
{% elif val == 'error' %}
mdi:alert-circle
{% elif val == 'printing' %}
mdi:printer-3d-nozzle
{% elif val == 'paused' %}
mdi:pause-circle
{% elif val == 'complete' %}
mdi:printer-3d
{% else %}
mdi:help-circle
{% endif %}
3d_printer_current_print:
friendly_name: "Current Print"
value_template: '{{ states.sensor.printer_3d_sensor.attributes["print_stats"]["filename"]}}'
3d_printer_current_progress:
friendly_name: "Progress"
value_template: '{{ ((states.sensor.printer_3d_sensor.attributes["display_status"]["progress"])*100) | round(0, "floor") }}'
unit_of_measurement: "%"
icon_template: mdi:progress-clock
3d_printer_print_time:
friendly_name: "Time Elapsed"
value_template: '{{ states.sensor.printer_3d_sensor.attributes["print_stats"]["print_duration"] |timestamp_custom("%H:%M:%S", 0)}}'
icon_template: mdi:camera-timer
3d_printer_time_remaining:
friendly_name: "Time Remaining"
value_template: '{{ (((states.sensor.printer_3d_sensor.attributes["print_stats"]["print_duration"]/states.sensor.printer_3d_sensor.attributes["display_status"]["progress"]- states.sensor.printer_3d_sensor.attributes["print_stats"]["print_duration"]) if states.sensor.printer_3d_sensor.attributes["display_status"]["progress"]>0 else 0)) | timestamp_custom("%H:%M:%S", 0)}}'
icon_template: mdi:timer-sand
3d_printer_eta:
friendly_name: "ETA"
value_template:
'{%- if states.sensor.printer_3d_sensor.attributes["display_status"]["progress"] > 0 and states.sensor.printer_3d_sensor.attributes["display_status"]["progress"] < 1 -%}
{{ (as_timestamp(now())+1*60*60+ ((states.sensor.printer_3d_sensor.attributes["print_stats"]["print_duration"]/states.sensor.printer_3d_sensor.attributes["display_status"]["progress"]-states.sensor.printer_3d_sensor.attributes["print_stats"]["print_duration"]))) | timestamp_custom("%H:%M:%S", 0)}}
{%- else -%}
{{ 0 | timestamp_custom("%H:%M:%S", 0) }}
{%- endif -%}'
icon_template: mdi:av-timer
3d_printer_message:
friendly_name: "Message"
value_template: '{{ states.sensor.printer_3d_sensor.attributes["display_status"]["message"]}}'
3d_printer_layer_height:
friendly_name: "Layer Height"
value_template: '{{ states.sensor.printer_3d_file_metadata.attributes["layer_height"] | float }}'
unit_of_measurement: "mm"
icon_template: mdi:arrow-collapse-down
3d_printer_object_height:
friendly_name: "Object Height"
value_template: '{{ (states.sensor.printer_3d_file_metadata.attributes["object_height"] | float) - (states.sensor.printer_3d_file_metadata.attributes["layer_height"] | float) }}'
unit_of_measurement: "mm"
icon_template: mdi:arrow-expand-vertical
3d_printer_current_height:
friendly_name: "Current Height"
value_template: '{{ states.sensor.printer_3d_sensor.attributes["gcode_move"]["gcode_position"][2] | float | round(2) }}'
unit_of_measurement: "mm"
icon_template: mdi:arrow-collapse-down
3d_printer_current_layer:
friendly_name: "Current Layer"
value_template: '{{ (states("sensor.3d_printer_current_height")|float / states("sensor.3d_printer_layer_height")|float)|round(0) }}'
3d_printer_total_layers:
friendly_name: "Total Layers"
value_template: '{{ (states("sensor.3d_printer_object_height")|float / states("sensor.3d_printer_layer_height")|float)|round(0) }}'
3d_printer_object_thumbnails:
friendly_name: "Object Thumbnails"
# Get largest thumbnail
value_template: >-
{%- set thumbs = states.sensor.printer_3d_file_metadata.attributes["thumbnails"] -%}
{%- set ns = namespace(heighest = thumbs[0]) -%}
{%- for t in thumbs -%}
{%- if t.width > ns.heighest.width -%}
{% set ns.heighest = t %}
{%- endif -%}
{%- endfor -%}{{ ns.heighest["relative_path"] }}
icon_template: mdi:image
3d_printer_state_message:
friendly_name: "State Message"
value_template: '{{ states.sensor.printer_3d_info.attributes["state_message"] }}'
3d_printer_heaters_power:
friendly_name: "Bed and Nozzle Power"
value_template: '{{ states("sensor.3d_printer_bed_power") }}% / {{ states("sensor.3d_printer_hotend_power") }}%'
binary_sensor:
- platform: template
sensors:
3d_printer_filament:
friendly_name: "Filament Detected"
icon_template: mdi:printer-3d-nozzle-alert
device_class: motion
value_template: >-
{{ states.sensor.printer_3d_sensor.attributes["filament_switch_sensor Filament"]["filament_detected"] }}