Hi,
Yep, I have done exactly that with my pool.
You are on the right track with the ‘difference’. This is how we find out how much grid power is either being imported or exported.
Here is a very simple template sensor that will give you a positive or negative number.
If production is > than consumption, then you will have a positive number to indicate excess power being exported to grid.
- sensor:
- name: Net Power
state_class: measurement
unit_of_measurement: W
device_class: power
icon: mdi:transmission-tower
state: >
{% set production = states('sensor.solar_production') | int %}
{% set consumption = states('sensor.house_consumption') | int %}
{{ (production - consumption) }}
And then here is my automation.
alias: Pool Pump On
description: ''
trigger:
- platform: numeric_state
above: '1100'
for:
hours: 0
minutes: 10
seconds: 0
milliseconds: 0
entity_id: sensor.net_power
condition:
- condition: state
entity_id: switch.sonoff
state: 'off'
action:
- scene: scene.pool_pump_on
- service: notify.notify
data_template:
message: Pool Pump on {{ states('sensor.net_power') }} Watts
If you want a seperate sensor for grid import and grid export, then I suggest reading the post here