Skip to content

Instantly share code, notes, and snippets.

@pjanuario
Created August 14, 2020 12:53
Show Gist options
  • Save pjanuario/c4f66675df86c5a7ecb0a1be07e16b86 to your computer and use it in GitHub Desktop.
Save pjanuario/c4f66675df86c5a7ecb0a1be07e16b86 to your computer and use it in GitHub Desktop.
Homeassistant Energy View
title: Energia
icon: mdi:transmission-tower
path: energy
background: var(--background-image)
cards:
- type: vertical-stack
cards:
- type: horizontal-stack
cards:
- type: entities
title: Energia Consumida
show_header_toggle: false
entities:
- type: section
label: Dia
- entity: sensor.daily_energy_simple
name: Energia Simples
- entity: sensor.energy_invoice_simple_day
name: Energia Simples
- entity: sensor.daily_energy_fora_de_vazio
name: Energia Hora de Ponta
- entity: sensor.daily_energy_vazio
name: Energia Vazio
- entity: sensor.energy_invoice_bi_day
name: Energia Bi-Horário
- type: section
label: Mês
- entity: sensor.monthly_energy_simple
name: Energia Simples
- entity: sensor.energy_invoice_simple
name: Energia Simples
- entity: sensor.monthly_energy_fora_de_vazio
name: Energia Hora de Ponta
- entity: sensor.monthly_energy_vazio
name: Energia Vazio
- entity: sensor.energy_invoice_bi
name: Energia Bi-Horário
style: |
ha-card {
border: solid 2px var(--primary-color);
- type: vertical-stack
cards:
# Total Power
- type: 'custom:mini-graph-card'
name: Potência Total (24h)
color_thresholds:
- color: '#039BE5'
value: 0
- color: '#0da035'
value: 600
- color: '#e0b400'
value: 1200
- color: '#e45e65'
value: 2400
color_thresholds_transition: hard
entities:
- sensor.power_shellyem_b9e975
- color: 'rgba(0,0,255,1)'
entity: binary_sensor.dark_outside
show_line: false
y_axis: secondary
group: false
hour24: true
hours_to_show: 24
line_width: 4
points_per_hour: 4
show:
extrema: true
fill: fade
icon: true
labels: false
name: true
state: true
state_map:
- label: Dia
value: 'off'
- label: Noite
value: 'on'
style: |
ha-card {
border: solid 2px var(--primary-color);
# Voltage
- type: 'custom:mini-graph-card'
name: Voltagem (24h)
line_color: '#0da035'
entities:
- sensor.voltage_shellyem_b9e975
group: false
hour24: true
hours_to_show: 24
line_width: 4
points_per_hour: 4
show:
extrema: true
fill: fade
icon: true
labels: false
name: true
state: true
style: |
ha-card {
border: solid 2px var(--primary-color);
@pjanuario
Copy link
Author

The view uses mini-graph and use the following sensors:

  • for detecting day/night, since graph is 24h using this day/night makes it easy to identify approximated time of day
  • shelly sensors for voltage and power
  • energy meter sensors
  • template sensor to calculate pricing

Pricing sensor calculation

# Information: https://forum.cpha.pt/t/contabilizar-os-custos-com-energia-electrica/3151
# Explicando os valores:
# 0.1008€/kWh é o custo da energia em vazio
# 0.1875€/kWh é o custo da energia fora de vazio
# 0.1456€/kWh é o custo da energia no tarifário normal
# 0.2292€/dia é o custo de 3.45kVA de potencia contratada
# 3.02€ é a soma das taxas e taxinhas (contribuições audiovisuais e afins)
# 1.23 para obter o valor da fatura com IVA a 23%
- platform: template
  sensors:
    daily_energy_simple:
      value_template: >-
        {{ (float(states.sensor.daily_energy_vazio.state) + float(states.sensor.daily_energy_fora_de_vazio.state)) | round(2) }}
      unit_of_measurement: kWh
      icon_template: mdi:transmission-tower
    monthly_energy_simple:
      value_template: >-
        {{ (float(states.sensor.monthly_energy_vazio.state) + float(states.sensor.monthly_energy_fora_de_vazio.state)) | round(2) }}
      unit_of_measurement: kWh
      icon_template: mdi:transmission-tower
    energy_invoice_bi:
      value_template: >-
        {{ ((float(states.sensor.monthly_energy_vazio.state) * 0.1008  + float(states.sensor.monthly_energy_fora_de_vazio.state) * 0.1875 + now().day * 0.2292 + 3.02 ) * 1.23 ) | round(2) }}
      unit_of_measurement: "€"
      icon_template: mdi:currency-eur
    energy_invoice_simple:
      value_template: >-
        {{ ((float(states.sensor.monthly_energy_vazio.state) * 0.1456  + float(states.sensor.monthly_energy_fora_de_vazio.state) * 0.1456 + now().day * 0.2292 + 3.02 ) * 1.23 ) | round(2) }}
      unit_of_measurement: "€"
      icon_template: mdi:currency-eur
    energy_invoice_bi_day:
      value_template: >-
        {{ ((float(states.sensor.daily_energy_vazio.state) * 0.1008  + float(states.sensor.daily_energy_fora_de_vazio.state) * 0.1875 + now().day * 0.2292 + 3.02 ) * 1.23 ) | round(2) }}
      unit_of_measurement: "€"
      icon_template: mdi:currency-eur
    energy_invoice_simple_day:
      value_template: >-
        {{ ((float(states.sensor.daily_energy_vazio.state) * 0.1456  + float(states.sensor.daily_energy_fora_de_vazio.state) * 0.1456 + now().day * 0.2292 + 3.02 ) * 1.23 ) | round(2) }}
      unit_of_measurement: "€"
      icon_template: mdi:currency-eur

Shelly sensors

I use Shelly EM to monitor the power usage of the entire home, can be replaced by something similar.

- platform: mqtt
  name: power_shellyem_b9e975
  state_topic: "shellies/shellyem-B9E975/emeter/0/power"
  qos: 1
  unit_of_measurement: "W"
  device_class: power

- platform: mqtt
  name: energy_shellyem_b9e975
  state_topic: "shellies/shellyem-B9E975/emeter/0/total"
  value_template: '{{ (value | float /1000)|round(3) }}' # Wh to kWh
  qos: 1
  unit_of_measurement: "kWh"
  icon: mdi:flash

- platform: mqtt
  name: voltage_shellyem_b9e975
  state_topic: "shellies/shellyem-B9E975/emeter/0/voltage"
  qos: 1
  unit_of_measurement: "V"
  icon: mdi:flash

Electricity and utility meter

electricity:
  edp:
    country: Portugal
    operator: EDP
    plan: Bi-horário - ciclo diário

utility_meter:
  daily_energy:
    source: sensor.energy_shellyem_b9e975
    cycle: daily
    tariffs:
      - Fora de Vazio
      - Vazio
  monthly_energy:
    source: sensor.energy_shellyem_b9e975
    cycle: monthly
    tariffs:
      - Fora de Vazio
      - Vazio

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment