Issue with power sensor

Hi.

I just ran an upgrade from 2021.9.5 to 2021.9.7.

I have no whole-of-house power monitoring, so I simply have a sensor that adds up all my power-monitoring plugs and lights.

As of today, this happened (pic) and so my energy monitoring thinks I’ve used 2816kwh today :scream:

  1. Is there any way I can correct these stats by wiping out the zero.
  2. Any idea how this happened and how I can prevent it happening again?

Sensor code:

    - name: "total_power"
      unit_of_measurement: "kWh"
      state: >
        {% set myvalue = states('sensor.bathroom_light_energy_meter') | float %}
        {% set myvalue = myvalue + states('sensor.bedroom_light_energy_meter') | float  %}
        {% set myvalue = myvalue + states('sensor.daniel_s_light_energy_meter') | float  %}
        {% set myvalue = myvalue + states('sensor.dryer_energy_meter') | float  %}
        {% set myvalue = myvalue + states('sensor.fryer_energy_meter') | float  %}
        {% set myvalue = myvalue + states('sensor.hall_light_energy_meter') | float  %}
        {% set myvalue = myvalue + states('sensor.lounge_light_energy_meter') | float  %}
        {% set myvalue = myvalue + states('sensor.mirror_lights_energy_meter') | float  %}
        {% set myvalue = myvalue + states('sensor.washing_machine_energy_meter_x') | float  %} 
        {{myvalue |round(2)}}

Thanks
cropped Screenshot from 2021-10-04 14-59-42

Start by finding out which of your energy meter(s) suddenly give aberrant values.

since the value is 0, the issue is with either all the sensors or with the total_power sensor itself. Since this occurred during a reboot is it possible that the sensors were not yet available when total_power was computed?

Regards

Ah, I misunderstood the issue.

Quite likely. | float on a string like “unavailable” will return 0.0

I can’t guarantee that this will fix the problem but, at the very least, it will make your Template Sensor a bit neater and more robust.

Create a group containing all of the energy_meter sensors.

group:
  energy_meters:
    name: All Energy Meters
    entities:
      - sensor.bathroom_light_energy_meter
      - sensor.bedroom_light_energy_meter
      - sensor.daniel_s_light_energy_meter
      - sensor.dryer_energy_meter
      - sensor.fryer_energy_meter
      - sensor.hall_light_energy_meter
      - sensor.lounge_light_energy_meter
      - sensor.mirror_lights_energy_meter
      - sensor.washing_machine_energy_meter_x

The group can be used to simplify the state template and to create an availability option.

    - name: "total_power"
      unit_of_measurement: "kWh"
      state: "{{ expand('group.energy_meters') | map(attribute='state') | map('float') | sum | round(2) }}"
      availability: >
        {{ expand('group.energy_meters') | rejectattr('state', 'in', ['unavailable', 'unknown']) | list | count
            == expand('group.energy_meters') | list | count }}

The availability template simply computes the total number of sensors in the group and compares it to the number of sensors whose state is not unavailable or unknown. If the two don’t match then it means some of the group’s sensors have no value and the template should not perform its calculation.

3 Likes

Superbly brilliant !