Baloco
October 8, 2017, 1:40am
1
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.
Hi, I purchased an Aeon Labs Aeotec Z-Wave Smart Switch from amazon in order to track the energy usage of my space heater and to turn it on or off at different times. I’ve spent the last day trying to use the energy monitoring feature while...
Reading time: 1 mins 🕑
Likes: 5 ❤
Have anyone been working on something like this, logging the data to a google spreadsheet could also be an option
Thanks!
1 Like
j.assuncao
(Jorge Assunção)
October 8, 2017, 2:40pm
2
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.
Baloco
October 8, 2017, 11:55pm
3
Thanks, It will be really helpful, never tried something like that before
j.assuncao
(Jorge Assunção)
October 9, 2017, 8:14am
4
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
tompat
October 17, 2017, 11:34am
5
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
brett5150
(Brett )
October 17, 2017, 6:45pm
6
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?
j.assuncao
(Jorge Assunção)
March 14, 2018, 2:22pm
8
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?
j.assuncao
(Jorge Assunção)
March 14, 2018, 2:31pm
10
Just look at the code I’ve posted.
j.assuncao:
value_template: ‘230’
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)
j.assuncao
(Jorge Assunção)
March 14, 2018, 2:54pm
12
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
j.assuncao
(Jorge Assunção)
March 14, 2018, 3:04pm
14
Use an automations that makes the calculation every 60 minutes for watts hour.
irqnet
(Christoph)
March 15, 2018, 7:32am
15
tompat:
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.
Is it possible that you provide the sql query you have used in Grafana to get the values out of the db?
1 Like
tompat
March 15, 2018, 7:50am
16
The top graph is done like this
The bottom one is
1 Like
irqnet
(Christoph)
March 15, 2018, 8:28am
17
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
irqnet
(Christoph)
March 15, 2018, 12:44pm
18
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?
j.assuncao
(Jorge Assunção)
March 15, 2018, 3:32pm
19
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"
irqnet
(Christoph)
March 15, 2018, 4:21pm
20
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