Hi I have the following template sensor that I am trying to implement but I can’t get the value of “assigned_value” (see below ) to be assigned to the sensor.
Anyone able to help with this ?
energie_fantome:
friendly_name: Energie Fantome
unit_of_measurement: 'Watt'
value_template: >-
{% set cerbogxacoutwatt = states('sensor.cerbogxacoutwatt') | float(0) %}
{% set cerbogxacinwatt = states('sensor.cerbogxacinwatt') | float(0) %}
{% set cerbogxmppttotal = states('sensor.cerbogxmppttotal') | float(0) %}
{% set cerbogxbatteriewatt = states('sensor.cerbogxbatteriewatt') | float(0) %}
{% if cerbogxbatteriewatt < 0 %}
{% set In_Victron_Total = cerbogxacinwatt+cerbogxmppttotal+(-cerbogxbatteriewatt) %}
{% set assigned_value = In_Victron_Total - cerbogxacoutwatt %}
{% else %}
{% set In_Victron_Total = cerbogxacinwatt+cerbogxmppttotal %}
{% set assigned_value = In_Victron_Total - cerbogxacoutwatt - cerbogxbatteriewatt %}
{% endif %}
@Didgeridrew , thanks for helping me on this, after searching through the forum, I modified my .yaml to the modern template sensor . But even if I modified the code and add {{ assigned_value }} after the {% endif %}, when I look at the entity sensor, (sensor.energie_fantome) there are no value change (i tested the code in the development tools and i can see that the {{ assigned_value }} change and is shown as a return value
name: “energie_fantome”
unit_of_measurement: ‘Watt’
state: >
{% set cerbogxacoutwatt = states(‘sensor.cerbogxacoutwatt’) | float(0) %}
{% set cerbogxacinwatt = states(‘sensor.cerbogxacinwatt’) | float(0) %}
{% set cerbogxmppttotal = states(‘sensor.cerbogxmppttotal’) | float(0) %}
{% set cerbogxbatteriewatt = states(‘sensor.cerbogxbatteriewatt’) | float(0) %}
{% if cerbogxbatteriewatt < 0 %}
{% set In_Victron_Total = cerbogxacinwatt+cerbogxmppttotal+(-cerbogxbatteriewatt) %}
{% set assigned_value = In_Victron_Total - cerbogxacoutwatt %}
{% else %}
{% set In_Victron_Total = cerbogxacinwatt+cerbogxmppttotal %}
{% set assigned_value = In_Victron_Total - cerbogxacoutwatt - cerbogxbatteriewatt %}
{% endif %}
{{ (assigned_value | round(1)) }}