updating utility_meter example to use new template format (#19826)

Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
Chris Turra 2021-10-26 10:40:53 -07:00 committed by GitHub
parent 8930212454
commit ea6dd73836
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -226,22 +226,34 @@ utility_meter:
cycle: monthly cycle: monthly
``` ```
Additionally, you can add template sensors to compute daily and monthly total usage. Additionally, you can add template sensors to compute daily and monthly total usage. Important note, in these examples,
we use the `is_number()` [function](/docs/configuration/templating/#numeric-functions-and-filters) to verify the values
returned from the sensors are numeric. If this evalutes to false, `None` is returned.
{% raw %} {% raw %}
```yaml ```yaml
sensor: template:
- platform: template - sensor:
sensors: - name: 'Daily Energy Total'
daily_energy: device_class: energy
friendly_name: Daily Energy unit_of_measurement: kWh
unit_of_measurement: kWh state: >
value_template: "{{ states('sensor.daily_energy_offpeak')|float + states('sensor.daily_energy_peak')|float }}" {% if is_number(states('sensor.daily_energy_offpeak')) and is_number(states('sensor.daily_energy_peak')) %}
monthly_energy: {{ (states('sensor.daily_energy_offpeak') + states('sensor.daily_energy_peak')) | float }}
friendly_name: Monthly Energy {% else %}
unit_of_measurement: kWh None
value_template: "{{ states('sensor.monthly_energy_offpeak')|float + states('sensor.monthly_energy_peak')|float }}" {% endif %}
- name: 'Monthly Energy Total'
device_class: energy
unit_of_measurement: kWh
state: >
{% if is_number(states('sensor.monthly_energy_offpeak')) and is_number(states('sensor.monthly_energy_peak')) %}
{{ (states('sensor.monthly_energy_offpeak') + states('sensor.monthly_energy_peak')) | float }}
{% else %}
None
{% endif %}
``` ```
{% endraw %} {% endraw %}