Hello, I like to display solar power via Awtrix. The raw data should be processed so that it is meaningful and not too long:
Average of the last 10 min.
Formatting: below 9000 in W, above in kW, rounded to whole numbers
As this is too much for me, I had ChatGPT write the template. Looks good, but doesn’t work. Output is code-lines instead of a value.
Where is the problem? Thanks for some help…
sensor:
- platform: statistics
name: "Durchschnitt DC Gesamtleistung (10 Minuten)"
unique_id: "average_dc_power_10min"
entity_id: sensor.sh20t_a2442602734_total_dc_power
state_characteristic: mean
max_age:
minutes: 10
- platform: template
sensors:
formatted_average_dc_power_10min:
friendly_name: "Durchschnittliche DC-Leistung (10 Minuten)"
unique_id: "formatted_average_dc_power_10min"
value_template: >
{% set value = states('sensor.average_dc_power_10min') | float(0) %}
{% if value < 9000 %}
{{ value | round }}
{% else %}
{{ (value / 1000) | round }}
{% endif %}
unit_of_measurement: >
{% set value = states('sensor.average_dc_power_10min') | float(0) %}
{% if value < 9000 %}
W
{% else %}
kW
{% endif %}