sender
February 8, 2023, 8:22am
1
Hi, just need some confirmation.help.
I have sensor I use in a template sensor (for energy - strictly increasing ). But it is not always increasing due to some “flaws” .
The original sensor sometimes is “unavailable”:
(envoy_today_gen)
This end up like:
(solar_today_gen)
When I use this template:
solar_today_gen:
unit_of_measurement: 'kWh'
friendly_name: Total Solar Today
device_class: energy
value_template: >
{% set growattodaykwh = states('sensor.growattmodbus_today_gen') | float(0) %}
{% set envoytodaykwh = states('sensor.envoy_today_gen') | float(0) / 1000 %}
{{ [ growattodaykwh + envoytodaykwh, 0 ] | max | round(2) }}
I think I need something like this:
envoy_today_gen_preserved:
value_template: >-
{% if states('sensor.envoy_today_gen') not in ['unknown', 'unavailable'] %}
{{ states('sensor.envoy_today_gen') }}
{% else %}
{{ states('sensor.envoy_today_gen_preserved') }}
{% endif %}
But I don’t know how to “combine” them (syntax wise)…
CChris
(Christoph)
February 8, 2023, 8:39am
2
you should use the “availability” option for your template:
solar_today_gen:
unit_of_measurement: 'kWh'
friendly_name: Total Solar Today
device_class: energy
value_template: >
{% set growattodaykwh = states('sensor.growattmodbus_today_gen') | float(0) %}
{% set envoytodaykwh = states('sensor.envoy_today_gen') | float(0) / 1000 %}
{{ [ growattodaykwh + envoytodaykwh, 0 ] | max | round(2) }}
availability: >
{{ states('sensor.NAME') not in ['unknown', 'unavailable', 'None'] }}
The problem might be, that you need to cover BOTH sensors in your availability check…
I am not sure, if this can be covered…
Other than that:
You could try to solve that with existing UI options…
You might need to check, if you need to change the unit of measurement for the envoy_today_gen within the settings of the sensor
then, you could create a new sensor group where you add both → envoy_today and growattmodbus and use Type=> Sum
the other option would be, to create sensor templates with the correct unit of measurements based on your current “variables”
And then use the sensor group to create the sum.
This should overcome the “availability” issue - if you use the availability on both sensor templates directly
Use the template editor in developer tools to test templates. But along the lines of this for a double sensor availability check (with some spacing so it’s easier to see what it does):
{{
(states('sensor.NAME') not in ['unknown', 'unavailable', 'None'])
and
(states('sensor.NAME2') not in ['unknown', 'unavailable', 'None'])
}}
sender
February 8, 2023, 3:31pm
4
CChris:
then, you could create a new sensor group where you add both → envoy_today and growattmodbus and use Type=> Sum
the other option would be, to create sensor templates with the correct unit of measurements based on your current “variables”
And then use the sensor group to create the sum.
This should overcome the “availability” issue - if you use the availability on both sensor templates directly
Never knew this option! Done and will check! Thank you!
sender
February 10, 2023, 7:04pm
5
Not sure on how to use this…
Something like this? would that take out spike when one of the tow sensors is “not sending a value”?
sensor:
- platform: template
sensors:
solar_today_gen:
unit_of_measurement: 'kWh'
friendly_name: Total Solar Today
device_class: energy
value_template: >
{% set growattodaykwh = states('sensor.growattmodbus_today_gen') | float(0) %}
{% set envoytodaykwh = states('sensor.envoy_today_s_energy_production') | float(0) %}
{{ [ growattodaykwh + envoytodaykwh, 0 ] | max | round(2) }}
availability_template:
{{
(states('sensor.sensor.growattmodbus_today_gen') not in ['unknown', 'unavailable', 'None'])
and
(states('sensor.envoy_today_s_energy_production') not in ['unknown', 'unavailable', 'None'])
}}