Greetings.
Would sb be kind to point me in the right direction. I have a solar inverter which outputs power to my Home Assistant as a +/- value so I found a template on this very forum which would convert both those values to positive and created entities, and then later I would convert those to energy and ad them to energy dashboard. The problem is after most recent HA update to 2024.9 this template and entities stopped working. Any idea why? I browsed through HA change log but didn’t find any breaking changes as for this template. Below is the template which worked for 2 months until HA 2024.9
template:
- sensor:
- name: "Battery Power Input"
unit_of_measurement: "W"
device_class: power
unique_id: Battery Input Power
state: >
{% if states('sensor.smg_ii_smg_ii_battery_average_power')|float >= 0 %}
{{ states('sensor.smg_ii_smg_ii_battery_average_power') }}
{% else %}
0
{% endif %}
- name: "Battery Power Output"
unit_of_measurement: "W"
device_class: power
unique_id: Battery Output Power
state: >
{% if states('sensor.smg_ii_smg_ii_battery_average_power')|float < 0 %}
{{ -1* states('sensor.smg_ii_smg_ii_battery_average_power')|float }}
{% else %}
0
{% endif %}
It could be a combined effect of the source integration loading slowly and the fact that you don’t have defaults for your float filters. Try adding defaults…
template:
- sensor:
- name: "Battery Power Input"
unit_of_measurement: "W"
device_class: power
unique_id: Battery Input Power
state: >
{% if states('sensor.smg_ii_smg_ii_battery_average_power')|float(0) >= 0 %}
{{ states('sensor.smg_ii_smg_ii_battery_average_power')|float(0) }}
{% else %}
0
{% endif %}
- name: "Battery Power Output"
unit_of_measurement: "W"
device_class: power
unique_id: Battery Output Power
state: >
{% if states('sensor.smg_ii_smg_ii_battery_average_power')|float(0) < 0 %}
{{ -1* states('sensor.smg_ii_smg_ii_battery_average_power')|float(0) }}
{% else %}
0
{% endif %}
Sorry, this is my first time debugging HA, did not think about logs at all. The problem is solved, It seems I had two “template” sections in my configuration.yaml. After moving the “sensor” part into one template section, the whole template started to work again.
In future, how should I enclose the log in this forum? Should I download the whole log and enclose it in a zip file, or browse through it find the relevant information pointing to problems and enclose a snippet? I’ve browsed through the log and didn’t find any problem now, but probably after the problems with the template started I have deleted the template, re added it, and the entities did not appear in HA at all so maybe that is why logs did not point at this template as faulty? Strange that it worked so long in previous formatting.
Thanks for your input and help.