Hey!
So I have had this template working for a while but recently noticed that I was getting negative values on my energy dashboard. After some research, it was suggested that best practice is to add an availability_template:
. It appears the current template reports ‘0’ when the device is unavailable which explains the drops and negative values.
Source: Why an availability template is important for energy template sensors
Anyone know what to add to this template? Perhaps this could be of a starting point?
availability_template: "{{ not is_state('sensor.energy_monitor_instantaneous_demand', 'unknown') }}"
Original Template
template:
- sensor:
- name: "Live Electricity Usage"
unique_id: "live_electricity_total"
unit_of_measurement: "W"
state: "{{ (states('sensor.energy_monitor_instantaneous_demand')|float * 1000 / 2000) | round(0) }}"
state_class: measurement
device_class: power
#availability_template: "{{ not is_state('sensor.energy_monitor_instantaneous_demand', 'unknown') }}"
- name: "Total Electricity Usage"
unique_id: "total_electricity_usage"
unit_of_measurement: "kWh"
state: "{{ (states('sensor.energy_monitor_summation_delivered')|float * 1000 / 2000) | round(2) }}"
state_class: total_increasing
device_class: energy