91 lines
15 KiB
JSON
91 lines
15 KiB
JSON
[
|
|
{
|
|
"id": "'3D Printer - Active Tray Changed: Update Spoolman Last Used'",
|
|
"automation": "- alias: '3D Printer - Active Tray Changed: Update Spoolman Last Used'\n description: Trigger whenever the printer's Active Tray is updated and currently\n printing - so that it can update Last Used date/time in Spoolman for the corresponding\n Spool\n triggers:\n - trigger: state\n entity_id:\n - sensor.ntk_ryansoffice_3dprinter_active_tray\n - trigger: state\n entity_id:\n - sensor.ntk_ryansoffice_3dprinter_current_stage\n to: printing\n conditions:\n - condition: and\n conditions:\n - condition: state\n entity_id: sensor.ntk_ryansoffice_3dprinter_current_stage\n state: printing\n - condition: not\n conditions:\n - condition: state\n entity_id: sensor.ntk_ryansoffice_3dprinter_active_tray\n state: unavailable\n alias: Active Tray is NOT Unavailable\n - condition: not\n conditions:\n - condition: state\n entity_id: sensor.ntk_ryansoffice_3dprinter_active_tray\n state: unknown\n alias: Active Tray is NOT Unknown\n actions:\n - action: persistent_notification.create\n data:\n title: debug active tray info\n message: uuid is {{ active_tray.uuid }}, color is {{ active_tray.color }}, remaining\n is {{ active_tray.remain }}\n enabled: false\n - variables:\n active_tray:\n uuid: '{{ state_attr(''sensor.ntk_ryansoffice_3dprinter_active_tray'', ''tray_uuid'')\n }}'\n type: '{{ state_attr(''sensor.ntk_ryansoffice_3dprinter_active_tray'', ''type'')\n }}'\n color: '{{ state_attr(''sensor.ntk_ryansoffice_3dprinter_active_tray'', ''color'')\n | replace(''#'', '''') }}'\n name: '{{ state_attr(''sensor.ntk_ryansoffice_3dprinter_active_tray'', ''name'')\n }}'\n remain: '{{ state_attr(''sensor.ntk_ryansoffice_3dprinter_active_tray'', ''remain'')\n }}'\n - action: script.find_matching_spool_in_spoolman\n metadata: {}\n data:\n parameters:\n target_color_hex: '{{ active_tray.color }}'\n target_type: '{{ active_tray.type }}'\n target_uuid: '{{ active_tray.uuid }}'\n remaining_enabled: false\n remaining_percent: '{{ active_tray.remain }}'\n tray_weight: 1000\n target_name: '{{ active_tray.name }}'\n response_variable: find_spool_response\n - alias: Take action if Spool was found (or error if not)\n choose:\n - conditions:\n - alias: Spool Found (response from script)\n condition: template\n value_template: '{{ find_spool_response.success == true }}'\n sequence:\n - alias: Loop through Spools (from Spoolman)\n repeat:\n for_each: '{{ spools.content }}'\n sequence:\n - action: persistent_notification.create\n metadata: {}\n data:\n title: Test Spool Notification\n message: 'ID: {{ repeat.item.id }} Location: {{ repeat.item.location\n }} Filament Name: {{ repeat.item.filament.name }} UUID: {{ repeat.item.extra.spool_uuid\n | replace(''\"'', '''') }}\n\n '\n enabled: false\n - condition: template\n value_template: \"{{ repeat.item.extra.spool_uuid | replace('\\\"', '') ==\\\n \\ active_tray.uuid }}\\n \"\n alias: Test if Active Tray UUID matches the Spool UUID from Spoolman\n - sequence:\n - variables:\n found_spool: true\n alias: Set Variable to Spool Found = True\n - action: persistent_notification.create\n metadata: {}\n data:\n title: Found Spool\n message: Found spool - it is number {{ repeat.item.id }} first_used {{\n repeat.item.first_used if 'first_used' in repeat.item else now().isoformat()\n }}\n - action: spoolman.patch_spool\n metadata: {}\n data:\n id: '{{ repeat.item.id }}'\n last_used: '{{ now().isoformat() }}'\n first_used: '{{ repeat.item.first_used if ''first_used'' in repeat.item\n else now().isoformat() }}\n\n '\n alias: Update Spoolman Last Used (and First Used if empty)\n enabled: false\n - action: script.update_spool_last_and_first_used\n metadata: {}\n data:\n spool: '{{ find_spool_response.spool }}'\n - alias: Update Spoolman UUID if needed (and valid)\n if:\n - alias: If Tray UUID defined, not blank of 00000 and found spool UUID isn't\n populated and found spool is from Bambu Lab\n condition: template\n value_template: '{{ active_tray.uuid is not none and active_tray.uuid |\n length > 0 and active_tray.uuid | regex_match(''^0+$'') == false and find_spool_response.spool.extra.spool_uuid\n | string | trim(''\"'') | length == 0 and find_spool_response.spool.filament.vendor.name\n == ''Bambu Lab'' }}'\n then:\n - action: spoolman.patch_spool\n metadata: {}\n data:\n id: '{{ find_spool_response.spool.id }}'\n extra:\n spool_uuid: '{{ active_tray.uuid }}'\n alias: Update UUID in Spoolman for matched Spool\n - conditions:\n - alias: No single matching spool found\n condition: template\n value_template: '{{ find_spool_response.success == false }}'\n sequence:\n - action: persistent_notification.create\n metadata: {}\n data:\n title: 'Spoolman Update Error: Cannot Find Spool'\n message: 'Cannot update Spoolman with last used spool information due to\n issue finding the correct spool. Error message: \"{{ find_spool_response.Message\n }}\"'\n - variables:\n needUUIDUpdate: '{{ active_tray.uuid is not none and active_tray.uuid | length\n > 0 and active_tray.uuid | regex_match(''^0+$'') == false and find_spool_response.spool.tray_uuid\n | length == 0 and find_spool_response.spool.filament.vendor.name == ''Bambu\n Lab'' }}'\n activeTrayNotNone: '{{ active_tray.uuid is not none }}'\n activeTrayUuidLengthBiggerThanZero: '{{ active_tray.uuid | length > 0 }}'\n uuidNotZeros: '{{ active_tray.uuid | regex_match(''^0+$'') == false }}'\n spoolHasNoUUID: '{{ find_spool_response.spool.tray_uuid | length == 0 }}'\n spoolHasNoUUIDv2: '{{ find_spool_response.spool.extra.spool_uuid | length ==\n 0 }}'\n isBambuLab: '{{ find_spool_response.spool.filament.vendor.name == ''Bambu Lab'' }}'\n enabled: false\n mode: single",
|
|
"config": [
|
|
{
|
|
"name": "3d printer active tray",
|
|
"room": "office",
|
|
"type": "sensor",
|
|
"id": {
|
|
"entity_id": "sensor.ntk_ryansoffice_3dprinter_active_tray",
|
|
"device_id": null
|
|
}
|
|
},
|
|
{
|
|
"name": "3d printer current stage",
|
|
"room": "office",
|
|
"type": "sensor",
|
|
"id": {
|
|
"entity_id": "sensor.ntk_ryansoffice_3dprinter_current_stage",
|
|
"device_id": null
|
|
}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"id": "Print Complete - Update Filament Usage",
|
|
"automation": "- alias: Print Complete - Update Filament Usage\n description: ''\n triggers:\n - device_id: 210dfdfa64085e8cf073e50eae757d90\n domain: bambu_lab\n type: event_print_finished\n trigger: device\n conditions: []\n actions:\n - action: persistent_notification.create\n metadata: {}\n data:\n message: Print Finished\n enabled: false\n - variables:\n store_print_weight: '{{ states(''sensor.ntk_ryansoffice_3dprinter_print_weight'')\n }}'\n - variables:\n attributes: '{{ states.sensor.ntk_ryansoffice_3dprinter_print_weight.attributes.items()\n }}'\n - repeat:\n sequence:\n - variables:\n key: '{{ repeat.item[0] }}'\n value: '{{ repeat.item[1] }}'\n - if:\n - condition: template\n value_template: '\"{{ ''AMS'' in key }}\"'\n then:\n - action: logbook.log\n metadata: {}\n data:\n name: AMS Attribute Logger\n message: '{{ key }}: {{ value }}'\n for_each: '{{ attributes }}'\n enabled: false\n - repeat:\n count: '{{ states.sensor.ntk_ryansoffice_3dprinter_print_weight.attributes |\n length }}'\n sequence:\n - action: logbook.log\n metadata: {}\n data:\n name: index\n message: '{{ repeat.index }}'\n - variables:\n att: '{{ states.sensor.ntk_ryansoffice_3dprinter_print_weight.attributes[repeat.index]\n }}'\n enabled: false\n - variables:\n ams_trays_string: \"{% for key, value in states.sensor.ntk_ryansoffice_3dprinter_print_weight.attributes.items()\\\n \\ %}\\n {% if key.startswith('AMS') %}\\n {{ key }}:{{ value }}, \\n {%\\\n \\ endif %}\\n{% endfor %}\\n\"\n ams_tray_list: '{{ ams_trays_string.rstrip('','').split('','') | list }}\n\n '\n - repeat:\n sequence:\n - variables:\n tray_name: '{{ repeat.item.split('':'')[0] }}'\n tray_print_weight: '{{ repeat.item.split('':'')[1] | int }}'\n tray_number: '{{ tray_name.split('' '')[3] }}'\n tray_entity_id: sensor.p1s_01p00c460102350_ams_1_tray_{{ tray_number }}\n - choose:\n - conditions:\n - condition: template\n value_template: '{{ tray == 1 }}'\n sequence:\n - variables:\n tray_entity: sensor.p1s_01p00c460102350_ams_1_tray_1\n - conditions:\n - condition: template\n value_template: '{{ tray == 2 }}'\n sequence:\n - variables:\n tray_entity: sensor.p1s_01p00c460102350_ams_1_tray_2\n - conditions:\n - condition: template\n value_template: '{{ tray == 4 }}'\n sequence:\n - variables:\n tray_entity: sensor.p1s_01p00c460102350_ams_1_tray_4\n enabled: false\n - variables:\n selected_tray:\n uuid: '{{ state_attr(tray_entity_id, ''tray_uuid'') }}'\n type: '{{ state_attr(tray_entity_id, ''type'') }}'\n color: '{{ state_attr(tray_entity_id, ''color'') | replace(''#'', '''') }}'\n - action: script.find_matching_spool_in_spoolman\n metadata: {}\n data:\n parameters:\n target_color_hex: '{{ selected_tray.color }}'\n target_type: '{{ selected_tray.type }}'\n target_uuid: '{{ selected_tray.uuid }}'\n response_variable: find_spool_response\n - alias: Take action if Spool was found (or error if not)\n choose:\n - conditions:\n - condition: template\n value_template: '{{ find_spool_response.success == true }}'\n alias: Spool found (response from script)\n sequence:\n - action: spoolman.use_spool_filament\n metadata: {}\n data:\n id: '{{ find_spool_response.spool.id }}'\n use_weight: '{{ tray_print_weight }}'\n - action: logbook.log\n metadata: {}\n data:\n name: Spoolman {{ tray_name }}\n message: Print Job complete - {{ states('sensor.ntk_ryansoffice_3dprinter_task_name')\n }} Updated Filament Usage for {{ tray_name }}. Spool ID {{ find_spool_response.spool.id\n }} ({{ find_spool_response.spool.filament.name }}). Used {{ tray_print_weight\n }} grams.\n alias: Log the Filament Usage\n - action: persistent_notification.create\n metadata: {}\n data:\n title: Print Job {{ states('sensor.ntk_ryansoffice_3dprinter_task_name')\n }} Finished\n message: 'Print Job complete - **{{ states(''sensor.ntk_ryansoffice_3dprinter_task_name'')\n }}**\n\n\n Updated Filament Usage for {{ tray_name }}. Spool ID {{ find_spool_response.spool.id\n }} ({{ find_spool_response.spool.filament.name }}).\n\n\n Used {{ tray_print_weight }} grams.'\n - conditions:\n - condition: not\n conditions:\n - condition: template\n value_template: '{{ find_spool_response.success == false }}'\n alias: Spool not found - error (cannot update usage)\n alias: Spool not found - error (cannot update usage)\n sequence:\n - action: persistent_notification.create\n metadata: {}\n data:\n title: 'Spoolman Update Error: Cannot Find Spool'\n message: 'Cannot update Spoolman with print weight usage information\n due to issue finding the correct spool. Error message: \"{{ find_spool_response.Message\n }}\"'\n alias: Active Tray UUID is NOT empty (eg Bambu Spool)\n for_each: '{{ ams_tray_list }}'\n mode: single",
|
|
"config": [
|
|
{
|
|
"name": "3d printer print weight",
|
|
"room": "office",
|
|
"type": "sensor",
|
|
"id": {
|
|
"entity_id": "sensor.ntk_ryansoffice_3dprinter_print_weight",
|
|
"device_id": null
|
|
}
|
|
},
|
|
{
|
|
"name": "3d printer task name",
|
|
"room": "office",
|
|
"type": "sensor",
|
|
"id": {
|
|
"entity_id": "sensor.ntk_ryansoffice_3dprinter_task_name",
|
|
"device_id": null
|
|
}
|
|
},
|
|
{
|
|
"name": "ams 1 tray 1",
|
|
"room": "office",
|
|
"type": "sensor",
|
|
"id": {
|
|
"entity_id": "sensor.p1s_01p00c460102350_ams_1_tray_1",
|
|
"device_id": null
|
|
}
|
|
},
|
|
{
|
|
"name": "ams 1 tray 2",
|
|
"room": "office",
|
|
"type": "sensor",
|
|
"id": {
|
|
"entity_id": "sensor.p1s_01p00c460102350_ams_1_tray_2",
|
|
"device_id": null
|
|
}
|
|
},
|
|
{
|
|
"name": "ams 1 tray 4",
|
|
"room": "office",
|
|
"type": "sensor",
|
|
"id": {
|
|
"entity_id": "sensor.p1s_01p00c460102350_ams_1_tray_4",
|
|
"device_id": null
|
|
}
|
|
},
|
|
{
|
|
"name": "3d printer device",
|
|
"room": "office",
|
|
"type": "bambu_lab",
|
|
"id": {
|
|
"entity_id": null,
|
|
"device_id": "210dfdfa64085e8cf073e50eae757d90"
|
|
}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"id": "Reload Spoolman Integration - Daily @11pm",
|
|
"automation": "- alias: Reload Spoolman Integration - Daily @11pm\n description: Each night forces a reload of the Spoolman integration. This seems\n to be required for new spools to be registered in Home Assistant.\n triggers:\n - trigger: time\n at: '23:00:00'\n conditions: []\n actions:\n - action: homeassistant.reload_config_entry\n metadata: {}\n data:\n entry_id: 01JPNH7WNWR5TMZ8YSNDHXWR38\n mode: single",
|
|
"config": []
|
|
}
|
|
] |