Hello everyone.
Is it possible to a template sensor to publish two states/values for the same time?
I have a custom energy monitor system that outputs two power sensors that I use to measure the production of a solar system and the power from/for the network (active_power_1 and active_power_2), every 10 seconds.
From these two sensors, I calculate the solar system production, house exporting, house importing, house consuption and power usage from the solar system.
Active power 1
Active power 2
Solar system production
House exporting
House importing
House consuption
Power used from the solar system
The problem lies in the template sensor “House consuption” and in the template sensor “Power used from the solar system”, where as you can see, for the same time, there are two states (those strange vertical lines).
The sensors hierarchy is:
The code is:
# Power from the solar system
casa_eletricidade_potencia_solar:
friendly_name_template: Produção solar
unique_id: 3
icon_template: mdi:white-balance-sunny
value_template: >-
{% if (states('sensor.active_power_1')|int) < 40 %}
{{0}}
{% else %}
{{ (states('sensor.active_power_1')|int) }}
{% endif %}
unit_of_measurement: "W"
# House exporting
casa_eletricidade_potencia_exportacao:
friendly_name_template: Casa a exportar
unique_id: 1
icon_template: mdi:export
value_template: >-
{% if (states('sensor.active_power_2')|int) <= 0 %}
{% if (states('sensor.active_power_2')|int|abs) >= (states('sensor.active_power_1')|int) %}
{{ (states('sensor.active_power_1')|int) }}
{% else %}
{{ (states('sensor.active_power_2')|int|abs) }}
{% endif %}
{% else %}
{{ 0 }}
{% endif %}
unit_of_measurement: "W"
# House importing
casa_eletricidade_potencia_importacao:
friendly_name_template: Casa a importar
unique_id: 2
icon_template: mdi:import
value_template: >-
{% if (states('sensor.active_power_2')|int) <= 0 %}
{{0}}
{% else %}
{{ (states('sensor.active_power_2')|int|abs) }}
{% endif %}
unit_of_measurement: "W"
# House consuming (either from the network or from the solar system)
casa_eletricidade_potencia_consumo:
friendly_name_template: Casa a consumir
unique_id: khj9875fuh
icon_template: mdi:home
value_template: >-
{% if (states('sensor.casa_eletricidade_potencia_importacao')|int) > 0 %}
{{ (states('sensor.casa_eletricidade_potencia_importacao')|int) + (states('sensor.casa_eletricidade_potencia_solar')|int) }}
{% else %}
{{ (states('sensor.casa_eletricidade_potencia_solar')|int) - (states('sensor.casa_eletricidade_potencia_exportacao')|int) }}
{% endif %}
unit_of_measurement: "W"
# Power produced by the solar system that is used in the house
casa_eletricidade_potencia_solar_consumo:
friendly_name_template: Solar para consumo
unique_id: 7sfd8
icon_template: mdi:weather-sunset
value_template: >-
{{ (states('sensor.casa_eletricidade_potencia_solar')|int) - (states('sensor.casa_eletricidade_potencia_exportacao')|int) }}
unit_of_measurement: "W"
From what I have read, when there is a change in state of a sensor, it triggers the next one to update, so I should be seeing only one update every 10 seconds also and not two updates for the same time.
Your help would be very appreciated.
Thank you!