I use the built in solar prediction feature which exposes a sensor.energy_production_today value
I want to calculate the estimated remaining power for the day based on the time of day
I have been able to get calculations for total daylight hours in the day and hours until sunset to work but I cannot seems to figure how to make the calculation of % of the days daylight left and take that percentage and multiply it by the sensor.energy_production_today value to return about how much energy will be generated for the rest of the day.
Any help is much appreciated, below is what I have so far. Help is needed on the “Solar Power Remaining”
template:
- sensor:
- name: "Hours Until Sunset"
state: >
{% set t = as_timestamp(state_attr('sun.sun', 'next_setting'))-now().timestamp() %}
{{ t | timestamp_custom('%H:%M', false) }}
- name: "Hours Daylight"
state: >
{% set nr = as_timestamp(state_attr('sun.sun','next_rising')) %}
{% set ns = as_timestamp(state_attr('sun.sun','next_setting')) %}
{% if nr > ns %}
{% set nr = nr - 60*60*24 %}
{% endif %}
{{ (ns - nr)|timestamp_custom('%H:%M',false) }}
- name: "Solar Power Remaining"
state: >
{{ ((float(states('sensor.energy_production_today')) )) | round(1) }}
Thanks, that appears to working in the template editor but after adding to configuration.yaml and reloading templates I have a new sensor but the value is unavailable
That is logical as neither t nor ns or nr are in that sensor…you would have to add them too of course
- name: "Solar Power Remaining"
state: >
{% set t = as_timestamp(state_attr('sun.sun', 'next_setting'))-now().timestamp() %}
{% set nr = as_timestamp(state_attr('sun.sun','next_rising')) %}
{% set ns = as_timestamp(state_attr('sun.sun','next_setting')) %}
{% if nr > ns %}
{% set nr = nr - 60*60*24 %}
{% endif %}
{{ ((float(states('sensor.energy_production_today')) * (t/(ns-nr)) )) | round(1) }}
thanks, that makes sense. I wondering why it was working in the template simulator. It seems the variables spill over there but not once you get into configuration.yaml
below is my final working yaml entry
template:
- sensor:
- name: "Hours Until Sunset"
state: >
{% set t = as_timestamp(state_attr('sun.sun', 'next_setting'))-now().timestamp() %}
{{ t | timestamp_custom('%H:%M', false) }}
- name: "Hours Daylight"
state: >
{% set nr = as_timestamp(state_attr('sun.sun','next_rising')) %}
{% set ns = as_timestamp(state_attr('sun.sun','next_setting')) %}
{% if nr > ns %}
{% set nr = nr - 60*60*24 %}
{% endif %}
{{ (ns - nr)|timestamp_custom('%H:%M',false) }}
- name: "Solar Power Remaining"
unique_id: sensor.energy_production_today_remaining
unit_of_measurement: kWh
device_class: energy
state: >
{% set t = as_timestamp(state_attr('sun.sun', 'next_setting'))-now().timestamp() %}
{% set nr = as_timestamp(state_attr('sun.sun','next_rising')) %}
{% set ns = as_timestamp(state_attr('sun.sun','next_setting')) %}
{% if nr > ns %}
{% set nr = nr - 60*60*24 %}
{% endif %}
{{ ((float(states('sensor.energy_production_today')) * (t/(ns-nr)) )) | round(1) }}
I made one more adjustment so that the value will return zero when the sun is not yet up or when the sun has gone down
state: >
{% set nr = as_timestamp(state_attr('sun.sun','next_rising')) %}
{% set ns = as_timestamp(state_attr('sun.sun','next_setting')) %}
{% if is_state("sun.sun", "above_horizon") %}
{% set t = ns-now().timestamp() %}
{% else %}
{% set t = 0 %}
{% endif %}
{% if nr > ns %}
{% set nr = nr - 60*60*24 %}
{% endif %}
{{ ((float(states('sensor.energy_production_today')) * (t/(ns-nr)) )) | round(1) }}
It is produced by the built in built in solar prediction feature part the energy management features. See Forecast.Solar - Home Assistant
I am using remaining predicted value so that I can decide to run a dump load or not when my batteries are near full. If the “solar day” is almost over I will not trigger a dump load.
I’ve just put in solar, and am wondering the same thing, how do I work out how much extra solar I can expect to produce.
The approach taken would seem to be looking at sunrise and sunset, assuming even distribution between the two, and making a calculation on that basis, but particular with my south-west facing panels, I think that’s an inaccurate assumption.
I’m pretty sure this underlying model isn’t exposed as a state, so no amount of magic with value templates will allow for accuracy (Within the parameters of a forecast)
I have been using this prediction (solar today) to make decision each day as to whether I want to allow my battery to be depleted or not. I keep my battery at 70% overnight and deplete to 40% SOC if there is decent solar expected that day. If not I leave it at 70%
I separately use dump loads to keep the battery below 80% except once a week I allow it to go to a full charge. In my case I use a water heater and a water pump (fills a cistern) as dump loads so far.
Dump load run in a sequence as needed and all cut off if battery falls to 70%
These dump loads trigger based solely on SOC regardless of solar prediction.