5 files
This commit is contained in:
+141
@@ -0,0 +1,141 @@
|
||||
# ha_mcp_backup
|
||||
schema_version: 1
|
||||
domain: automation
|
||||
entity_id: automation.sparkx_i7_deduct_filament_in_spoolman_on_print_complete
|
||||
captured: '2026-10-11T03:52:39.789581+00:00'
|
||||
tool: ha_config_set_automation
|
||||
config:
|
||||
id: '1791477238729'
|
||||
alias: SparkX i7 - Deduct filament in Spoolman on print complete
|
||||
description: On print completion, deducts the final segment (used_material_length
|
||||
delta since last checkpoint x g/cm) from the Spoolman spool in the CFS Lite location
|
||||
matching the latched slot color (remaining weight > 0 guard), accumulates it per
|
||||
slot, then sends a summary notification with total and per-slot breakdown whenever
|
||||
anything was deducted. Silent when total is 0. Clears the latch and re-baselines
|
||||
the checkpoint.
|
||||
triggers:
|
||||
- trigger: state
|
||||
entity_id: sensor.sparkx_i7_print_status
|
||||
from: printing
|
||||
to: completed
|
||||
conditions: []
|
||||
actions:
|
||||
- variables:
|
||||
old_slot: '{{ states(''input_text.sparkx_i7_print_spool_latch'') }}'
|
||||
cur: '{{ states(''sensor.sparkx_i7_used_material_length'') | float(0) }}'
|
||||
checkpoint: '{{ states(''input_number.sparkx_i7_spoolman_length_checkpoint'')
|
||||
| float(0) }}'
|
||||
- variables:
|
||||
final_grams: '{{ (([cur | float - (checkpoint | float), 0] | max) * (states(''input_number.sparkx_i7_filament_g_cm'')
|
||||
| float(0.03))) | round(2) }}'
|
||||
color: '{{ states(''sensor.sparkx_i7_cfs_'' ~ (old_slot | lower | replace(''
|
||||
'', ''_'')) ~ ''_color'') | replace(''#'', '''') | lower }}'
|
||||
- variables:
|
||||
spool_id: '{% set ns = namespace(id='''') %}{% for e in integration_entities(''spoolman'')
|
||||
%}{% if e.endswith(''_color_hex'') and (states(e) | replace(''#'', '''') |
|
||||
lower) == color and (state_attr(e[:-10], ''location'') | default('''', true)
|
||||
| lower) == ''cfs lite'' %}{% set b = e[:-10] %}{% if (states(b) | float(0))
|
||||
> 0 and ns.id == '''' %}{% set ns.id = states(b ~ ''_id'') %}{% endif %}{%
|
||||
endif %}{% endfor %}{{ ns.id }}'
|
||||
- variables:
|
||||
helper_idx: '{{ old_slot.split('' '')[-1] if old_slot.split('' '')[-1] in [''1'',
|
||||
''2'', ''3'', ''4''] else '''' }}'
|
||||
- variables:
|
||||
nonhelper_g: '{{ final_grams if (final_grams | float > 0) and (spool_id not
|
||||
in ['''', ''unknown'', ''unavailable'']) and (helper_idx == '''') else 0 }}'
|
||||
- if:
|
||||
condition: template
|
||||
value_template: '{{ final_grams | float > 0 }}'
|
||||
then:
|
||||
- choose:
|
||||
- conditions:
|
||||
condition: template
|
||||
value_template: '{{ spool_id not in ['''', ''unknown'', ''unavailable'']
|
||||
}}'
|
||||
sequence:
|
||||
- action: spoolman.use_spool_filament
|
||||
data:
|
||||
id: '{{ spool_id | int(0) }}'
|
||||
use_weight: '{{ final_grams | float(0) }}'
|
||||
- if:
|
||||
condition: template
|
||||
value_template: '{{ helper_idx != '''' }}'
|
||||
then:
|
||||
- action: input_number.set_value
|
||||
target:
|
||||
entity_id: input_number.sparkx_i7_slot_{{ helper_idx }}_grams
|
||||
data:
|
||||
value: '{{ (states(''input_number.sparkx_i7_slot_'' ~ helper_idx ~ ''_grams'')
|
||||
| float(0)) + (final_grams | float) }}'
|
||||
default:
|
||||
- action: notify.persistent_notification
|
||||
data:
|
||||
title: 'Spoolman: no spool for slot color'
|
||||
message: 'Print completed: final segment of {{ final_grams }} g from {{
|
||||
old_slot if old_slot else ''the active slot'' }} (color #{{ color | upper
|
||||
}}) could not be deducted - no Spoolman spool in the CFS Lite location
|
||||
with remaining weight matches that color. Register the new roll in Spoolman
|
||||
with location CFS Lite, then adjust manually if needed.'
|
||||
- action: notify.mobile_app_francos_ipad
|
||||
data:
|
||||
title: 'Spoolman: no spool for slot color'
|
||||
message: 'Print completed: final segment of {{ final_grams }} g from {{
|
||||
old_slot if old_slot else ''the active slot'' }} (color #{{ color | upper
|
||||
}}) could not be deducted - no Spoolman spool in the CFS Lite location
|
||||
with remaining weight matches that color. Register the new roll in Spoolman
|
||||
with location CFS Lite, then adjust manually if needed.'
|
||||
- action: notify.mobile_app_sm_f956w
|
||||
data:
|
||||
title: 'Spoolman: no spool for slot color'
|
||||
message: 'Print completed: final segment of {{ final_grams }} g from {{
|
||||
old_slot if old_slot else ''the active slot'' }} (color #{{ color | upper
|
||||
}}) could not be deducted - no Spoolman spool in the CFS Lite location
|
||||
with remaining weight matches that color. Register the new roll in Spoolman
|
||||
with location CFS Lite, then adjust manually if needed.'
|
||||
- variables:
|
||||
summary_total: '{% set ns = namespace(t = 0) %}{% for n in [''1'', ''2'', ''3'',
|
||||
''4''] %}{% set g = states(''input_number.sparkx_i7_slot_'' ~ n ~ ''_grams'')
|
||||
| float(0) %}{% if g > 0 %}{% set ns.t = ns.t + g %}{% endif %}{% endfor %}{{
|
||||
(ns.t + (nonhelper_g | float)) | round(1) }}'
|
||||
- variables:
|
||||
summary_lines: '{% set ns = namespace(l = []) %}{% for n in [''1'', ''2'', ''3'',
|
||||
''4''] %}{% set g = states(''input_number.sparkx_i7_slot_'' ~ n ~ ''_grams'')
|
||||
| float(0) %}{% if g > 0 %}{% set ns.l = ns.l + [''Slot '' ~ n ~ '' ('' ~
|
||||
states(''sensor.sparkx_i7_slot_'' ~ n ~ ''_color_name'') ~ ''): '' ~ (g |
|
||||
round(1)) ~ '' g''] %}{% endif %}{% endfor %}{% if nonhelper_g | float > 0
|
||||
%}{% set ns.l = ns.l + [(old_slot if old_slot else ''Unlatched'') ~ '': ''
|
||||
~ (nonhelper_g | float | round(1)) ~ '' g''] %}{% endif %}{{ ns.l | join(''\n'')
|
||||
}}'
|
||||
- if:
|
||||
condition: template
|
||||
value_template: '{{ summary_total | float > 0 }}'
|
||||
then:
|
||||
- action: notify.persistent_notification
|
||||
data:
|
||||
title: Print complete - Spoolman updated
|
||||
message: 'Print complete - Spoolman deducted {{ summary_total }} g
|
||||
|
||||
{{ summary_lines }}'
|
||||
- action: notify.mobile_app_francos_ipad
|
||||
data:
|
||||
title: Print complete - Spoolman updated
|
||||
message: 'Print complete - Spoolman deducted {{ summary_total }} g
|
||||
|
||||
{{ summary_lines }}'
|
||||
- action: notify.mobile_app_sm_f956w
|
||||
data:
|
||||
title: Print complete - Spoolman updated
|
||||
message: 'Print complete - Spoolman deducted {{ summary_total }} g
|
||||
|
||||
{{ summary_lines }}'
|
||||
- action: input_number.set_value
|
||||
target:
|
||||
entity_id: input_number.sparkx_i7_spoolman_length_checkpoint
|
||||
data:
|
||||
value: '{{ cur }}'
|
||||
- action: input_text.set_value
|
||||
target:
|
||||
entity_id: input_text.sparkx_i7_print_spool_latch
|
||||
data:
|
||||
value: ''
|
||||
mode: single
|
||||
File diff suppressed because it is too large
Load Diff
@@ -4365,3 +4365,5 @@
|
||||
{"timestamp": "2026-10-11T03:50:50.556393+00:00", "tool_name": "ha_config_set_helper", "parameters": {"helper_type": "input_number", "name": "SparkX i7 Last Job Filament Weight", "helper_id": null, "entry_id": null, "subentry_type": null, "subentry_id": null, "show_advanced_options": false, "icon": "mdi:weight-gram", "area_id": null, "labels": null, "min_value": 0.0, "max_value": 10000.0, "step": 0.1, "unit_of_measurement": "g", "options": null, "initial": null, "mode": "box", "has_date": null, "has_time": null, "restore": null, "duration": null, "monday": null, "tuesday": null, "wednesday": null, "thursday": null, "friday": null, "saturday": null, "sunday": null, "latitude": null, "longitude": null, "radius": null, "passive": null, "user_id": null, "device_trackers": null, "picture": null, "tag_id": null, "description": null, "category": null, "config": null, "wait": true, "action": null, "MandatoryBPS": true, "BestPracticeKey": null}, "execution_time_ms": 66.59555435180664, "success": true, "error_message": null, "response_size_bytes": 51937, "user_context": null}
|
||||
{"timestamp": "2026-10-11T03:52:10.140061+00:00", "tool_name": "ha_config_get_dashboard", "parameters": {"url_path": "sparkx-i7", "list_only": false, "force_reload": true, "entity_id": null, "card_type": null, "heading": null, "include_config": false, "include_screenshot": false, "view_path": null, "mode": null, "query": null}, "execution_time_ms": 193.38178634643555, "success": true, "error_message": null, "response_size_bytes": 58116, "user_context": null}
|
||||
{"timestamp": "2026-10-11T03:52:10.823878+00:00", "tool_name": "ha_config_get_automation", "parameters": {"identifier": "automation.sparkx_i7_deduct_filament_in_spoolman_on_print_complete"}, "execution_time_ms": 878.4890174865723, "success": true, "error_message": null, "response_size_bytes": 5980, "user_context": null}
|
||||
{"timestamp": "2026-10-11T03:52:40.263776+00:00", "tool_name": "ha_config_set_dashboard", "parameters": {"url_path": "sparkx-i7", "config": null, "python_transform": "for c in config['views'][0]['sections'][4]['cards']:\n if c.get('name') == 'Filament Used':\n c['primary'] = \"{% set st = states('sensor.sparkx_i7_print_status') %}{% if st in ['printing', 'paused'] %}{{ states('sensor.sparkx_i7_filament_weight_estimated') | round(1) }} g{% else %}Last job: {{ states('input_number.sparkx_i7_last_job_filament_weight') | round(1) }} g{% endif %}\"\n elif c.get('name') == 'Job Cost (total)':\n c['entity'] = 'input_number.sparkx_i7_last_job_cost'\n c['multiline_secondary'] = True\n c['primary'] = \"{% set st = states('sensor.sparkx_i7_print_status') %}{% if st in ['printing', 'paused'] %}{{ states('sensor.sparkx_i7_filament_cost') | round(2) }} ${% else %}{{ states('input_number.sparkx_i7_last_job_cost') | round(2) }} ${% endif %}\"\n c['secondary'] = \"{% set st = states('sensor.sparkx_i7_print_status') %}{% if st in ['printing', 'paused'] %}this job (live){% else %}last job{% endif %}\"\n c['type'] = 'custom:mushroom-template-card'", "config_hash": "b19b095defd4f5fe", "title": null, "icon": null, "require_admin": null, "show_in_sidebar": null, "MandatoryBPS": true, "BestPracticeKey": null, "return_screenshot": false, "view_path": null, "patch": null}, "execution_time_ms": 133.79645347595215, "success": true, "error_message": null, "response_size_bytes": 33779, "user_context": null}
|
||||
{"timestamp": "2026-10-11T03:52:41.864447+00:00", "tool_name": "ha_config_set_automation", "parameters": {"config": null, "identifier": "automation.sparkx_i7_deduct_filament_in_spoolman_on_print_complete", "python_transform": "idx = None\nfor i, a in enumerate(config.get('actions', [])):\n if a.get('action') == 'input_number.set_value' and a.get('target', {}).get('entity_id') == 'input_number.sparkx_i7_spoolman_length_checkpoint':\n idx = i\n break\nif idx is not None:\n config['actions'].insert(idx, {\"action\": \"input_number.set_value\", \"target\": {\"entity_id\": \"input_number.sparkx_i7_last_job_cost\"}, \"data\": {\"value\": \"{{ ((final_grams | float) * (states('input_number.filament_price_per_kg') | float(25)) / 1000) | round(2) }}\"}})\n config['actions'].insert(idx, {\"action\": \"input_number.set_value\", \"target\": {\"entity_id\": \"input_number.sparkx_i7_last_job_filament_weight\"}, \"data\": {\"value\": \"{{ final_grams }}\"}})", "config_hash": "5f9e3b69007edc22", "take_control_of_blueprint": false, "category": null, "wait": true, "enabled": null, "run_actions": false, "MandatoryBPS": true, "BestPracticeKey": null}, "execution_time_ms": 2014.4972801208496, "success": true, "error_message": null, "response_size_bytes": 80509, "user_context": null}
|
||||
|
||||
@@ -555,7 +555,7 @@
|
||||
"icon": "{% set st = states('sensor.sparkx_i7_print_status') %}{% if st in ['printing', 'paused'] %}mdi:printer-3d-nozzle{% else %}mdi:calendar-today{% endif %}",
|
||||
"multiline_secondary": true,
|
||||
"name": "Filament Used",
|
||||
"primary": "{% set st = states('sensor.sparkx_i7_print_status') %}{% if st in ['printing', 'paused'] %}{{ states('sensor.sparkx_i7_filament_weight_estimated') | round(1) }} g{% else %}No active job{% endif %}",
|
||||
"primary": "{% set st = states('sensor.sparkx_i7_print_status') %}{% if st in ['printing', 'paused'] %}{{ states('sensor.sparkx_i7_filament_weight_estimated') | round(1) }} g{% else %}Last job: {{ states('input_number.sparkx_i7_last_job_filament_weight') | round(1) }} g{% endif %}",
|
||||
"secondary": "{% set st = states('sensor.sparkx_i7_print_status') %}{% if st in ['printing', 'paused'] %}{{ states('sensor.sparkx_i7_used_material_length') | round(0) }} cm this job{% else %}{{ states('sensor.sparkx_i7_filament_weight_daily') | round(1) }} g · {{ states('sensor.sparkx_i7_filament_cost_daily') | round(2) }} $ today{% endif %}",
|
||||
"type": "custom:mushroom-template-card"
|
||||
},
|
||||
@@ -581,13 +581,16 @@
|
||||
"type": "custom:mushroom-template-card"
|
||||
},
|
||||
{
|
||||
"entity": "sensor.sparkx_i7_filament_cost",
|
||||
"entity": "input_number.sparkx_i7_last_job_cost",
|
||||
"grid_options": {
|
||||
"columns": 3
|
||||
},
|
||||
"icon": "mdi:cash",
|
||||
"name": "Job Cost (total)",
|
||||
"type": "tile"
|
||||
"type": "custom:mushroom-template-card",
|
||||
"multiline_secondary": true,
|
||||
"primary": "{% set st = states('sensor.sparkx_i7_print_status') %}{% if st in ['printing', 'paused'] %}{{ states('sensor.sparkx_i7_filament_cost') | round(2) }} ${% else %}{{ states('input_number.sparkx_i7_last_job_cost') | round(2) }} ${% endif %}",
|
||||
"secondary": "{% set st = states('sensor.sparkx_i7_print_status') %}{% if st in ['printing', 'paused'] %}this job (live){% else %}last job{% endif %}"
|
||||
},
|
||||
{
|
||||
"entity": "sensor.sparkx_i7_filament_cost_daily",
|
||||
|
||||
@@ -4507,6 +4507,17 @@
|
||||
message: 'Print complete - Spoolman deducted {{ summary_total }} g
|
||||
|
||||
{{ summary_lines }}'
|
||||
- action: input_number.set_value
|
||||
target:
|
||||
entity_id: input_number.sparkx_i7_last_job_filament_weight
|
||||
data:
|
||||
value: '{{ final_grams }}'
|
||||
- action: input_number.set_value
|
||||
target:
|
||||
entity_id: input_number.sparkx_i7_last_job_cost
|
||||
data:
|
||||
value: '{{ ((final_grams | float) * (states(''input_number.filament_price_per_kg'')
|
||||
| float(25)) / 1000) | round(2) }}'
|
||||
- action: input_number.set_value
|
||||
target:
|
||||
entity_id: input_number.sparkx_i7_spoolman_length_checkpoint
|
||||
|
||||
Reference in New Issue
Block a user