mirror of
https://github.com/home-assistant/home-assistant.io.git
synced 2025-07-19 15:26:59 +00:00
updating utility_meter example to use new template format (#19826)
Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
parent
8930212454
commit
ea6dd73836
@ -226,22 +226,34 @@ utility_meter:
|
||||
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 %}
|
||||
|
||||
```yaml
|
||||
sensor:
|
||||
- platform: template
|
||||
sensors:
|
||||
daily_energy:
|
||||
friendly_name: Daily Energy
|
||||
template:
|
||||
- sensor:
|
||||
- name: 'Daily Energy Total'
|
||||
device_class: energy
|
||||
unit_of_measurement: kWh
|
||||
value_template: "{{ states('sensor.daily_energy_offpeak')|float + states('sensor.daily_energy_peak')|float }}"
|
||||
monthly_energy:
|
||||
friendly_name: Monthly Energy
|
||||
state: >
|
||||
{% if is_number(states('sensor.daily_energy_offpeak')) and is_number(states('sensor.daily_energy_peak')) %}
|
||||
{{ (states('sensor.daily_energy_offpeak') + states('sensor.daily_energy_peak')) | float }}
|
||||
{% else %}
|
||||
None
|
||||
{% endif %}
|
||||
|
||||
- name: 'Monthly Energy Total'
|
||||
device_class: energy
|
||||
unit_of_measurement: kWh
|
||||
value_template: "{{ states('sensor.monthly_energy_offpeak')|float + states('sensor.monthly_energy_peak')|float }}"
|
||||
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 %}
|
||||
|
Loading…
x
Reference in New Issue
Block a user