I finally got my power monitoring integrated into HA using some help from this thread.
The problem I have now is that I have an entity that tracks net power usage and goes negative when I returning power to the grid. The energy dashboard doesn’t like this negative value and I cannot figure out how to create a new sensor so it will read properly. I tried making it so when it was a negative value it turned positive and a positive value reported as 0. This worked but I could not use the sensor in the energy dashboard.
The code I have for the sensors currently is
Sensors.yaml
- platform: integration
source: sensor.net
name: Net Back to Grid
unit_prefix: k
round: 2
Rest Sensor in Config.Yaml
- name: "Net"
value_template: "{{ value_json.net }}"
device_class: power
unique_id: curb-14
unit_of_measurement: W
Every variation I have tried that
will give me a positive value in kWh but will not allow me to select it in the energy dashboard.
I can use sensor.net_back_to_grid in the energy dashboard but because its a negative value it messes up the calculations.
Can anyone help me out? ChatGPT can only get me so far as my coding knowledge is laughable.
Are you using CURB’s to calculate your energy generation?
Here’s my code to convert CURB’S Solar Generation Watts Sensors to positive:
### CONVERT CURB VALUE TO POSITIVE FOR SOLAR CT 1
- platform: template
sensors:
solar_panel_1_positive:
value_template: "{{ states('sensor.curb_solar_panels_1') | int(0) | abs }}"
friendly_name: 'Solar Panel 1 Power Generation'
unit_of_measurement: 'W'
### CONVERT CURB VALUE TO POSITIVE FOR SOLAR CT 2
- platform: template
sensors:
solar_panel_2_positive:
value_template: "{{ states('sensor.curb_solar_panels_2') | int(0) | abs }}"
friendly_name: 'Solar Panel 2 Power Generation'
unit_of_measurement: 'W'
Here’s my code too sum each of the CT into 1 sensor:
### SUM SOLAR CT 1 + SOLAR CT 2
- platform: template
sensors:
energy_solar_total:
friendly_name: "Solar Total Power"
unit_of_measurement: 'W'
device_class: power
value_template: "{{ states('sensor.solar_panel_1_positive') |float + states('sensor.solar_panel_2_positive') | float }}"
As you can see by my sensor I have 2 CT Clamps for measuring each leg of the breaker box feeding energy to the grid/house. If you want the sensor to show as energy (kWh) and not as power (W) you can create another sensor like this:
### CURB Energy Riemann sum integral ###
- platform: integration
source: sensor.solar_total_power
name: energy_return_to_grid
unit_prefix: k
round: 2
Let me know if you need any help if this does not work for your setup.
I hobbled some stuff together from your code and what I had so its now working.
I am using curb to calculate my energy generation. Curb outputs a variable Net, Consumption (total power being used), and Solar(although I am using my solaredge inverter to report this info as I already had it setup). The NET variable tells me how much power I am using from the grid (positive value) and how much power I am returning to the grid (negative value). So I made a sensor that reports any negative value of NET as return to grid and any positive value being from grid.
I am sure there is a more elegant way to make this work than the spaghetti I wrote but it seems to work.
Thank you very much