flash3d
1
I used this:
template:
- sensor:
- name: 'Daily Consumed Total'
device_class: energy
unit_of_measurement: kWh
state: >
{% if is_number(states('sensor.daily_consumed_low')) and is_number(states('sensor.daily_consumed_high')) %}
{{ (states('sensor.daily_consumed_low') + states('sensor.daily_consumed_high')) | float }}
{% else %}
None
{% endif %}
- name: 'Daily Produced Total'
device_class: energy
unit_of_measurement: kWh
state: >
{% if is_number(states('sensor.daily_produced_low')) and is_number(states('sensor.daily_produced_high')) %}
{{ (states('sensor.daily_produced_low') + states('sensor.daily_produced_high')) | float }}
{% else %}
None
{% endif %}
But sometimes the sensors have a unknown value, how would I ignore this and have an always “working” Daily Consumed Total and Daily Produced Total.
I found some examples here but how would I change the above state?
oalbaf
2
Suggestion. Change
{% if is_number(states(‘sensor.daily_consumed_low’)) and is_number(states(‘sensor.daily_consumed_high’)) %}
to
{% if (states(‘sensor.daily_consumed_low’) != ‘unavailable’) and (states('sensor.daily_consumed_high) != ‘unavailable’) %}
flash3d
3
flash3d
4
Tried your change but getting error:
Invalid config for [template]: invalid template (TemplateSyntaxError: unexpected char ‘‘’ at 14) for dictionary value @ data[‘sensor’][0][‘state’]. Got “{% if (states(‘sensor.daily_consumed_low’) != ‘unavailable’) and (states('sensor.daily_consumed_high) != ‘unavailable’) %}\n {{ (states(‘sensor.daily_consumed_low’) + states(‘sensor.daily_consumed_high’)) | float }}\n {% else %}\n None\n {% endif %}\n \n”. (See /config/configuration.yaml, line 188).
oalbaf
5
Try
{% if (states('sensor.daily_consumed_low') != "unavailable") and (states('sensor.daily_consumed_high') != "unavailable") %}
{{ (states('sensor.daily_consumed_low') + states('sensor.daily_consumed_high')) | float }}
{% else %}
0
{% endif %}
But first I would try to avoid having sensors with ‘unknown value’
You may need to rethink your strategy for extracting the data and I advise you to use Utility Meter - Home Assistant
flash3d
6
Hi, already was using the utility meter but needed the sum of two utility values.
I searched here and solved it by using this:
daily_consumed_total:
friendly_name: "Daily Consumed Total"
device_class: energy
unit_of_measurement: "kWh"
value_template: "{{ states('sensor.daily_consumed_low') |float(0) + states('sensor.daily_consumed_high') | float(0) }}"
daily_produced_total:
friendly_name: "Daily Produced Total"
device_class: energy
unit_of_measurement: "kWh"
value_template: "{{ states('sensor.daily_produced_low') |float(0) + states('sensor.daily_produced_high') | float(0) }}"
Troon
(Troon)
7
That’s because @oalbaf didn’t format the code properly in the first post, and you copied and pasted the “smart quotes”.
oalbaf
8
Certain. Rookie mistake. I have learned for the following contribution. Sorry!