I do not have a sensor installed for Solar production.
But I have sensors for Total load power, Battery charging power & Battery discharging power. All are in Watt.
If Total load power sensor is D, Battery charging power sensor is B & Battery discharging power sensor is C, can someone give me the code to calculate the Solar production (A + B as per the below drawing)?
template:
- sensor:
- name: Total Solar Power
unit_of_measurement: W
device_class: power
state_class: measurement
state: "{{ states('sensor.d')|float(0) - states('sensor.c')|float(0) + states('sensor.b')|float(0) }}"
availability: "{{ has_value('sensor.d') and has_value('sensor.c') and has_value('sensor.b') }}"
# Loads default set of integrations. Do not remove.
default_config:
# Load frontend themes from the themes folder
frontend:
themes: !include_dir_merge_named themes
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
sensor:
- platform: template:
- sensor:
- name: Total Solar Power
unit_of_measurement: W
device_class: power
state_class: measurement
state: "{{ states('sensor.total_power_consumption')|float(0) - states('sensor.jk_bms_discharging_power')|float(0) + states('sensor.jk_bms_charging_power')|float(0) }}"
availability: "{{ has_value('sensor.total_power_consumption') and has_value('jk_bms_discharging_power') and has_value('sensor.jk_bms_charging_power') }}"
template: is an integration. Like sensor: , script: or automation: it belongs hard up against the file margin.
You don’t put it under sensor:. You do this:
# Loads default set of integrations. Do not remove.
default_config:
# Load frontend themes from the themes folder
frontend:
themes: !include_dir_merge_named themes
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
template:
- sensor:
- name: Total Solar Power
unit_of_measurement: W
device_class: power
state_class: measurement
state: "{{ states('sensor.d')|float(0) - states('sensor.c')|float(0) + states('sensor.b')|float(0) }}"
availability: "{{ has_value('sensor.d') and has_value('sensor.c') and has_value('sensor.b') }}"