- sensor:
- name: "Pellet_Usage_Difference" # Name of the sensor
unique_id: e7900b1b-e89b-4356-a050-a6928781042f # Unique identifier for the sensor
icon: mdi:weight-kilogram # Icon representing the sensor
unit_of_measurement: "kg" # Unit of measurement for the sensor value
state: >-
# Get pellet count at midnight, default to 0
{% set gewicht_start = states('input_number.pelletsatmidnight') | float(0) %}
# Get current pellet usage, default to 0
{% set gewicht_end = states('sensor.solarfocus_biomass_boiler_pellet_usage_total') | float(0) %}
# Check if the current usage is zero or the sensor is unavailable
{% if gewicht_end == 0 or
is_state('sensor.solarfocus_biomass_boiler_pellet_usage_total', 'unavailable') or
is_state('sensor.solarfocus_biomass_boiler_pellet_usage_total', 'unknown') %}
# Return 0 if any conditions are met
0
{% else %}
# Calculate the difference and ensure it's at least 0
{{ max(0, (gewicht_end - gewicht_start) | round(2)) }}
{% endif %}
availability: >
# Check if the sensor is available (not unknown or unavailable)
{{ states('sensor.solarfocus_biomass_boiler_pellet_usage_total') not in ['unknown', 'unavailable'] }}
Lässt sich prüfen und kompilieren, alleine der Sensor wird dann nicht erkannt.
Gleicher Code ohne Kommentare, läuft… Ist das normal?
ChatGPT hat die Kommentare, auf meinen Wunsch hin, zugefügt.
- sensor:
- name: "Pellet_Usage_Difference" # Name of the sensor
unique_id: e7900b1b-e89b-4356-a050-a6928781042f # Unique identifier for the sensor
icon: mdi:weight-kilogram # Icon representing the sensor
unit_of_measurement: "kg" # Unit of measurement for the sensor value
state: >-
{% set gewicht_start = states('input_number.pelletsatmidnight') | float(0) %}
{% set gewicht_end = states('sensor.solarfocus_biomass_boiler_pellet_usage_total') | float(0) %}
{% if gewicht_end == 0 or
is_state('sensor.solarfocus_biomass_boiler_pellet_usage_total', 'unavailable') or
is_state('sensor.solarfocus_biomass_boiler_pellet_usage_total', 'unknown') %}
0
{% else %}
{{ max(0, (gewicht_end - gewicht_start) | round(2)) }}
{% endif %}
availability: >
{{ states('sensor.solarfocus_biomass_boiler_pellet_usage_total') not in ['unknown', 'unavailable'] }}
- sensor:
# Name of the sensor
- name: "Pellet Usage Difference"
# Unique identifier for the sensor
unique_id: e7900b1b-e89b-4356-a050-a6928781042f
# Icon representing the sensor
icon: mdi:weight-kilogram
# Unit of measurement for the sensor value
unit_of_measurement: "kg"
state: >-
{# Get pellet count at midnight, default to 0 #}
{% set gewicht_start = states('input_number.pelletsatmidnight') | float(0) %}
{# Get current pellet usage, default to 0 #}
{% set gewicht_end = states('sensor.solarfocus_biomass_boiler_pellet_usage_total') | float(0) %}
{# Check if the current usage is zero or the sensor is unavailable #}
{% if gewicht_end == 0 or
is_state('sensor.solarfocus_biomass_boiler_pellet_usage_total', 'unavailable') or
is_state('sensor.solarfocus_biomass_boiler_pellet_usage_total', 'unknown') %}
{# Return 0 if any conditions are met #}
0
{% else %}
{# Calculate the difference and ensure it's at least 0 #}
{{ max(0, (gewicht_end - gewicht_start) | round(2)) }}
{% endif %}
availability: >
# Check if the sensor is available (not unknown or unavailable)
{{ states('sensor.solarfocus_biomass_boiler_pellet_usage_total') not in ['unknown', 'unavailable'] }}
Scheinbar muss man genau darauf achten, wie man wo kommentiert!!!
Ich habe es aufgegeben. Auch das ist mir um die Ohren geflogen, also muss ich ohne Kommentare glücklich werden…
Ehrlich gesagt habe ich sie noch nie vermisst, weil ich das meiste selbsterklärend finde. Und bei den Sachen, die nicht selbsterklärend sind, helfen mir Kommentare, die ich selbst schreibe, auch nicht weiter. Ich kann mir höchstens vorstellen, dass das gut ist, wenn man für andere einen Code schreibt und diejenigen nicht genau wissen, wozu die einzelnen Schritte gut sind. Habe ich selbst aber noch nie gemacht, also für andere codiert: bekomme ja gerade so eben meine Sachen auf die Reihe
Was mich so wahnsinnig macht: Der Template Editor zeigt den Code schön ohne Kommentare an, also ist ja alles gut. Die Berechnung stimmt auch.
Und dann findet der Studio Code Server die Kommentare “doof”. Ok, kann man sich ja noch irgendwie schön reden. Aber wenn HA dann den Code, der im Template Editor funktioniert, nicht kompiliere will, verstehe ich nicht wirklich was da los ist!!
Ich könnte auch ohne Kommentare leben, jetzt will ich aber wissen, warum es nicht geht…
# Mal wieder ein neuer Test Sensor
- trigger:
- platform: state # Zustandänderung als Auslöser 😱
entity_id: input_number.stromzahler
sensor:
name: Test Trigger
state: |
{% set x = states('input_number.stromzahler') %} {## Hier wird die Varuiable x definiert ##}
{## Beginn von IIF ##}
{{ iif(is_number(x), x, this.state) }}
{## Ende von IIF ##}
unique_id: 0c7ba491-2ad2-4bf0-98fe-f7ca3771a661 # Keinen pseude Uniqe ID 😀
Der Kommentar unter “availability: >” muss auch ein jinja {# Kommentar #} sein!!!
- sensor:
# Name of the sensor
- name: "Pellet_Usage_Difference"
# Unique identifier for the sensor
unique_id: 62ecb2ee-939d-40b8-801f-a9ad0cdab8df
# Icon representing the sensor
icon: mdi:weight-kilogram
# Unit of measurement for the sensor value
unit_of_measurement: "kg"
state: >-
{# Get pellet count at midnight, default to 0 #}
{% set gewicht_start = states('input_number.pelletsatmidnight') | float(0) %}
{# Get current pellet usage, default to 0 #}
{% set gewicht_end = states('sensor.solarfocus_biomass_boiler_pellet_usage_total') | float(0) %}
{# Check if the current usage is zero or the sensor is unavailable #}
{% if gewicht_end == 0 or
is_state('sensor.solarfocus_biomass_boiler_pellet_usage_total', 'unavailable') or
is_state('sensor.solarfocus_biomass_boiler_pellet_usage_total', 'unknown') %}
{# Return 0 if any conditions are met #}
0
{% else %}
{# Calculate the difference and ensure it's at least 0 #}
{{ max(0, (gewicht_end - gewicht_start) | round(2)) }}
{% endif %}
availability: >
{# Check if the sensor is available (not unknown or unavailable) #}
{{ states('sensor.solarfocus_biomass_boiler_pellet_usage_total') not in ['unknown', 'unavailable'] }}