One of the entities periodically becomes unavailable

Looking for a piece of advice regarding an issue with one of the entities (sensors) I’ve created in Home Assistant.

I have 15 smart plugs that measure power consumption and use Zigbee protocol and are connected to HA. I’ve created a /config/sensors.yaml file that combines all 15 smart plugs into one entity called “Active power consumption combined”.

When all 15 plugs are powered everything works fine. But when some of the plugs are offline, the entity behaves weirdly. 50% of the time it is unavailable and shows no data and the other 50% of the time it works fine. Please see attached screenshot for details.

I don’t quite understand what is wrong with my config and why this entity becomes unavailable periodically. Any help is appreciated.

Here is the /config/sensors.yaml file:

# Active consumption combined
- platform: template
  sensors:
    active_consumption_combined:
      friendly_name: 'Active power consumption combined'
      value_template: '{{
      (states.sensor.smart_plug_01_smartenergy_metering.state | float) +
      (states.sensor.smart_plug_02_smartenergy_metering.state | float) +
      (states.sensor.smart_plug_03_smartenergy_metering.state | float) +
      (states.sensor.smart_plug_04_smartenergy_metering.state | float) +
      (states.sensor.smart_plug_05_smartenergy_metering.state | float) +
      (states.sensor.smart_plug_06_smartenergy_metering.state | float) +
      (states.sensor.smart_plug_07_smartenergy_metering.state | float) +
      (states.sensor.smart_plug_08_smartenergy_metering.state | float) +
      (states.sensor.smart_plug_09_smartenergy_metering.state | float) +
      (states.sensor.smart_plug_10_smartenergy_metering.state | float) +
      (states.sensor.smart_plug_11_smartenergy_metering.state | float) +
      (states.sensor.smart_plug_12_smartenergy_metering.state | float) +
      (states.sensor.smart_plug_13_smartenergy_metering.state | float) +
      (states.sensor.smart_plug_14_smartenergy_metering.state | float) +
      (states.sensor.smart_plug_15_smartenergy_metering.state | float)
}}'
      unit_of_measurement: "W"

Here is the /config/configuration.yaml file:

# Loads default set of integrations. Do not remove.
default_config:

# Text to speech
tts:
  - platform: google_translate

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

# My custom sensors
sensor: !include sensors.yaml

If only one of them becomes unavailable the total calc will go wrong, change float to float(0) as it will then provide a 0 as default value.

1 Like

I think it might also be solved just by using a group helper.
Select sensor group, add your entities and for type, choose sum;

Just make sure you have ignore non numeric ticked and you should be good to go.

Then just reference this in your dashboards:

1 Like

Yep, would also do it… not used that before :slight_smile:

Looks like both solutions work perfectly. Thank you for proposing your ideas. Your help is highly appreciated and keeps this community so helpful and friendly☺️