A YAML script that supplements the HACS SolarEdge Modbus feature and data feed to allow the Energy Dashboard to monitor the SolarEdge Solar and Battery, if you have two of them like I do.
Configuration YAML
solaredge.yaml
template:
- sensor:
- name: solaredge_battery_charge_power
unit_of_measurement: kW
device_class: power
state: >
{% if states('sensor.solaredge_status') | int(0) > 0 %}
{% if states("sensor.solaredge_battery1_status") == "Charging" and states('sensor.solaredge_status') | int(0) == 4 %}
{% set charge = ((states("sensor.solaredge_battery1_power") | float(0) + states("sensor.solaredge_battery2_power") | float(0)) / 1000) %}
{% if charge > 0 %}
{{ charge | round(2) }}
{% else %}
0
{% endif %}
{% else %}
0
{% endif %}
{% else %}
0
{% endif %}
icon: mdi:power-plug-battery
- name: solaredge_battery_discharge_power
unit_of_measurement: kW
device_class: power
state: >
{% if states('sensor.solaredge_status') | int(0) > 0 %}
{% if states("sensor.solaredge_battery1_status") == "Discharging" and states('sensor.solaredge_status') | int(0) == 4 %}
{% set discharge = ((states("sensor.solaredge_battery1_power") | float(0) + states("sensor.solaredge_battery2_power") | float(0)) * -1 / 1000) %}
{% if discharge > 0 %}
{{ discharge | round(2) }}
{% else %}
0
{% endif %}
{% else %}
0
{% endif %}
{% else %}
0
{% endif %}
icon: mdi:power-plug
- name: solaredge_solar_production_power
unit_of_measurement: kW
device_class: power
state: >
{% if states('sensor.solaredge_status') | int(0) > 0 %}
{% if states('sun.sun') == 'above_horizon' and states('sensor.solaredge_status') | int(0) == 4 %}
{% set pv = (states("sensor.solaredge_dc_power") | float(0) / 1000) %}
{% set depletion = states("sensor.solaredge_battery_discharge_power") | float(0) %}
{% set charge = states("sensor.solaredge_battery_charge_power") | float(0) %}
{% set net = pv - depletion + charge %}
{% if net > 0.003 %}
{{ net | round(2) }}
{% else %}
0
{% endif %}
{% else %}
0
{% endif %}
{% else %}
0
{% endif %}
icon: mdi:solar-power
- name: solaredge_consumption_power
unit_of_measurement: kW
device_class: power
state: >
{% if states('sensor.solaredge_status') | int(0) > 0 %}
{% set consumption = ( states('sensor.solaredge_ac_power') | float(0) / 1000 ) + ( states("sensor.solaredge_m1_ac_power") | float(0) * -1 / 1000 ) %}
{% if consumption > 0.003 %}
{{ consumption | round(2) }}
{% else %}
{{ states('sensor.solaredge_consumption_power') }}
{% endif %}
{% else %}
{{ states('sensor.solaredge_consumption_power') }}
{% endif %}
icon: mdi:flash
- name: solaredge_grid_consumption_power
unit_of_measurement: kW
device_class: power
state: >
{% if states('sensor.solaredge_status') | int(0) > 0 %}
{% set grid = (states('sensor.solaredge_m1_ac_power') | float(0) * -1 / 1000 ) %}
{% if grid > 0.003 %}
{{ grid | round(2) }}
{% else %}
0
{% endif %}
{% else %}
{{ states('sensor.solaredge_grid_consumption_power') }}
{% endif %}
icon: mdi:transmission-tower-export
- name: solaredge_battery_charge
unit_of_measurement: "%"
device_class: battery
state: >
{% if states('sensor.solaredge_status') | int(0) > 0 %}
{% if states('sensor.solaredge_battery1_state_of_charge') | is_number %}
{{ ( (states("sensor.solaredge_battery1_state_of_charge") | float(0) + states("sensor.solaredge_battery2_state_of_charge") | float(0) ) / 2) | round(1) }}
{% else %}
{{ states('sensor.solaredge_battery_charge') }}
{% endif %}
{% else %}
{{ states('sensor.solaredge_battery_charge') }}
{% endif %}
- name: solaredge_inverter_status
state: >
{% if states('sensor.solaredge_status') | int(0) == 1 %}
Off
{% elif states('sensor.solaredge_status') | int(0) == 2 %}
Night Mode
{% elif states('sensor.solaredge_status') | int(0) == 3 %}
Starting
{% elif states('sensor.solaredge_status') | int(0) == 4 %}
Normal
{% elif states('sensor.solaredge_status') | int(0) == 5 %}
Throttled
{% elif states('sensor.solaredge_status') | int(0) == 6 %}
Shutting Down
{% elif states('sensor.solaredge_status') | int(0) == 7 %}
Fault
{% elif states('sensor.solaredge_status') | int(0) == 8 %}
Maintenance
{% else %}
Unknown
{% endif %}
icon: mdi:generator-stationary
sensor:
- platform: integration
source: sensor.solaredge_battery_charge_power
name: solaredge_battery_charge_kwh
unit_time: h
method: left
round: 2
- platform: integration
source: sensor.solaredge_battery_discharge_power
name: solaredge_battery_discarge_kwh
unit_time: h
method: left
round: 2
- platform: integration
source: sensor.solaredge_solar_production_power
name: solaredge_solar_production_kwh
unit_time: h
method: left
round: 2
- platform: integration
source: sensor.solaredge_consumption_power
name: solaredge_consumption_kwh
unit_time: h
method: left
round: 2
utility_meter:
solaredge_battery_charge_kwh_daily:
source: sensor.solaredge_battery_charge_kwh
cycle: daily
solaredge_battery_discarge_kwh_daily:
source: sensor.solaredge_battery_discarge_kwh
cycle: daily
solaredge_solar_production_kwh_daily:
source: sensor.solaredge_solar_production_kwh
cycle: daily
solaredge_consumption_kwh_daily:
source: sensor.solaredge_consumption_kwh
cycle: daily
solaredge_import_kwh_daily:
source: sensor.solaredge_m1_imported_a_kwh
cycle: daily
solaredge_export_kwh_daily:
source: sensor.solaredge_m1_exported_kwh
cycle: daily
homeassistant:
customize:
sensor.solaredge_battery_charge_power:
friendly_name: "SolarEdge Battery Charge Power"
unit_of_measurement: kW
device_class: power
sensor.solaredge_battery_discharge_power:
friendly_name: "SolarEdge Battery Discharge Power"
unit_of_measurement: kW
device_class: power
sensor.solaredge_solar_production_power:
friendly_name: "SolarEdge Solar Production Power"
unit_of_measurement: kW
device_class: power
sensor.solaredge_consumption_power:
friendly_name: "Household Consumption Power"
unit_of_measurement: kW
device_class: power
sensor.solaredge_grid_consumption_power:
friendly_name: "SolarEdge Grid Consumption Power"
unit_of_measurement: kW
device_class: power
sensor.solaredge_battery_charge:
friendly_name: "SolarEdge Battery Charge"
unit_of_measurement: "%"
device_class: battery
sensor.solaredge_inverter_status:
friendly_name: "SolarEdge Inverter Status"
sensor.solaredge_battery_charge_kwh:
friendly_name: "SolarEdge Battery Charge Energy"
unit_of_measurement: kWh
device_class: energy
sensor.solaredge_battery_discarge_kwh:
friendly_name: "SolarEdge Battery Discharge Energy"
unit_of_measurement: kWh
device_class: energy
sensor.solaredge_solar_production_kwh:
friendly_name: "SolarEdge Solar Production Energy"
unit_of_measurement: kWh
device_class: energy
sensor.solaredge_consumption_kwh:
friendly_name: "Household Consumption Energy"
unit_of_measurement: kWh
device_class: energy
sensor.solaredge_battery_charge_kwh_daily:
friendly_name: "SolarEdge Battery Charge Energy (Daily)"
unit_of_measurement: kWh
device_class: energy
sensor.solaredge_battery_discarge_kwh_daily:
friendly_name: "SolarEdge Battery Discharge Energy (Daily)"
unit_of_measurement: kWh
device_class: energy
sensor.solaredge_solar_production_kwh_daily:
friendly_name: "SolarEdge Solar Production Energy (Daily)"
unit_of_measurement: kWh
device_class: energy
sensor.solaredge_consumption_kwh_daily:
friendly_name: "Household Consumption Energy (Daily)"
unit_of_measurement: kWh
device_class: energy
sensor.solaredge_import_kwh_daily:
friendly_name: "SolarEdge Electricity Import Energy (Daily)"
unit_of_measurement: kWh
device_class: energy
sensor.solaredge_export_kwh_daily:
friendly_name: "SolarEdge Electricity Export Energy (Daily)"
unit_of_measurement: kWh
device_class: energy
group:
solaredge:
name: SolarEdge
entities:
- sensor.solaredge_battery_charge_power
- sensor.solaredge_battery_discharge_power
- sensor.solaredge_solar_production_power
- sensor.solaredge_consumption_power
- sensor.solaredge_grid_consumption_power
- sensor.solaredge_battery_charge
- sensor.solaredge_inverter_status
- sensor.solaredge_battery_charge_kwh
- sensor.solaredge_battery_discarge_kwh
- sensor.solaredge_solar_production_kwh
- sensor.solaredge_consumption_kwh
- sensor.solaredge_battery_charge_kwh_daily
- sensor.solaredge_battery_discarge_kwh_daily
- sensor.solaredge_solar_production_kwh_daily
- sensor.solaredge_consumption_kwh_daily
- sensor.solaredge_import_kwh_daily
- sensor.solaredge_export_kwh_daily
Dashboard Code
Dashboard Code
type: vertical-stack
cards:
- type: markdown
content: <h1>Solar</h1>
- show_name: true
show_icon: true
show_state: true
type: glance
entities:
- entity: sensor.solaredge_inverter_status
name: Status
icon: mdi:generator-stationary
- entity: sensor.solaredge_solar_production_power
name: Panels
icon: mdi:solar-power
- entity: sensor.solaredge_grid_consumption_power
name: Grid
icon: mdi:transmission-tower-export
- entity: sensor.solaredge_consumption_power
name: Consumption
state_color: false
- type: glance
entities:
- entity: sensor.solaredge_battery_charge_power
name: Charge
icon: mdi:power-plug-battery
- entity: sensor.solaredge_battery_charge
name: Level
- entity: sensor.solaredge_battery_discharge_power
name: Discharge
icon: mdi:power-plug
Energy Dashboard
You can now proceed to add a refined collection of sensors to the Energy Dashboard to track your energy usage over time.
| Energy Dashboard Config | Sensor Name |
|---|---|
| Grid Consumption | SolarEdge Electricity Import Energy (Daily) |
| Return to grid | SolarEdge Electricity Export Energy (Daily) |
| Solar production | SolarEdge Solar Production Energy (Daily) |
| Battery systems | SolarEdge Battery Charge Energy (Daily) SolarEdge Battery Discharge Energy (Daily) |
