Hello,
I have a small issue with the utility meter I created to track and group my power consumption.
setup:
I have several energy mqtt sensor (one per light) and I sum them all with a template sensor.
I created a utility meter on the template sensor, to track the daily consumption.
The problem is, in some cases the mqtt sensor has a GAP, the cap generates a 0 point in my template and this creates a huge step up in my meter…
Any suggestion on how to solve this?
Thanks!
Code example
sensor:
- platform: mqtt
name: 'light1'
unique_id: 'MAC_e1'
qos: 1
state_topic: 'dingz/MAC/dz1f-pir/energy/light/1'
device_class: energy
state_class: total_increasing
unit_of_measurement: 'Wh'
value_template: >
{% if value == 0 %}
{{ states('sensor.light1') }}
{% else %}
{{ value | float / 3600 }}
{% endif %}
icon: mdi:lightning-bolt
template:
- sensor:
- name: "Lights Energy"
state: >
{{
(
states('sensor.light1')| float(0) +
states('sensor.light2')| float(0)
)|float(0)|round(2)
}}
state_class: total
device_class: energy
unit_of_measurement: "Wh"
unique_id: template.sensor_energy_lights
utility_meter:
energy:
name: Light Daily
source: sensor.lights_energy
cycle: daily