configuration.yaml, zigbee2mqtt/state.json

This commit is contained in:
Home Assistant Version Control
2026-08-08 11:08:21 +00:00
parent 5af889ba2a
commit b39c9840e0
2 changed files with 32 additions and 29 deletions
+16 -13
View File
@@ -221,8 +221,9 @@ template:
unit_of_measurement: "mm"
icon: mdi:spool
state: >-
{% set lengths = state_attr('sensor.octoprint_filament_used_total', 'filamentLength') %}
{{ lengths[-1] | float | round(2) if lengths else 0 }}
{% set jobs = state_attr('sensor.octoprint_filament_used_total', 'filamentModels') | default([]) %}
{% set last = jobs[0] if jobs else {} %}
{{ last.get('total', {}).get('usedLength', 0) | float | round(2) if last else 0 }}
# Legacy and Integration Sensor Section
sensor:
@@ -248,7 +249,7 @@ sensor:
# OctoPrint PrintHistory - filament usage from https://ender5pro.duckdns.org
rest:
- resource: "https://ender5pro.duckdns.org/plugin/printhistory/history"
- resource: "https://ender5pro.duckdns.org/plugin/PrintJobHistory/loadPrintJobHistoryByQuery?from=0&to=100000&sortColumn=printStartDateTime&sortOrder=desc&filterName="
method: GET
headers:
X-Api-Key: !secret octoprint_api_key
@@ -262,21 +263,23 @@ rest:
icon: mdi:spool
value_template: >-
{{
value_json.history
| selectattr('filamentLength', 'ne', None)
| map(attribute='filamentLength')
| map('float')
value_json.allPrintJobs
| map(attribute='filamentModels')
| select('defined')
| map(attribute='total')
| select('defined')
| map(attribute='usedLength')
| select('is_number')
| sum
| round(2)
}}
json_attributes_path: "$.history"
json_attributes_path: "$.allPrintJobs"
json_attributes:
- "fileName"
- "filamentLength"
- "filamentVolume"
- "printTime"
- "success"
- "timestamp"
- "filamentModels"
- "printStatusResult"
- "duration"
- "printStartDateTimeFormatted"
# OctoPrint physical position (holds last value when idle; raw discovery sensor zeroes on currentZ:null)
mqtt: