Hello everybody…
I can’t understand what I’m wrong … because I can’t set the sensors …
use lovelace…
#solar sensor ... name file solar_sensor-serbat.yaml
template:
- platform: template
sensors:
grid_to_battery:
friendly_name: "Grid to battery"
unit_of_measurement: "W"
device_class: power
value_template: >-
{% set ip = states('sensor.grid_active_power') | int %}
{% set cdp = states('sensor.charge_discharge_power') | int %}
{% if ip < 0 and cdp > 0 %}
{{ (-1 * ip) | int }}
{% else %}
{{ (0) }}
{% endif %}
availability_template: >-
{{ (states('sensor.grid_active_power') not in [ 'unavailable', 'none', 'unknown' ] )
and (states('sensor.charge_discharge_power') not in [ 'unavailable', 'none', 'unknown' ]) }}
grid_to_house:
friendly_name: "Grid to house"
unit_of_measurement: "W"
device_class: power
value_template: >-
{% set g_c = states('sensor.grid_consumption2') | int %}
{% set g_t_b = states('sensor.grid_to_battery') | int %}
{{ (g_c-g_t_b) | int }}
availability_template: >-
{{ (states('sensor.grid_consumption2') not in [ 'unavailable', 'none', 'unknown' ] )
and (states('sensor.grid_to_battery') not in [ 'unavailable', 'none', 'unknown' ]) }}
generation_to_battery:
friendly_name: "Generation to battery"
unit_of_measurement: "W"
device_class: power
value_template: >-
{% set b = states('sensor.battery_charge') | int %}
{% set ap = states('sensor.input_power') | int %}
{% if b > 0 and ap > 0 and b < ap %}
{{ (b) | int }}
{% elif b > 0 and ap > 0 and b > ap %}
{{ (ap) | int }}
{% else %}
{{ (0) | int }}
{% endif %}
availability_template: >-
{{ (states('sensor.battery_charge') not in [ 'unavailable', 'none', 'unknown' ] )
and (states('sensor.input_power') not in [ 'unavailable', 'none', 'unknown' ]) }}
generation_to_house:
friendly_name: "Generation to house"
unit_of_measurement: "W"
device_class: power
value_template: >-
{% set pv = states('sensor.input_power') | int %}
{% set g_t_b = states('sensor.generation_to_battery') | int %}
{% set g_t_gr = states('sensor.generation_to_grid') | int %}
{% if (pv - g_t_b - g_t_gr) > 0 %}
{{ (pv - g_t_b - g_t_gr) | int }}
{% else %}
{{ (0) }}
{% endif %}
availability_template: >-
{{ (states('sensor.input_power') not in [ 'unavailable', 'none', 'unknown' ] )
and (states('sensor.generation_to_battery') not in [ 'unavailable', 'none', 'unknown' ])
and (states('sensor.generation_to_grid') not in [ 'unavailable', 'none', 'unknown' ]) }}
grid_consumption2:
friendly_name: "Grid consumption2"
unit_of_measurement: "W"
device_class: power
value_template: >-
{% set u = states('sensor.grid_active_power') | int %}
{% if u < 0 %}
{{ (- u) | int }}
{% else %}
{{ (0) | int }}
{% endif %}
availability_template: >-
{{ (states('sensor.grid_active_power') not in [ 'unavailable', 'none', 'unknown' ] )}}
generation_to_grid:
friendly_name: "Generation to grid"
unit_of_measurement: "W"
device_class: power
value_template: >-
{% set ip = states('sensor.input_power') | int %}
{% set pmap = states('sensor.active_power') | int %}
{% if pmap > 0 and ip > pmap%}
{{ (pmap) | int }}
{% else %}
{{ (0) | int }}
{% endif %}
availability_template: >-
{{ (states('sensor.input_power') not in [ 'unavailable', 'none', 'unknown' ] )
and (states('sensor.active_power') not in [ 'unavailable', 'none', 'unknown' ]) }}
battery_to_house:
friendly_name: "Battery to house"
unit_of_measurement: "W"
device_class: power
value_template: >-
{% set u = states('sensor.charge_discharge_power') | int %}
{% if u < 0 %}
{{ (- u) | int }}
{% else %}
{{ (0) | int }}
{% endif %}
availability_template: >-
{{ (states('sensor.charge_discharge_power') not in [ 'unavailable', 'none', 'unknown' ] ) }}
battery_charge:
friendly_name: "Battery charge"
unit_of_measurement: "W"
device_class: power
value_template: >-
{% set u = states('sensor.charge_discharge_power') | int %}
{% if u > 0 %}
{{ (u) | int }}
{% else %}
{{ (0) | int }}
{% endif %}
availability_template: >-
{{ (states('sensor.charge_discharge_power') not in [ 'unavailable', 'none', 'unknown' ] ) }}
house_consumption:
friendly_name: "House consumption"
unit_of_measurement: "W"
device_class: power
value_template: >-
{% set t = states('sensor.battery_to_house') | int %}
{% set u = states('sensor.grid_to_house') | int %}
{% set g = states('sensor.generation_to_house') | int %}
{{ (t + u + g) }}
availability_template: >-
{{ (states('sensor.battery_to_house') not in [ 'unavailable', 'none', 'unknown' ] )
and (states('sensor.grid_to_house') not in [ 'unavailable', 'none', 'unknown' ])
and (states('sensor.generation_to_house') not in [ 'unavailable', 'none', 'unknown' ]) }}
in lovelace
cards:
- type: horizontal-stack
cards:
- type: sensor
entity: sensor.daily_yield #
detail: 4
- type: sensor
entity: sensor.battery_day_charge #
detail: 4
- type: horizontal-stack
cards:
- type: custom:tesla-style-solar-power-card
generation_to_house_entity: sensor.generation_to_house
generation_to_grid_entity: sensor.generation_to_grid
generation_to_battery_entity: sensor.generation_to_battery
grid_consumption_entity: sensor.grid_consumption
house_consumption_entity: sensor.house_consumption
grid_to_house_entity: sensor.grid_to_house
battery_to_house_entity: sensor.battery_to_house
grid_to_battery_entity: sensor.grid_to_battery
battery_extra_entity: sensor.battery_state_of_capacity
hide_inactive_lines: 1
show_gap: true
- type: horizontal-stack
cards:
- type: custom:apexcharts-card
header:
show: true
title: Power
show_states: true
colorize_states: true
all_series_config:
type: area
opacity: 0.1
stroke_width: 1
group_by:
func: last
duration: 5m
series:
- entity: sensor.input_power
color: lightgreen
name: Produzione Pannelli
- entity: sensor.active_power
color: blue
#name: Consumo casa
- entity: sensor.charge_discharge_power
name: Battery Charge
transform: return Math.max(0,x);
color: orange
#name: Carico batteria
- entity: sensor.charge_discharge_power
name: Battery Discharge
color: '#800080'
transform: return -Math.min(0,x);
#name: Scarico batteria
- entity: sensor.grid_active_power
name: Grid Export
transform: return Math.max(0,x);
color: lime
#name: Esportazione
- entity: sensor.grid_active_power
name: Grid Import
color: red
transform: return -Math.min(0,x);
#name: Importazione da rete
thank you all…
ok, solved for the insertion of the sensors, but something is wrong in the operations …