This commit is contained in:
Home Assistant Version Control committed 2026-10-15 13:23:24 +00:00
1 parent c181946323
commit c85606c96e
3 files changed
+368 -83

No files matched your search

@@ -0,0 +1,171 @@
# ha_mcp_backup
schema_version: 1
domain: automation
entity_id: '1791477238729'
captured: '2026-10-15T13:23:17.499559+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
id: complete
- trigger: state
entity_id: sensor.sparkx_i7_print_status
to: stopped
id: stopped
- trigger: state
entity_id: sensor.sparkx_i7_print_status
to: error
id: error
conditions:
- condition: template
value_template: '{{ trigger.id == ''complete'' or states(''input_text.sparkx_i7_print_spool_latch'')
not in ['''', ''unknown'', ''unavailable''] }}'
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) }}'
outcome: '{% set tid = trigger.id | default(''complete'') %}{{ ''cancelled''
if tid == ''stopped'' else (''error'' if tid == ''error'' else ''complete'')
}}'
- 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 (state_attr(e[:-10], ''location'')
| default('''', true) | lower) == (''cfs lite '' ~ old_slot.split(''_'')[-1])
%}{% 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 {{ outcome }}: 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 {{ outcome }}: 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 {{ outcome }}: 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 {{ outcome }} - Spoolman updated
message: 'Print {{ outcome }} - Spoolman deducted {{ summary_total }} g
{{ summary_lines }}'
- action: notify.mobile_app_francos_ipad
data:
title: Print {{ outcome }} - Spoolman updated
message: 'Print {{ outcome }} - Spoolman deducted {{ summary_total }} g
{{ summary_lines }}'
- action: notify.mobile_app_sm_f956w
data:
title: Print {{ outcome }} - Spoolman updated
message: 'Print {{ outcome }} - Spoolman deducted {{ summary_total }} g
{{ summary_lines }}'
- if:
condition: template
value_template: '{{ trigger.id == ''complete'' }}'
then:
- action: input_number.set_value
target:
entity_id: input_number.sparkx_i7_last_job_filament_weight
data:
value: '{{ summary_total }}'
- action: input_number.set_value
target:
entity_id: input_number.sparkx_i7_last_job_cost
data:
value: '{{ ((summary_total | 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
data:
value: '{{ cur }}'
- action: input_text.set_value
target:
entity_id: input_text.sparkx_i7_print_spool_latch
data:
value: ''
mode: single
+1
View File
@@ -4563,3 +4563,4 @@
{"timestamp": "2026-10-15T13:22:39.599656+00:00", "tool_name": "ha_config_get_script", "parameters": {"script_id": "spoolman_set_spool_remaining"}, "execution_time_ms": 108.43968391418457, "success": true, "error_message": null, "response_size_bytes": 2239, "user_context": null}
{"timestamp": "2026-10-15T13:22:39.822007+00:00", "tool_name": "ha_config_get_automation", "parameters": {"identifier": "1791477238762"}, "execution_time_ms": 334.63048934936523, "success": true, "error_message": null, "response_size_bytes": 5649, "user_context": null}
{"timestamp": "2026-10-15T13:22:39.905414+00:00", "tool_name": "ha_config_get_automation", "parameters": {"identifier": "1791477238799"}, "execution_time_ms": 413.3596420288086, "success": true, "error_message": null, "response_size_bytes": 7574, "user_context": null}
{"timestamp": "2026-10-15T13:23:18.159012+00:00", "tool_name": "ha_config_set_automation", "parameters": {"config": null, "identifier": "1791477238729", "python_transform": "_repl = [(\"matching the latched slot color\", \"matching the latched slot's CFS Lite location\"), (\"Spoolman: no spool for slot color\", \"Spoolman: no spool for the latched slot\"), (\"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.\", \"no Spoolman spool with remaining weight is in that slot's CFS Lite location. Register the new roll in Spoolman in that location, then adjust manually if needed.\")]\nstack = [config]\nfor _ in range(20000):\n if not stack:\n break\n node = stack.pop()\n if isinstance(node, dict):\n for k in list(node.keys()):\n v = node[k]\n if isinstance(v, str):\n for a, b in _repl:\n if a in v:\n v = v.replace(a, b)\n node[k] = v\n elif isinstance(v, (dict, list)):\n stack.append(v)\n elif isinstance(node, list):\n for i in range(len(node)):\n v = node[i]\n if isinstance(v, str):\n for a, b in _repl:\n if a in v:\n v = v.replace(a, b)\n node[i] = v\n elif isinstance(v, (dict, list)):\n stack.append(v)", "config_hash": "75d85b947ad8ec44", "take_control_of_blueprint": false, "category": null, "wait": true, "enabled": null, "run_actions": false, "MandatoryBPS": true, "BestPracticeKey": null}, "execution_time_ms": 622.8833198547363, "success": true, "error_message": null, "response_size_bytes": 83935, "user_context": null}