Log monthly and daily readings from Aeon Home Energy Meter

Hi Guys,

I´ve just managed to configure my home energy meter, but I only get the actual readings.

It will be great to to see the energy consumption evolution, and check daily or monthly consumption and costs.

I´ve seen some similar projects for SmartThings, It would be great to have the same for homeassistant.

Have anyone been working on something like this, logging the data to a google spreadsheet could also be an option

Thanks!

1 Like

You can create a couple of automations to publish to MQTT topics, with retain, the values at midnight and at the first day of month. Then create sensor templates that read those topics and subtract from the current values. If you want i can publish mine here.

Thanks, It will be really helpful, never tried something like that before

Hi @Baloco.

First i’ve created an automation to get the total consumption value at midnight:

- alias: 'Grava kWh Diário'
  initial_state: 'on'
  trigger:
    - platform: time
      seconds: '/5'
  condition:
    - condition: template
      value_template: '{{ (as_timestamp( now() ) | timestamp_custom("%Y-%m-%d")) > (as_timestamp(states.sensor.consumo_datahora_diario.state) | timestamp_custom("%Y-%m-%d")) }}'
  action:
    - service: mqtt.publish
      data_template:
        topic: 'home/indoor/sensor/ESP_Energy_Meter_01/kwh_at_midnight'
        retain: true
        payload_template: '{{ states.sensor.consumo_acumulado_kwh.state }}'
    - service: mqtt.publish
      data_template:
        topic: 'home/indoor/sensor/ESP_Energy_Meter_01/kwh_at_midnight_time'
        retain: true
        payload_template: '{{ now() }}'

Then, created another automation to get the total consumption value on the first day of month:

- alias: 'Grava kWh Mensal'
  initial_state: 'on'
  trigger:
    - platform: time
      seconds: '/5'
  condition:
    - condition: template
      value_template: '{{ (as_timestamp( now() ) | timestamp_custom("%m")) > (as_timestamp(states.sensor.consumo_datahora_mensal.state) | timestamp_custom("%m")) }}'
  action:
    - service: mqtt.publish
      data_template:
        topic: 'home/indoor/sensor/ESP_Energy_Meter_01/kwh_at_1st_day_month'
        retain: true
        payload_template: '{{ states.sensor.consumo_acumulado_kwh.state }}'
    - service: mqtt.publish
      data_template:
        topic: 'home/indoor/sensor/ESP_Energy_Meter_01/kwh_at_1st_day_month_time'
        retain: true
        payload_template: '{{ now() }}'

After that, template sensors to do the math:

#### Consumo Diário
    consumption_daily_total_kwh:
      friendly_name: 'Total '
      value_template: '{{ ((states.sensor.consumo_acumulado_kwh.state | float ) - ( states.sensor.consumo_dia_kwh.state | float )) | round(2) }}'
      unit_of_measurement: "kWh"
    consumption_daily_total_euro:
      friendly_name: 'Total '
      value_template: '{{ ((((states.sensor.consumption_daily_total_kwh.state | round (2) ) * (0.1997 | round(2) )) + (0.3616))) | round(2) }}'
      unit_of_measurement: "€"

#### Consumo Mensal
    consumption_monthly_total_kwh:
      friendly_name: 'Total '
      value_template: '{{ ((states.sensor.consumo_acumulado_kwh.state | float ) - ( states.sensor.consumo_mes_kwh.state | float )) | round(2) }}'
      unit_of_measurement: "kWh"
    consumption_monthly_total_euro:
      friendly_name: 'Total '
      value_template: '{{ (((states.sensor.consumption_monthly_total_kwh.state | round (2)) * (0.1997 | round(2) ))) | round (2) }}'
      unit_of_measurement: "€"

And the last step is to create a couple of groups to display the information:

#### Consumos Diários
consumos_diarios:
  name: 'Consumos Diários'
  entities:
    - sensor.consumption_daily_total_kwh
    - sensor.consumption_daily_total_euro

#### Consumos Mensais
consumos_mensais:
  name: 'Consumos Mensais'
  entities:
    - sensor.consumption_monthly_total_kwh
    - sensor.consumption_monthly_total_euro

Hope this helps! Good luck

3 Likes

I’d suggest you log your values to an instance of InfluxDB and plot it out with Grafana.
You can then really make some nice presentation out of the logged data.

Here’s my two graphs, the top one is a moving 24 hour power with 3 phases and the total.
The bottom one is a 7 day graph of consumption per hour and per day.

1 Like

Check out emoncms. I use their free hosted account (you can also host your own locally if you want). They have electric apps already set up that will totalize information for you. I use the emoncms history component for HASS to send my aeon meter data to EmonCMS. Then use EmonCMS inputs/feeds to manipulate the data. Once setup I can see daily, weekly, monthly or even yearly data in a easy to use graph form.

1 Like

How would you do having only the W power. Of course energy is the W per amount of time.

I do have thw W value every 10 seconds, how can I calculate the energy per hour and per day?

You just need to add volts and hertz, the rest is just math! This is what i use:

#### ELECTRICAL CONSUMPTION
  - platform: template
    sensors:
      energy_volt:
        friendly_name: 'Tensão (fixo) '
        value_template: '230'
        unit_of_measurement: "V"
      energy_hertz:
        friendly_name: 'Frequência (fixo) '
        value_template: '50'
        unit_of_measurement: "Hz"
      energy_amp:
        friendly_name: 'Corrente (calc.) '
        value_template: '{{ ((states.sensor.potencia_w.state | int ) / (states.sensor.energy_volt.state | int )) | round (2) }}'
        unit_of_measurement: "A"
      energy_watt:
        friendly_name: 'Potência (real) '
        value_template: '{{ states.sensor.potencia_w.state }}'
        unit_of_measurement: "W"
      energy_power_kwh:
        friendly_name: 'Consumo (real) '
        value_template: '{{ states.sensor.consumo_kwh.state }}'
        unit_of_measurement: "kWh"
      energy_power_wh:
        friendly_name: 'Consumo (real) '
        value_template: '{{ (states.sensor.consumo_kwh.state | round(3)) * 1000 }}'
        unit_of_measurement: "Wh"
      energy_apparent_power:
        friendly_name: 'Potência Aparente (calc.) '
        value_template: '{{ (((states.sensor.energy_amp.state | float) * (states.sensor.energy_volt.state | int)) / 1000) | round (3) }}'
        unit_of_measurement: "kVA"

#### DAILY CONSUMPTION
      consumption_daily_total_kwh:
        friendly_name: 'Total '
        value_template: '{{ ((states.sensor.consumo_acumulado_kwh.state | float ) - ( states.sensor.consumo_dia_kwh.state | float )) | round(2) }}'
        unit_of_measurement: "kWh"
      consumption_daily_total_euro:
        friendly_name: 'Total '
        value_template: '{{ ((((states.sensor.consumption_daily_total_kwh.state | float) * 0.1997) + (0.3616)) | round (2)) }}'
        unit_of_measurement: "€"
      consumption_daily_total_kwh_fora_de_vazio:
        friendly_name: 'Fora de Vazio '
        value_template: '- - -'
        unit_of_measurement: "kWh"
      consumption_daily_total_kwh_vazio:
        friendly_name: 'Vazio '
        value_template: '- - -'
        unit_of_measurement: "kWh"

#### MONTHLY CONSUMPTION
      consumption_monthly_total_kwh:
        friendly_name: 'Total '
        value_template: '{{ ((states.sensor.consumo_acumulado_kwh.state | float ) - ( states.sensor.consumo_mes_kwh.state | float )) | round(2) }}'
        unit_of_measurement: "kWh"
      consumption_monthly_total_euro:
        friendly_name: 'Total '
        value_template: '{{ ((((states.sensor.consumption_monthly_total_kwh.state | float) * 0.1997) + (0.3616)) | round (2)) }}'
        unit_of_measurement: "€"
      consumption_monthly_total_kwh_fora_de_vazio:
        friendly_name: 'Fora de Vazio '
        value_template: '- - -'
        unit_of_measurement: "kWh"
      consumption_monthly_total_kwh_vazio:
        friendly_name: 'Vazio '
        value_template: '- - -'
        unit_of_measurement: "kWh"

#### TOTALIZER
      consumption_total_kwh:
        friendly_name: 'Total '
        value_template: '{{ states.sensor.consumo_acumulado_kwh.state }}'
        unit_of_measurement: "kWh"
      consumption_total_euro:
        friendly_name: 'Total '
        value_template: '{{ (((states.sensor.consumption_total_kwh.state | float) * (0.1997 )) | round(2)) }}'
        unit_of_measurement: "€"
      consumption_total_fora_de_vazio:
        friendly_name: 'Fora de Vazio '
        value_template: '- - -'
        unit_of_measurement: "kWh"
      consumption_total_vazio:
        friendly_name: 'Vazio '
        value_template: '- - -'
        unit_of_measurement: "kWh"

yes I have W (potencia) reading every 10 seconds, how can I turn that into hourly/daily energy reading?

Just look at the code I’ve posted.

sorry I do not get it. You make calculation from power to current (W to A), but it seems you already have a sensor for the energy (kwh).

I have the sensor of the power (w every 10 sec), and need to calculate the value of the energy (wh)

Just do the math. A simple google search gives watt-hour = watts × hours

I used google and did not find the solution on how to have E=WxH from having W every 10 seconds in HA.

Thanks anyway

Use an automations that makes the calculation every 60 minutes for watts hour.

Is it possible that you provide the sql query you have used in Grafana to get the values out of the db?

1 Like

The top graph is done like this

The bottom one is

1 Like

thx! it seems to be a bit different for me, because I’m using a mariadb on my synology. I’m not familiar with sql statemens so it’s hard to figure out what I have to change.

Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '"W" WHERE "entity_id"='sensor.stromzaehler_power' AND $timeFilter GROUP BY time(' at line 1

It’s the first time playing around with the templating sensors. Are those couple of sensors you are using:

sensor.consumo_datahora_diario
sensor.consumo_acumulado_kwh.state
sensor.consumo_datahora_mensal

etc. automaticaly added by the energy meter you are using? or have they been created using the value template?

It’s done with automations and sensors.

################################################################################
#### AUTOMATIONS
################################################################################

automation:

#### SAVE DAILY TOTAL
  - alias: 'Grava kWh Diário'
    initial_state: 'on'
    trigger:
      - platform: time
        seconds: '/5'
    condition:
      - condition: template
        value_template: '{{ (as_timestamp( now() ) | timestamp_custom("%Y-%m-%d")) > (as_timestamp(states.sensor.consumo_datahora_diario.state) | timestamp_custom("%Y-%m-%d")) }}'
    action:
      - service: mqtt.publish
        data_template:
          topic: 'home/indoor/sensor/MAID-EM-01/kwh_at_midnight'
          retain: true
          payload_template: '{{ states.sensor.consumo_acumulado_kwh.state }}'
      - service: mqtt.publish
        data_template:
          topic: 'home/indoor/sensor/MAID-EM-01/kwh_at_midnight_time'
          retain: true
          payload_template: '{{ now() }}'
      - service: script.notify_save_to_file
        data:
          message: '{{ as_timestamp (now()) | timestamp_custom("%d/%b/%Y %T") }} - kWh Diários - GRAVADO'

#### SAVE MONTHLY TOTAL
  - alias: 'Grava kWh Mensal'
    initial_state: 'on'
    trigger:
      - platform: time
        seconds: '/5'
    condition:
      - condition: template
        value_template: '{{ (as_timestamp( now() ) | timestamp_custom("%m")) != (as_timestamp(states.sensor.consumo_datahora_mensal.state) | timestamp_custom("%m")) }}'
    action:
      - service: mqtt.publish
        data_template:
          topic: 'home/indoor/sensor/MAID-EM-01/kwh_at_1st_day_month'
          retain: true
          payload_template: '{{ states.sensor.consumo_acumulado_kwh.state }}'
      - service: mqtt.publish
        data_template:
          topic: 'home/indoor/sensor/MAID-EM-01/kwh_at_1st_day_month_time'
          retain: true
          payload_template: '{{ now() }}'
      - service: script.notify_save_to_file
        data:
          message: '{{ as_timestamp (now()) | timestamp_custom("%d/%b/%Y %T") }} - kWh Mensais - GRAVADO'


################################################################################
#### SENSORS
################################################################################

sensor:

#### READINGS
  - platform: mqtt
    name: "Potência (W)"
    state_topic: "home/indoor/sensor/MAID-EM-01/watt"
    unit_of_measurement: "W"
  - platform: mqtt
    name: "Consumo (kWh)"
    state_topic: "home/indoor/sensor/MAID-EM-01/kwh"
    unit_of_measurement: "kWh"
  - platform: mqtt
    name: "Consumo Acumulado (kWh)"
    state_topic: "home/indoor/sensor/MAID-EM-01/pulse"
    unit_of_measurement: "kWh"

#### TOTALIZERS
  - platform: mqtt
    name: "Consumo dia (kWh)"
    state_topic: "home/indoor/sensor/MAID-EM-01/kwh_at_midnight"
    unit_of_measurement: "kWh"
  - platform: mqtt
    name: "Consumo mês (kWh)"
    state_topic: "home/indoor/sensor/MAID-EM-01/kwh_at_1st_day_month"
    unit_of_measurement: "kWh"
  - platform: mqtt
    name: "Consumo data/hora Diário"
    state_topic: "home/indoor/sensor/MAID-EM-01/kwh_at_midnight_time"
  - platform: mqtt
    name: "Consumo data/hora Mensal"
    state_topic: "home/indoor/sensor/MAID-EM-01/kwh_at_1st_day_month_time"

so the values you are using are published to mqtt by your powermeter?

home/indoor/sensor/MAID-EM-01/watt
home/indoor/sensor/MAID-EM-01/kwh
home/indoor/sensor/MAID-EM-01/pulse