From 57950cba9c0d61e2b25153a8c720ec86a2b5b67c Mon Sep 17 00:00:00 2001 From: Home Assistant Version Control Date: Thu, 8 Oct 2026 17:53:01 +0000 Subject: [PATCH] 4 files --- ...n_set_spool_remaining.20261008_175220.yaml | 24 ++++++++++ .ha_mcp/logs/mcp_usage.jsonl | 3 ++ scripts.yaml | 48 ++++++++++++++++--- zigbee2mqtt/state.json | 16 +++---- 4 files changed, 77 insertions(+), 14 deletions(-) create mode 100644 .ha_mcp/backups/script.spoolman_set_spool_remaining.20261008_175220.yaml diff --git a/.ha_mcp/backups/script.spoolman_set_spool_remaining.20261008_175220.yaml b/.ha_mcp/backups/script.spoolman_set_spool_remaining.20261008_175220.yaml new file mode 100644 index 00000000..4f8f49a2 --- /dev/null +++ b/.ha_mcp/backups/script.spoolman_set_spool_remaining.20261008_175220.yaml @@ -0,0 +1,24 @@ +# ha_mcp_backup +schema_version: 1 +domain: script +entity_id: spoolman_set_spool_remaining +captured: '2026-10-08T17:52:20.969671+00:00' +tool: ha_config_set_script +config: + alias: Spoolman - Set Spool Remaining + fields: + spool_id: + required: true + name: Spool ID + selector: + number: + min: 1 + max: 9999 + mode: box + sequence: + - action: spoolman.patch_spool + data: + id: '{{ spool_id | int(0) }}' + remaining_weight: '{{ states(''input_number.spoolman_set_remaining'') | float(0) + }}' + mode: single diff --git a/.ha_mcp/logs/mcp_usage.jsonl b/.ha_mcp/logs/mcp_usage.jsonl index 59df0b10..53ce0aef 100644 --- a/.ha_mcp/logs/mcp_usage.jsonl +++ b/.ha_mcp/logs/mcp_usage.jsonl @@ -4029,3 +4029,6 @@ {"timestamp": "2026-10-08T17:50:29.608770+00:00", "tool_name": "ha_config_set_automation", "parameters": {"config": null, "identifier": "automation.sparkx_i7_deduct_filament_in_spoolman_on_print_complete", "python_transform": "msgc = \"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 with remaining weight matches that color. Register the new roll in Spoolman, then adjust manually if needed.\"\nnt = [{'action': 'notify.persistent_notification', 'data': {'title': 'Spoolman: no spool for slot color', 'message': msgc}}, {'action': 'notify.mobile_app_francos_ipad', 'data': {'title': 'Spoolman: no spool for slot color', 'message': msgc}}, {'action': 'notify.mobile_app_sm_f956w', 'data': {'title': 'Spoolman: no spool for slot color', 'message': msgc}}]\nms = \"Print complete - Spoolman deducted {{ summary_total }} g\\n{{ summary_lines }}\"\nns = [{'action': 'notify.persistent_notification', 'data': {'title': 'Print complete - Spoolman updated', 'message': ms}}, {'action': 'notify.mobile_app_francos_ipad', 'data': {'title': 'Print complete - Spoolman updated', 'message': ms}}, {'action': 'notify.mobile_app_sm_f956w', 'data': {'title': 'Print complete - Spoolman updated', 'message': ms}}]\nconfig['description'] = 'On print completion, deducts the final segment (used_material_length delta since last checkpoint x g/cm) from the Spoolman spool 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.'\nconfig['conditions'] = []\nconfig['actions'] = [\n {'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) }}\"}},\n {'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 }}\"}},\n {'variables': {'spool_id': \"{% set ns = namespace(id='') %}{% for e in integration_entities('spoolman') %}{% if e.endswith('_color_hex') and (states(e) | replace('#', '') | lower) == color %}{% set b = e[:-10] %}{% if (states(b) | float(0)) > 0 and ns.id == '' %}{% set ns.id = states(b ~ '_id') %}{% endif %}{% endif %}{% endfor %}{{ ns.id }}\"}},\n {'variables': {'helper_idx': \"{{ old_slot.split(' ')[-1] if old_slot.split(' ')[-1] in ['1', '2', '3', '4'] else '' }}\"}},\n {'variables': {'nonhelper_g': \"{{ final_grams if (final_grams | float > 0) and (spool_id not in ['', 'unknown', 'unavailable']) and (helper_idx == '') else 0 }}\"}},\n {'if': {'condition': 'template', 'value_template': '{{ final_grams | float > 0 }}'},\n 'then': [{'choose': [\n {'conditions': {'condition': 'template', 'value_template': \"{{ spool_id not in ['', 'unknown', 'unavailable'] }}\"},\n 'sequence': [\n {'action': 'spoolman.use_spool_filament', 'data': {'id': '{{ spool_id | int(0) }}', 'use_weight': '{{ final_grams | float(0) }}'}},\n {'if': {'condition': 'template', 'value_template': \"{{ helper_idx != '' }}\"},\n '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) }}\"}}]}\n ]}\n ], 'default': nt}]},\n {'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) }}\"}},\n {'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') }}\"}},\n {'if': {'condition': 'template', 'value_template': '{{ summary_total | float > 0 }}'}, 'then': ns},\n {'action': 'input_number.set_value', 'target': {'entity_id': 'input_number.sparkx_i7_spoolman_length_checkpoint'}, 'data': {'value': '{{ cur }}'}},\n {'action': 'input_text.set_value', 'target': {'entity_id': 'input_text.sparkx_i7_print_spool_latch'}, 'data': {'value': ''}}\n]", "config_hash": "9a6285e4401f42ad", "take_control_of_blueprint": false, "category": null, "wait": true, "enabled": null, "run_actions": false, "MandatoryBPS": true, "BestPracticeKey": null}, "execution_time_ms": 1595.430850982666, "success": true, "error_message": null, "response_size_bytes": 84889, "user_context": null} {"timestamp": "2026-10-08T17:50:48.985057+00:00", "tool_name": "ha_config_get_script", "parameters": {"script_id": "spoolman_set_spool_remaining"}, "execution_time_ms": 96.89092636108398, "success": true, "error_message": null, "response_size_bytes": 494, "user_context": null} {"timestamp": "2026-10-08T17:50:49.070424+00:00", "tool_name": "ha_config_get_automation", "parameters": {"identifier": "automation.sparkx_i7_deduct_filament_in_spoolman_on_print_complete"}, "execution_time_ms": 180.57489395141602, "success": true, "error_message": null, "response_size_bytes": 5731, "user_context": null} +{"timestamp": "2026-10-08T17:52:21.426837+00:00", "tool_name": "ha_config_set_script", "parameters": {"script_id": "spoolman_set_spool_remaining", "config": null, "python_transform": "config['description'] = 'Sets a Spoolman spool remaining weight from the shared helper input_number.spoolman_set_remaining. Pass slot (1-4) to resolve the spool by the CFS slot color hex (no remaining-weight guard, so an exhausted spool can be reset to full), or pass spool_id directly. Notifies via persistent notification when nothing could be resolved.'\nconfig['fields'] = {\n 'slot': {'name': 'CFS Slot', 'description': 'CFS slot number 1-4 - resolves the spool by the slot color hex', 'selector': {'number': {'min': 1, 'max': 4, 'mode': 'box'}}},\n 'spool_id': {'name': 'Spool ID', 'description': 'Direct Spoolman spool ID - used when no slot is given', 'selector': {'number': {'min': 1, 'max': 9999, 'mode': 'box'}}}\n}\nconfig['sequence'] = [\n {'variables': {'resolved_id': \"{% set n = (slot | int(0)) if slot is defined else 0 %}{% if n >= 1 %}{% set color = states('sensor.sparkx_i7_cfs_box_1_slot_' ~ (n | int) ~ '_color') | replace('#', '') | lower %}{% set ns = namespace(id='') %}{% for e in integration_entities('spoolman') %}{% if e.endswith('_color_hex') and (states(e) | replace('#', '') | lower) == color and ns.id == '' %}{% set ns.id = states(e[:-10] ~ '_id') %}{% endif %}{% endfor %}{{ ns.id }}{% else %}{{ (spool_id | int(0)) if spool_id is defined else 0 }}{% endif %}\", 'slot_n': \"{{ (slot | int(0)) if slot is defined else 0 }}\"}},\n {'choose': [\n {'conditions': {'condition': 'template', 'value_template': '{{ resolved_id | int(0) > 0 }}'},\n 'sequence': [{'action': 'spoolman.patch_spool', 'data': {'id': \"{{ resolved_id | int(0) }}\", 'remaining_weight': \"{{ states('input_number.spoolman_set_remaining') | float(0) }}\"}}]}\n ], 'default': [\n {'action': 'notify.persistent_notification', 'data': {'title': 'Spoolman - remaining not set', 'message': \"{% if slot_n | int >= 1 %}No Spoolman spool matched CFS slot {{ slot_n }} (color {{ states('sensor.sparkx_i7_cfs_box_1_slot_' ~ (slot_n | int) ~ '_color') }}) - register a spool with that color hex in Spoolman, then try again.{% else %}No spool resolved - pass spool_id or a CFS slot 1-4. Nothing was set.{% endif %}\"}}\n ]}\n]", "config_hash": "437793b4a720ad6a", "take_control_of_blueprint": false, "category": null, "wait": true, "run": null, "variables": null, "MandatoryBPS": true, "BestPracticeKey": null}, "execution_time_ms": 432.71756172180176, "success": true, "error_message": null, "response_size_bytes": 81020, "user_context": null} +{"timestamp": "2026-10-08T17:52:54.751723+00:00", "tool_name": "ha_config_get_dashboard", "parameters": {"url_path": "sparkx-i7", "list_only": false, "force_reload": false, "entity_id": null, "card_type": null, "heading": null, "include_config": false, "include_screenshot": false, "view_path": "spoolman", "mode": null, "query": null}, "execution_time_ms": 9.920358657836914, "success": true, "error_message": null, "response_size_bytes": 7760, "user_context": null} +{"timestamp": "2026-10-08T17:52:54.757848+00:00", "tool_name": "ha_config_get_script", "parameters": {"script_id": "spoolman_set_spool_remaining"}, "execution_time_ms": 20.314455032348633, "success": true, "error_message": null, "response_size_bytes": 2243, "user_context": null} diff --git a/scripts.yaml b/scripts.yaml index 7bd8a4ec..af60ab30 100644 --- a/scripts.yaml +++ b/scripts.yaml @@ -243,18 +243,54 @@ light_color_temp_helper: spoolman_set_spool_remaining: alias: Spoolman - Set Spool Remaining fields: + slot: + name: CFS Slot + description: CFS slot number 1-4 - resolves the spool by the slot color hex + selector: + number: + min: 1 + max: 4 + mode: box spool_id: - required: true name: Spool ID + description: Direct Spoolman spool ID - used when no slot is given selector: number: min: 1 max: 9999 mode: box sequence: - - action: spoolman.patch_spool - data: - id: '{{ spool_id | int(0) }}' - remaining_weight: '{{ states(''input_number.spoolman_set_remaining'') | float(0) - }}' + - variables: + resolved_id: '{% set n = (slot | int(0)) if slot is defined else 0 %}{% if n + >= 1 %}{% set color = states(''sensor.sparkx_i7_cfs_box_1_slot_'' ~ (n | int) + ~ ''_color'') | replace(''#'', '''') | lower %}{% set ns = namespace(id='''') + %}{% for e in integration_entities(''spoolman'') %}{% if e.endswith(''_color_hex'') + and (states(e) | replace(''#'', '''') | lower) == color and ns.id == '''' + %}{% set ns.id = states(e[:-10] ~ ''_id'') %}{% endif %}{% endfor %}{{ ns.id + }}{% else %}{{ (spool_id | int(0)) if spool_id is defined else 0 }}{% endif + %}' + slot_n: '{{ (slot | int(0)) if slot is defined else 0 }}' + - choose: + - conditions: + condition: template + value_template: '{{ resolved_id | int(0) > 0 }}' + sequence: + - action: spoolman.patch_spool + data: + id: '{{ resolved_id | int(0) }}' + remaining_weight: '{{ states(''input_number.spoolman_set_remaining'') | + float(0) }}' + default: + - action: notify.persistent_notification + data: + title: Spoolman - remaining not set + message: '{% if slot_n | int >= 1 %}No Spoolman spool matched CFS slot {{ + slot_n }} (color {{ states(''sensor.sparkx_i7_cfs_box_1_slot_'' ~ (slot_n + | int) ~ ''_color'') }}) - register a spool with that color hex in Spoolman, + then try again.{% else %}No spool resolved - pass spool_id or a CFS slot + 1-4. Nothing was set.{% endif %}' mode: single + description: Sets a Spoolman spool remaining weight from the shared helper input_number.spoolman_set_remaining. + Pass slot (1-4) to resolve the spool by the CFS slot color hex (no remaining-weight + guard, so an exhausted spool can be reset to full), or pass spool_id directly. + Notifies via persistent notification when nothing could be resolved. diff --git a/zigbee2mqtt/state.json b/zigbee2mqtt/state.json index 1693ed11..a668be18 100644 --- a/zigbee2mqtt/state.json +++ b/zigbee2mqtt/state.json @@ -48,7 +48,7 @@ "voltage": 118.1, "countdown_to_turn_on": 0, "energy": 103.68, - "power_factor": 0.89, + "power_factor": 0.2, "ac_frequency": 60, "update": { "state": "idle", @@ -58,8 +58,8 @@ "latest_release_notes": null }, "linkquality": 145, - "power": 85, - "current": 0.83, + "power": 0.2, + "current": 0.01, "power_on_behavior": "on" }, "0xb40e060fffe031e3": { @@ -77,10 +77,10 @@ "voltage": 116.9, "state": "ON", "ac_frequency": 60, - "energy": 210.41, - "power": 105.5, - "current": 0.99, - "power_factor": 0.94, + "energy": 210.42, + "power": 104.2, + "current": 0.94, + "power_factor": 0.95, "update": { "state": "idle", "installed_version": 268513381, @@ -98,7 +98,7 @@ "voltage": 118.6, "energy": 100.68, "state": "ON", - "power": 10.6, + "power": 10.7, "current": 0.32, "ac_frequency": 60, "power_factor": 0.51,