diff --git a/helpers/sensor.estimated_charge_percent_today.jinja b/helpers/sensor.estimated_charge_percent_today.jinja new file mode 100644 index 0000000..4b24d23 --- /dev/null +++ b/helpers/sensor.estimated_charge_percent_today.jinja @@ -0,0 +1,7 @@ +{% set totalWh = 3200 %} +{% set currentChargePercent = states('sensor.system_flos_bkw_sb_state_of_charge') | float(0) %} + +{% set todayProductionWh = (states('sensor.balkon_solcast_pv_forecast_balkonsolar_forecast_remaining_today') | float(0)) * 1000 %} +{% set estimatedProductionPercent = 100 * (todayProductionWh / totalWh) %} + +{{ (currentChargePercent + estimatedProductionPercent) | round(2) }} \ No newline at end of file diff --git a/helpers/sensor.estimated_charge_percent_tomorrow.jinja b/helpers/sensor.estimated_charge_percent_tomorrow.jinja new file mode 100644 index 0000000..777b6e8 --- /dev/null +++ b/helpers/sensor.estimated_charge_percent_tomorrow.jinja @@ -0,0 +1,11 @@ +{% set totalWh = 3200 %} + +{% set estimatedChargePercentToday = states("sensor.estimated_charge_percent_today") | float(0) %} + +{% set avgConsumptionWh = states("sensor.energy_from_battery_7_days_average") | float(0) %} +{% set avgConsumptionPercent = 100 * (avgConsumptionWh / totalWh) %} + +{% set tomorrowProductionWh = (states('sensor.balkon_solcast_pv_forecast_balkonsolar_forecast_tomorrow') | float(0)) * 1000 %} +{% set estimatedProductionPercentTomorrow = 100 * (tomorrowProductionWh / totalWh) %} + +{{ (estimatedChargePercentToday - avgConsumptionPercent + estimatedProductionPercentTomorrow) | round(2) }} \ No newline at end of file diff --git a/helpers/sensor.estimated_optimal_output_limit.jinja b/helpers/sensor.estimated_optimal_output_limit.jinja new file mode 100644 index 0000000..1414dd8 --- /dev/null +++ b/helpers/sensor.estimated_optimal_output_limit.jinja @@ -0,0 +1,29 @@ +{# Configuration #} +{% set totalWh = 3200 %} +{% set maxPower = 600 %} +{% set targetChargePercent = 100 %} +{% set sunsetOffset = -3 %} + +{% set currentChargePercent = states('sensor.system_flos_bkw_sb_state_of_charge') | float(0) %} +{% set solarAvailable = states('binary_sensor.solar_power_available') | bool(false) %} + +{% if solarAvailable and currentChargePercent < 100 %} + {# Current state infos #} + {% set timeToSunsetHours = ((as_timestamp(state_attr('sun.sun', 'next_setting')) - as_timestamp(now()))) / 3600 + sunsetOffset %} + + {# Average battery power for the day to reach targetChargePercent #} + {% set remainingChargePercent = [ 0, targetChargePercent - currentChargePercent ] | max %} + {% set remainingChargeWh = (remainingChargePercent / 100) * totalWh %} + {% set remainingAvgPower = (remainingChargeWh / timeToSunsetHours) %} + + {# Today average production power #} + {% set todayProductionWh = (states('sensor.balkon_solcast_pv_forecast_balkonsolar_forecast_remaining_today') | float(0)) * 1000 %} + {% set todayOffsetWh = todayProductionWh - remainingChargeWh %} + {% set todayOffsetPower = todayOffsetWh / timeToSunsetHours %} + {% set positiveOffsetPower = [ 0, todayOffsetPower ] | max %} + {% set limitedOffsetPower = [ maxPower, positiveOffsetPower ] | min %} + + {{ limitedOffsetPower | round(0) }} +{% else %} + {{ 0 }} +{% endif %} \ No newline at end of file diff --git a/helpers/sensor.power_output_dynamic.jinja b/helpers/sensor.power_output_dynamic.jinja new file mode 100644 index 0000000..5a965a4 --- /dev/null +++ b/helpers/sensor.power_output_dynamic.jinja @@ -0,0 +1,25 @@ +{% set batFullToday = states("sensor.estimated_charge_percent_today") | float(0) >= 100 %} +{% set batFullTomorrow = states("sensor.estimated_charge_percent_today") | float(0) >= 100 %} + +{% set techTemp = states("sensor.klima_balkonsolar_temperature") | float(0) %} +{% set techTempThr = 35 %} +{% set safePowerLimit = 401 %} + +{% set powerUsageMin = states("sensor.power_usage_min_fault_tolerant") | float(0) %} +{% set powerUsageMax = states("sensor.power_usage_max_fault_tolerant") | float(0) %} + + + +{% if states("sensor.estimated_charge_percent_today") | float(0) >= 100 %} + {% set output = states("sensor.power_usage_max_fault_tolerant") | float(0) %} +{% endif %} + +{% set output = [ output, states("sensor.estimated_optimal_output_limit") | float(0) ] | max %} + +{% if states("sensor.klima_balkonsolar_temperature") | float(0) > 35 %} + {% set output = [ output, 401 ] | min %} +{% endif %} + + + +{{ output }} \ No newline at end of file