mirror of
https://github.com/home-assistant/home-assistant.io.git
synced 2025-07-19 07:17:14 +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
|
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
|
||||||
value_template: "{{ states('sensor.daily_energy_offpeak')|float + states('sensor.daily_energy_peak')|float }}"
|
state: >
|
||||||
monthly_energy:
|
{% if is_number(states('sensor.daily_energy_offpeak')) and is_number(states('sensor.daily_energy_peak')) %}
|
||||||
friendly_name: Monthly Energy
|
{{ (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
|
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 %}
|
{% endraw %}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user