Automation with the help of the sensor average value

Hello everyone,

I have connected the electricity meters in my home in a cascade. I read both meters every 10 seconds with one Tasmota read head each. Within my “configuration.yaml” I have built a sensor which shows me how much electricity the device consumes within the cascade with the help of a division between the two meters.

When I now read out the value, it looks great in the average value (dark blue line):
image

However, as you can see from the graph, the real values (light blue) fluctuate greatly. I would now like to build an automation that kicks in when the appliance requires more than 1KW on average. But how can I do this? Is there a way to use the “average value” in the automation instead of the real value?

You can use Statistics to get the average value of a sensor.

Or you can use ha-average custom component, which I personally find really useful.

2 Likes

Hi zentay42, Hi community team,

I tried both, but I can’t get it running - but I don’t know why. So what I did, inside of the “template” section of the configuration.yaml I’ve create the sensor with the value shown in my first post:

  - sensor:
    # Stromzähler Wärmpumpe Verbrauch
      - name: "Wärmepumpe akt. Verbrauch Kalkuliert"
        unique_id: "WaermepumpeAktVerbrauchCalc"
        unit_of_measurement: 'kWh'
        device_class: "energy"
        state_class: "total_increasing"
        state: >-
            {{ (float(states('sensor.gesamt_verbrauch'))) - (float(states('sensor.hausverbrauch'))) + (float(states('sensor.haus_erzeugung'))) - (float(states('sensor.gesamt_erzeugung'))) | round(1) }}

Afterwards I’ve installed the ha-avargage over HACS and create a “average” and a “statistics” inside the sensor section:

  - platform: average
    name: 'Average Verbrauch'
    entities:
      - sensor.warmepumpe_akt_verbrauch

  - platform: statistics
    name: "Heatpump in last minute"
    entity_id: sensor.warmepumpe_akt_verbrauch
    state_characteristic: average_linear
    sampling_size: 5
    precision: 1

When I have a look now inside my identities I can finde the “average” but this showing the more or less the same value as my sensor. The “statistic” entry I can’t find anywhere inside if my identities section.

Does somebody could help me, what I did wrong?