Hello,
I have the problem that I do not get the negative value displayed as positive.
I tried with the following entry, but it seems to be an error.
The value “sensor.einspeisungbezug_3” is delivered by the smartmeter positive and negative
I need one entitiy pos and one negativ
template:
- sensor:
- name: "GridPowerIn"
unit_of_measurement: "kWh"
state_class: total_increasing
device_class: energy
state: >
{% if states('sensor.einspeisungbezug_3') | float(0) >= 0 %}
{% set gridin = states('sensor.einspeisungbezug_3') | float(0) %}
{% else %}
{% set gridin = 0 %}
{% endif %}
{{ gridin }}
- name: "GridPowerOut"
unit_of_measurement: "kWh"
state_class: total_increasing
device_class: energy
state: >
{% if states('sensor.einspeisungbezug_3') | float(0) =< 0 %}
{% set gridout = states('sensor.einspeisungbezug_3') |float | abs) %}
{% else %}
{% set gridout = 0 %}
{% endif %}
{{ gridout }}
After restarting I always get this error:
Invalid config for [template]: invalid template (TemplateSyntaxError: expected token 'end of statement block', got '=') for dictionary value @ data['sensor'][1]['state']. Got "{% if states('sensor.einspeisungbezug_3') | float(0) =< 0 %}\n {% set gridout = states('sensor.einspeisungbezug_3') |float | abs) %}\n{% else %}\n {% set gridout = 0 %}\n{% endif %} {{ gridout }}\n". (See /config/configuration.yaml, line 179).
I can not find the solution