binsentsu / home-assistant-solaredge-modbus

Home assistant Component for reading data locally from Solaredge inverter through modbus TCP
293 stars 71 forks source link

Does anybody have this working with Tesla Style Solar Power Card? #55

Closed LukePrior closed 3 years ago

LukePrior commented 3 years ago

Hi,

I have configured this integration and can see the values in the energy dashboard however I want to setup a live view with the Tesla Style Power card. I have run into difficulties in finding what values to use and what templating is necessary. I would appreciate if anyone who has these two things setup and working correctly could post their configuration details.

I think @mpredfearn has this working looking at previous posts.

EDIT:

This configuration worked for me with a simple system with no battery.

Tesla Card:

type: custom:tesla-style-solar-power-card
house_entity: sensor.power_consumption
grid_entity: sensor.solaredge_m1_ac_power
generation_entity: sensor.solaredge_ac_power
grid_to_house_entity: sensor.power_grid_import
generation_to_grid_entity: sensor.power_grid_export
generation_to_house_entity: sensor.power_self_consumption

Template:

sensor:                                                                         
  - platform: template                                                          
    sensors:
      power_grid_import:                                                    
        friendly_name: "Power - Grid Import"                                    
        unit_of_measurement: "W"                                                
        value_template: "{{ (states('sensor.solaredge_m1_ac_power') | float | min(0) | abs()) }}"
      power_grid_export:                                                     
        friendly_name: "Power - Grid Export"                                    
        unit_of_measurement: "W"                                                
        value_template: "{{ states('sensor.solaredge_m1_ac_power') | float | max(0) | abs() }}"                                                                                                                                                   
      power_consumption:                                                  
        friendly_name: "Power - Consumption"                                    
        unit_of_measurement: "W"                                                
        value_template: "{{ (states('sensor.solaredge_ac_power') | float | max(0)) - (states('sensor.solaredge_m1_ac_power') | float) }}"
      power_self_consumption:                                            
        friendly_name: "Power - Self Consumption"                               
        unit_of_measurement: "W"                                                
        value_template: "{{ (states('sensor.solaredge_ac_power') | float | max(0)) - states('sensor.power_grid_export') | float}}"     
mpredfearn commented 3 years ago

Hey @LukePrior yeah I've got this working... It's not pretty (a lot of hacky templated sensors) - and I'm still working on improving things - but that's where my system is right now and I'm fairly pleased with it.

Screenshot_2021-10-08_09-51-40

And with the energy dashboard: Screenshot_2021-10-08_09-52-48

My Tesla card is configured like this:

type: custom:tesla-style-solar-power-card
name: Power Flow
energy_flow_diagramm: 1
change_house_bubble_color_with_flow: 1
house_entity: sensor.power_consumption
grid_entity: sensor.solaredge_modbus_m1_ac_power
generation_entity: sensor.power_solar_generation
battery_entity: sensor.solaredge_modbus_battery1_power
battery_extra_entity: sensor.solaredge_modbus_battery1_state_of_charge
grid_to_house_entity: sensor.power_grid_import
grid_to_battery_entity: sensor.power_battery_charging_ac
generation_to_grid_entity: sensor.power_grid_export
generation_to_house_entity: sensor.power_self_consumption
generation_to_battery_entity: sensor.power_battery_charging_solar
battery_to_house_entity: sensor.power_battery_discharging
appliance1_consumption_entity: sensor.evcharger_power
appliance1_extra_entity: sensor.audi_e_tron_state_of_charge

My energy dashboard like this: Screenshot_2021-10-08_09-55-41

Finally my templated sensors are:

sensor:                                                                         
  - platform: template                                                          
    sensors:  
      power_battery_charging:                                                   
        friendly_name: "Power - Battery Charging"                               
        unit_of_measurement: "W"                                                
        value_template: "{{ (states('sensor.solaredge_modbus_battery1_power') | float | max(0) | abs()) }}"
      power_battery_discharging:                                                
        friendly_name: "Power - Battery Discharging"                            
        unit_of_measurement: "W"                                                
        value_template: "{{ states('sensor.solaredge_modbus_battery1_power') | float | min(0) | abs() }}"
      power_battery_charging_ac:                                                
        friendly_name: "Power - Battery Charging from AC"                       
        unit_of_measurement: "W"                                                
        value_template: "{{ states('sensor.solaredge_modbus_i1_ac_power') | float | min(0) | abs() }}"
      power_battery_charging_solar:                                             
        friendly_name: "Power - Battery Charging from Solar"                    
        unit_of_measurement: "W"                                                
        value_template: "{{ (states('sensor.power_battery_charging') | float) - (states('sensor.power_battery_charging_ac') | float) }}"

      power_grid_import:                                                        
        friendly_name: "Power - Grid Import"                                    
        unit_of_measurement: "W"                                                
        value_template: "{{ (states('sensor.solaredge_modbus_m1_ac_power') | float | min(0) | abs()) - (states('sensor.power_battery_charging_ac') | float) }}"
      power_grid_export:                                                        
        friendly_name: "Power - Grid Export"                                    
        unit_of_measurement: "W"                                                
        value_template: "{{ states('sensor.solaredge_modbus_m1_ac_power') | float | max(0) | abs() }}"

      power_solar_generation:                                                   
        friendly_name: "Power - Solar Generation"                               
        unit_of_measurement: "W"                                                
        value_template: "{{ (states('sensor.solaredge_modbus_i1_ac_power') | float | max(0)) + (states('sensor.power_battery_charging_solar') | float) - (states('sensor.power_battery_discharging') | float) }}"

      power_consumption:                                                        
        friendly_name: "Power - Consumption"                                    
        unit_of_measurement: "W"                                                
        value_template: "{{ (states('sensor.solaredge_modbus_i1_ac_power') | float | max(0)) - (states('sensor.solaredge_modbus_m1_ac_power') | float) }}"
      power_self_consumption:                                                   
        friendly_name: "Power - Self Consumption"                               
        unit_of_measurement: "W"                                                
        value_template: "{{ (states('sensor.solaredge_modbus_i1_ac_power') | float | max(0)) - (states('sensor.power_battery_discharging') | float) - states('sensor.power_grid_export') | float}}"

      energy_solar_generation:                                                  
        friendly_name: "Energy - Solar Generation"                              
        unit_of_measurement: "kWh"                                              
        value_template: "{{ (states('sensor.solaredge_modbus_i1_ac_energy_kwh') | float) - (states('sensor.energy_battery_discharged') | float) + (states('sensor.energy_battery_charged_solar') | float) }}"
        availability_template: "{{ states('sensor.solaredge_modbus_i1_ac_energy_kwh') not in ['unknown', 'unavailable'] }}"

  - platform: integration                                                       
    name: energy_battery_charged                                                
    source: sensor.power_battery_charging                                       
    method: left                                                                
    unit_prefix: k                                                              
  - platform: integration                                                       
    name: energy_battery_charged_solar                                          
    source: sensor.power_battery_charging_solar                                 
    method: left                                                                
    unit_prefix: k                                                              
  - platform: integration                                                       
    name:  energy_battery_discharged                                            
    source: sensor.power_battery_discharging                                    
    method: left                                                                
    unit_prefix: k    

With the following hacks to change a couple of sensors into device class energy and state class total increasing:

homeassistant:                                                                                                       
  customize_glob:                                                               
    sensor.energy_solar_generation:                                             
      device_class: energy                                                      
      state_class: total_increasing                                             
    sensor.energy_battery_charged:                                              
      device_class: energy                                                      
    sensor.energy_battery_discharged:                                           
      device_class: energy   
mpredfearn commented 3 years ago

In an ideal world, I think the templated sensors should be provided by the integration, but that gets very complex very fast due to the variations in peoples systems:

mpredfearn commented 3 years ago

Note that my templates still don't cope with all the possibilities, for example it would all go wrong if the battery was put into "discharge to grid" mode because currently I assume "maximise self consumption" where the battery only discharges to match the house load.

LukePrior commented 3 years ago

Hey,

Thanks for providing your configuration, I see you have a battery configured so I have tried to remove that bit and get it all working.

Tesla Card:

type: custom:tesla-style-solar-power-card
house_entity: sensor.power_consumption
grid_entity: sensor.solaredge_modbus_m1_ac_power
generation_entity: sensor.solaredge_modbus_i1_ac_power
grid_to_house_entity: sensor.power_grid_import
generation_to_grid_entity: sensor.power_grid_export
generation_to_house_entity: sensor.power_self_consumption

Template

sensor:                                                                         
  - platform: template                                                          
    sensors:
      power_grid_import:                                                    
        friendly_name: "Power - Grid Import"                                    
        unit_of_measurement: "W"                                                
        value_template: "{{ (states('sensor.solaredge_modbus_m1_ac_power') | float | min(0) | abs()) }}"
      power_grid_export:                                                     
        friendly_name: "Power - Grid Export"                                    
        unit_of_measurement: "W"                                                
        value_template: "{{ states('sensor.solaredge_modbus_m1_ac_power') | float | max(0) | abs() }}"                                                                                                                                                   
      power_consumption:                                                  
        friendly_name: "Power - Consumption"                                    
        unit_of_measurement: "W"                                                
        value_template: "{{ (states('sensor.solaredge_modbus_i1_ac_power') | float | max(0)) - (states('sensor.solaredge_modbus_m1_ac_power') | float) }}"
      power_self_consumption:                                            
        friendly_name: "Power - Self Consumption"                               
        unit_of_measurement: "W"                                                
        value_template: "{{ (states('sensor.solaredge_modbus_i1_ac_power') | float | max(0)) - states('sensor.power_grid_export') | float}}" 

I'm not having much luck, however:

image image

This is my first time getting Home Assistant setup so I'm not sure what's going wrong. I know that all my entity values are correct as they correspond to the values in the SolarEdge app.

LukePrior commented 3 years ago

Ok so I have managed to fix a few things for my specific setup:

Template:

sensor:                                                                         
  - platform: template                                                          
    sensors:
      power_grid_import:                                                    
        friendly_name: "Power - Grid Import"                                    
        unit_of_measurement: "W"                                                
        value_template: "{{ (states('sensor.solaredge_m1_ac_power') | float | min(0) | abs()) }}"
      power_grid_export:                                                     
        friendly_name: "Power - Grid Export"                                    
        unit_of_measurement: "W"                                                
        value_template: "{{ states('sensor.solaredge_m1_ac_power') | float | max(0) | abs() }}"                                                                                                                                                   
      power_consumption:                                                  
        friendly_name: "Power - Consumption"                                    
        unit_of_measurement: "W"                                                
        value_template: "{{ (states('sensor.solaredge_ac_power') | float | max(0)) - (states('sensor.solaredge_m1_ac_power') | float) }}"
      power_self_consumption:                                            
        friendly_name: "Power - Self Consumption"                               
        unit_of_measurement: "W"                                                
        value_template: "{{ (states('sensor.solaredge_ac_power') | float | max(0)) - states('sensor.power_grid_export') | float}}"     

image

Tesla Card:

type: custom:tesla-style-solar-power-card
house_entity: sensor.power_consumption
grid_entity: sensor.solaredge_m1_ac_power
generation_entity: sensor.solaredge_ac_power
grid_to_house_entity: sensor.power_grid_import
generation_to_grid_entity: sensor.power_grid_export
generation_to_house_entity: sensor.power_self_consumption

image

So I think I just need to sort out why the template sensors aren't available to the Tesla Card.

I am getting this warning unsure if it is the problem:

Template warning: 'float' got invalid input 'unknown' when rendering template 'sensor: - platform: template sensors: power_grid_import: friendly_name: "Power - Grid Import" unit_of_measurement: "W" value_template: "{{ (states('sensor.solaredge_m1_ac_power') | float | min(0) | abs()) }}" power_grid_export: friendly_name: "Power - Grid Export" unit_of_measurement: "W" value_template: "{{ states('sensor.solaredge_m1_ac_power') | float | max(0) | abs() }}" power_consumption: friendly_name: "Power - Consumption" unit_of_measurement: "W" value_template: "{{ (states('sensor.solaredge_ac_power') | float | max(0)) - (states('sensor.solaredge_m1_ac_power') | float) }}" power_self_consumption: friendly_name: "Power - Self Consumption" unit_of_measurement: "W" value_template: "{{ (states('sensor.solaredge_ac_power') | float | max(0)) - states('sensor.power_grid_export') | float}}"' but no default was specified. Currently 'float' will return '0', however this template will fail to render in Home Assistant core 2021.12
mpredfearn commented 3 years ago

@LukePrior you need to put the templated sensors in your configuration.yaml file - the developer tools thing is fine for experimenting with templates - but to actually create the sensors they need to be described in the home assistant configuration.

Also as you've figured out my templates are based on my master (https://github.com/mpredfearn/home-assistant-solaredge-modbus/tree/master) which has a couple of commits from PRs that are not upstream yet - specifically the multiple inverter one will result in different sensor names if you don't have it (drop the "i1_" from the sensor names).

mpredfearn commented 3 years ago

(see https://www.home-assistant.io/docs/configuration/ & https://www.home-assistant.io/integrations/template/)

LukePrior commented 3 years ago

Awesome after I moved everything to the configuration.yaml file it all seemed to work:

image

Thanks

mpredfearn commented 3 years ago

Perfect :+1: no problem.