configuration.yaml, zigbee2mqtt/state.json
This commit is contained in:
+16
-13
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user