74 lines
2.8 KiB
YAML
74 lines
2.8 KiB
YAML
|
|
# ------------------------------------------------------------
|
||
|
|
# BAMBU: PrintsCharming (P1S)
|
||
|
|
# ------------------------------------------------------------
|
||
|
|
- alias: "Print Log - PrintsCharming - Start"
|
||
|
|
id: print_log_printcharming_start
|
||
|
|
description: "Creates Notion entry when PrintsCharming begins printing"
|
||
|
|
mode: single
|
||
|
|
trigger:
|
||
|
|
- platform: state
|
||
|
|
entity_id: sensor.p1s_01p09c470102673_print_status
|
||
|
|
to: "running"
|
||
|
|
condition:
|
||
|
|
- condition: template
|
||
|
|
value_template: "{{ trigger.from_state.state != 'running' }}"
|
||
|
|
- condition: template
|
||
|
|
value_template: "{{ states('input_text.notion_page_id_printcharming') | length < 10 }}"
|
||
|
|
action:
|
||
|
|
- delay: "00:00:05"
|
||
|
|
- action: rest_command.notion_create_print
|
||
|
|
data:
|
||
|
|
file_name: "{{ states('sensor.p1s_01p09c470102673_gcode_filename') }}"
|
||
|
|
printer_name: "PrintsCharming"
|
||
|
|
filament_type: "{{ state_attr('sensor.p1s_01p09c470102673_active_tray', 'type') | default('Unknown') }}"
|
||
|
|
filament_color: "{{ state_attr('sensor.p1s_01p09c470102673_active_tray', 'color') | default('Unknown') }}"
|
||
|
|
started: "{{ now().strftime('%Y-%m-%dT%H:%M:%S') }}"
|
||
|
|
response_variable: notion_response
|
||
|
|
- action: input_text.set_value
|
||
|
|
target:
|
||
|
|
entity_id: input_text.notion_page_id_printcharming
|
||
|
|
data:
|
||
|
|
value: "{{ notion_response.content.id | default('') }}"
|
||
|
|
|
||
|
|
- alias: "Print Log - PrintsCharming - Finish"
|
||
|
|
id: print_log_printcharming_finish
|
||
|
|
description: "Updates Notion entry when PrintsCharming finishes, fails, or is cancelled"
|
||
|
|
mode: single
|
||
|
|
trigger:
|
||
|
|
- platform: state
|
||
|
|
entity_id: sensor.p1s_01p09c470102673_print_status
|
||
|
|
to: "finish"
|
||
|
|
id: completed
|
||
|
|
- platform: state
|
||
|
|
entity_id: sensor.p1s_01p09c470102673_print_status
|
||
|
|
to: "failed"
|
||
|
|
id: failed
|
||
|
|
- platform: state
|
||
|
|
entity_id: sensor.p1s_01p09c470102673_print_status
|
||
|
|
to: "cancelled"
|
||
|
|
id: cancelled
|
||
|
|
condition:
|
||
|
|
- condition: template
|
||
|
|
value_template: "{{ states('input_text.notion_page_id_printcharming') | length > 10 }}"
|
||
|
|
action:
|
||
|
|
- delay: "00:00:05"
|
||
|
|
- variables:
|
||
|
|
page_id: "{{ states('input_text.notion_page_id_printcharming') }}"
|
||
|
|
- condition: template
|
||
|
|
value_template: "{{ page_id | length > 10 }}"
|
||
|
|
- action: rest_command.notion_update_print
|
||
|
|
data:
|
||
|
|
page_id: "{{ page_id }}"
|
||
|
|
status: >
|
||
|
|
{% if trigger.id == 'completed' %}Completed
|
||
|
|
{% elif trigger.id == 'failed' %}Failed
|
||
|
|
{% else %}Cancelled{% endif %}
|
||
|
|
weight: "{{ states('sensor.p1s_01p09c470102673_print_weight') | float(0) }}"
|
||
|
|
length: "{{ states('sensor.p1s_01p09c470102673_print_length') | float(0) }}"
|
||
|
|
completed: "{{ now().strftime('%Y-%m-%dT%H:%M:%S') }}"
|
||
|
|
- action: input_text.set_value
|
||
|
|
target:
|
||
|
|
entity_id: input_text.notion_page_id_printcharming
|
||
|
|
data:
|
||
|
|
value: ""
|