Surplus charge automation for Solarbank E1600 (1st generation) #81
Replies: 6 comments 12 replies
-
Hi,
I needed to remove the last line "alias" to make it work. |
Beta Was this translation helpful? Give feedback.
-
I added the first automation via yaml editor to automation ui and get the following error: I googled it but it seems not to be clear what it is. delete "" works not variables should be correct. what could be wrong with data ? the error is quite senseless, because no line is addressed. is there any other debugging option available?
thanks for any hints - replaced only entity names |
Beta Was this translation helpful? Give feedback.
-
I assume your variable do not resolve correctly. You should check all your templates in the developper tools to ensure they are ok for the automations. |
Beta Was this translation helpful? Give feedback.
-
Hi,thanks for your great work and the detailed instructions! Due to your work I was able to set my automations up within a day. Can't emphasize enough how valuable your input was for me! :) For my setup I did set keep_last_sample to true for the statistics sensors (see https://www.home-assistant.io/integrations/statistics). This avoids, that the state of those sensors gets unavailable/unknown if max_age is exceeded. Probably this is also useful for you. Thanks again! |
Beta Was this translation helpful? Give feedback.
-
Hi, Now I have the problem, that I don't rallye Know how to get the solarcycle resettet. All sensor and select entities I created about gui. It seems that I need no make an automation for the reset of the solarcycle - or is there a simple solution? What should an automation trigger looks like and what Action is needed? Could you please help me may be with an example? I also need to Look tomorrow if the sensor solarcycle deliveres something.. Thanks in regard! |
Beta Was this translation helpful? Give feedback.
-
Hi tholu,
Now I have the following questions:
It would therefore be important to know: How do the 2 storage units work together? Would you have to manually control 2 schedules or do they have a common schedule? What strategy would make sense for discharging the 2nd storage system? What seems to make sense from your experience? 500€ for the old one or 1000€ for the newer one, where the inverter would have to be sold. |
Beta Was this translation helpful? Give feedback.
-
Surplus charge automation for E1600
Introduction
I want to introduce my Home Assistant automations that I use to control the Anker Solix Solarbank E1600 Generation 1.
Based on the Anker Solix HA integration, it is now possible to modify the Solarbank time schedule parameters dynamically. This allows to automate the power export of the Solarbank to better fit your actual power consumption in the house. The goal and use case for my automations is following:
With this goal in mind, a charge priority use case for the solarbank is out of scope, since it will waste 15-20% solar energy unnecessarily due to battery management and energy conversion losses. Additionally, when the battery is full early in the day, the whole solar energy is bypassed to the house but cannot be consumed. My automations are optimized to use the battery only as buffer for solar energy that cannot be consumed directly. So the priority is not to avoid grid import at all cost, but avoid import as much as possible, while reducing export as much as necessary and possible. If you have different use cases for your Solarbank, these automations might not be applicable to you. But you could still get some ideas on how you can automate the Solarbank with Home Assistant.
Appliance overview
I own only a 790 Wp solar system with 2 panels and a single Solarbank. The panels are SE and SW oriented, ideally for stretching the solar production over the full day instead of having a shorter peek production. I have no shadows to consider over the day, which simplifies my optimization routines.
Since I have no over panelling, the automations are optimized for a balanced small photovoltaic system, that fits well with my daily consumption in spring and autumn, but may have surplus production with >4 kWh in summer which cannot all be consumed and buffered, especially if nobody is home to consume.
I use a normal automation mode that is considering a bias regulation slightly below the house consumption to ovoid exporting energy to the grid completely. However, I realized quickly that a more aggressive mode makes sense too for periods with expected overproduction.
For surplus periods when there is more energy expected as the solarbank can buffer, the automation is using a more aggressive regulation with a bias slightly above the house consumption. This will further reduce your grid energy import without exporting too much to the grid unnecessarily.
Requirements
The Solarbank provides value updates to the cloud in 1 min intervals at least. This is insufficient for usage in regulations. You need device or template sensors that can provide values in about 5 sec intervals or less, to ovoid time lags between value calculations and comparisons are becoming too significant. To realize my automations, you need sensor entities for following:
Actual AC power value exported from your inverter into the house
I use a Hoymiles inverter with OpenDTU, which provides a whole set of sensors via MQTT that can be refreshed in 5 seconds. If you have no direct quick inverter sensors, a quick smart plug may be used as well.
Actual grid power value
There are various smart Readers available to intergrate this value into HA. I use a Hichi DIY device providing the grid power via Tasmota FW and MQTT. Other devices like Shelly 3EM might be used as well, but you need quick and local interfaces. Getting the value via cloud API will be too slow and unreliable.
With those 2 (template) entities you create another template sensor that calculates your actual house consumption. The actual house consumption, or better a statistically flattened version of it, will be used as base to calculate the new power set point for your regulation.
I strongly recommend to use template sensors for those core entities instead of direct device sensors. This gives you more flexibility for the value they are reflecting in your regulation, and you don't need to change your automations when device sensors need to be changed or replaced. You can also combine values of multiple devices to reflect your entity. For example, my inverter is plugged into an outdoor Fritz Dect 210 smart socket. This only provides power once minute, so too slow for regulation. But I use this value when the inverter AC power entity is no longer available while the inverter is switched off. At that time it represents 0 W and does not break automation due to unavailability.
Another requirement is that you are familiar with HA usage, integrations, automations, templating and dashboards in general since I do not describe HA basics. Also YAML and Jinja knowledge should be available to make your own adoptions of the automations as necessary.
Regulation capabilities
Essentially there are two different approaches how you can regulate the generated AC power export to your house:
Both have pros and cons. Limiting the inverter must be supported by your inverter and you must integrate it into HA as well. It has the advantage that power regulation is typically very fast, and you can limit it well below 100W. However, it can negatively impact the MPPT trackers of your Solarbank and reduce the produced energy. Furthermore it typically limits all DC input channels equally, which is a disadvantage for asymmetrical setups where some solar panels are directly connected to the inverter. Therefore I do not recommend the inverter limit approach at daytime. However it is the best approach for discharging the solarbank. I realized this automation with a Hoymiles HM 600 inverter that I integrated into HA via an OpenDTU ESP DIY device. The project and the automation is described in the HA community.
For most efficient daytime regulation you need to adjust the solarbank power export to the house. The solarbank does not react as fast as the inverter and cannot be limited to less than the defined inverter limit of 150 W or 100 W. Furthermore power export increases are not allowed in less than 30 sec intervals by the integration and everything is processed via Api and depends on the cloud.
In this project I use both types of regulation and I optimized them for my use case. If you have no inverter limit regulation capabilities (Anker inverters do not provide that feature), this project may still help you to understand how you can automate you solarbank power export all day, even if I use it only for the daytime phase and the inverter regulation for the nighttime phase.
Automation overview
In general I split my regulation algorithms for daytime and nighttime. At daytime I use the solarbank regulation, at nighttime the inverter regulation. To clearly separate those two different concepts, I split the solarbank time schedule accordingly into a fixed format of 3 intervals:
The interval borders are adjusted automatically based on sun or other conditions.
The inverter automations are used only when the day interval is not active, but the automations will ensure to reset the inverter limit to its max. value for day interval or whenever the solarbank state indicates anything but a discharge state to prevent the inverter limit is reducing solar production by any means.
Overall I use 2 generic automations that are applicable for both regulation concepts:
Automation to set a helper for the regulation mode
While optimizing my regulations, I found that it is valuable to use 2 different modes for both regulation concepts. I use a 'moderate' mode and an 'aggressive' mode, but a single mode might be good for you too. Based on this mode, I optimize the algorithm parameters for both regulation approaches. They have the goal that the 'moderate' mode keeps the grid consumption slightly above 0 W and avoids any export to the grid if possible (0 to 30 W range), while the 'aggressive' mode keeps the grid export as small as possible while avoiding grid import if possible (-40 to 5 W range).
Automation for daily schedule adjustment
This will adjust the borders between day and night intervals of the Solarbank schedule and control when either of the two regulation approaches will be used
Furthermore I use 2 automations for the solarbank day interval, but their parameters are very unique and depend on your personal preference how you want to use the solarbank:
Automation to adjust export switch
This is based on various individual criteria, but mainly to avoid risk of unwanted discharge due to solarbank firmware inefficiency or bad weather conditions. However, the export need to be allowed for regulation of output power above the minimum bypass of 100/150 W
Automation to adjust power export to home
This is the main regulation automation, but only used at daytime interval and when export is allowed.
Last but not least, I use 2 automations for the inverter regulation:
Automation to adjust inverter limit
This is the main regulation automation, but not used at daytime interval.
Automation to reset inverter and its limit
This is to ensure the inverter is not limiting possible solarbank production at any time when it is not discharging. It will also reset the inverter daily yields once a day in case the inverter did not went off over night.
All automations are explained and provided in following sections, so you can adopt and adjust them to your own needs and use case.
If you have a dual solarbank setup, you also may benefit from this project when you automate them equally shared by regulating the whole appliance. While with version 1.3 of the Anker Solix HA integration and firmware 1.5.6 you can set individual solarbank power exports, such an asymmetrical or staggered use case is not considered in this project. It would make a meaningful split of regulation intervals much more complex and more automations may be needed to regulate each solarbank individually.
Full cycle example of a sunny day
Following screenshot provides an overview how the automations work across a sunny day (done with HACS ApexChart card)
The most important graph is the dark blue grid power, which is regulated closely to the 0 W axis while there is sufficient solar or battery power as highlighted below:
You can see how the moderate regulation at night keeps the average slightly above 0 W, avoiding grid export as much as possible. During the sunny day the regulation mode went to aggressive and kept the grid power close below the 0 W axis, trying to avoid grid import without exporting too much power. You can also see the light green inverter limit used for the regulation at night, which is reset during the day to its maximum. The sandy solarbank system preset graph shows my fixed 300 W limit for the discharging intervals at night and you see the regulation during the day. The switches between day and night periods are marked with the vertical Sun and Moon marker lines. The greenish SOC and self consumption percentage is printed against the 2nd Y axis (% unit) on the right. The little bumps in the light blue house consumption median graph are from the fridge which is toggling on and off multiple times a day. The high peek in house consumptions are large consumers like the coffee machine, but there was no cooking on that day which appears more of a pulsing peek consumption which is difficult to regulate.
Note:
I do not regulate over aggressively to limit the amount of changes that needs to be applied to either the inverter or solarbank limits. The wider you will choose your regulation range, the less adjustments may be required.
Daytime example with changing conditions
Following chart shows how the automations work on changing conditions during the day. Not only for cloudy conditions early in the morning, but also for cooking at noon. This chart is also showing the toggle from aggressive to moderate mode in the morning due to changed conditions/estimations. You can see how the dark blue grid power average shifts again slightly from below 0 W to above 0 W (done with HACS History Explorer card)
This chart is a good example to demonstrate that short peeks or fluctuations are difficult to regulate. If they are too short for the sensors and automation latency, they should be better ignored by the algorithm, otherwise the regulation starts when the peek is over and lots of energy is exported to the grid unnecessarily. Therefore my algorithm is a bit lazy for preset increases (initial delay after decrease, median delay), but immediately reacts on grid exports to limit the export as much as possible. This graph may also give you an idea, why your main sensors for grid power and produced solar/battery power should be near real time values, otherwise such a regulation effectiveness cannot be realized. Of course, the latency to apply a changed preset also matters, which is the reason why you must monitor the effectiveness of your automations and adopt the algorithm parameters eventually.
Implementation of automations
Preparation
Before you start adopting the automations, you should prepare the following.
Dashboard to monitor automation effectiveness
Build a dashboard that allows you to view and control the following:
Forecast Solar integration
Some automations are considering the Forecast Solar for decisions and optimizations. Therefore it will be useful to install a Forecast Solar integration and configure it for your solar panels as accurately as possible. You may need to monitor the Forecast Solar on various days and conditions to see whether this reflects your panel yields as good as possible. Possible integrations are:
Integration for your grid meter
Depending on your grid meter, various options are available to get the power consumption into HA. An important factor for the regulation is that this value is provided near real time. So you should not use a smartmeter reader that can be accessed only via cloud (dependency, latency, time lag issues). I use an ESP DYI device with Tasmota firmware that reads the grid meter via its optical interface and publishes the data to my WLAN and HA using MQTT. I can accomplish around 5 sec refresh and that is sufficient. Optionally you may use the known Shelly smart meters, since more and more vendors seem to corporate with shelly devices for power metering. They provide the grid meter data also locally via WLAN.
Integration for your inverter (optional)
In case you use the inverter regulation concept, depending on your inverter you will need devices and integrations to support near real time sensing of the AC output as well as capabilities to modify the inverter limit as needed. I use a Hoymiles HM600 inverter, which I integrated into HA with an OpenDTU device, providing the inverter connection via local Wifi and MQTT. So in my case, I had to install the MQTT Addon and configure my OpenDTU device to publish its data via the HA MQTT server.
Note:
One important generic requirement independent of the integration you use, you should create a template entity representing the inverter AC power into the house the ALL the time. Since your inverter is typically switched off at night, the integration entities may render unavailable. Your template should ensure that it always represents a value of 0 W if the inverter AC power inverter entity is no longer available. It will simplify all automations and templates based on the AC inverter power if represented by an entity that is typically not unavailable.
House consumption entity
You need to create a template entity for your actual (real time) house consumption. This will be used as the target set point in all regulation algorithms, so the value should be as accurate as possible.
Without solar panels this is typically your grid meter power value. However with solar panels or power batteries you have to consider the actual solar/battery AC power feeding into your home as well. The house consumption template sensor needs to consider that there may be time lags between both values and a negative house consumption is typically not possible. The larger the time lags are between the entities used for the calculation, the higher the fluctuation for this template can be. I found that it will be helpful to create a second statistic entity for the house consumption template entity. I use a median entity, which represents the 50th percentile. Other percentiles might be good for you as well and their purpose is to flatten out calculation peeks as well as very short peeks of your source entities that may occur and should be ignored for regulation. The disadvantage of the statistic entity is that it needs a couple of samples and therefore is lagging somewhat behind the actual value. I use the median value for solar/battery power increases into the house since this regulation can be a bit lazy and should not be over aggressive. For solar/battery power reductions I use the actual consumption sensor however, since I do not want to lag behind when external grid power dropped below my target range (for example when exporting to grid).
Note:
I created template sensors also for my important source device values instead of using the provided device entities directly. This has the benefit to make all your automations independent of the device or integration entities, because they could change in future (device or integration replacements etc). If you have a template sensor for them, you just need to update the template with the new device or integration entity after any change or replacement.
Following is an example how the median sensor flattens out peeks in the actual consumption calculation. The white calculated real time consumption line is overlayed by the light blue flattening median sensor line. You can see that all the white short peeks are flattened, and the long term changes are delayed by about half of the sampling interval.
When using the median value for increases in the automation, you consider a somewhat settled value for lazy increases.
House consumption template sensor
Following are the source entities you need to replace:
sensor.grid_power
In my case this is a template with positive Watt for grid import and negative Watt for grid export.
sensor.inverter_power
In my case this a template for the AC power in Watt coming from the inverter
House consumption median sensor
With about 5 sec samples for each of the source entities, the calculated house consumption entity gets 10-12 samples in 30 seconds. This has proven to be a good flattening sensor for actual house consumption which is only lagging about 15-20 seconds behind the real value. Following are the source entities you need to replace:
sensor.house_consumption
Your actual house consumption template sensor from above.
Solarbank battery energy change in last hour
Create an Integral sensor that will be tracking the energy in kWh that is going into and out of your battery all the time, so it will count up and down. The value itself is not that important, but it can be used as source for a statistic sensor that calculates the battery energy change during last hour. This sensor will be used in automations to predict the time when the battery is full or empty and switch the regulation mode based on it.
Integral sensor for solarbank energy
Create a helper for an Integral sensor from your Solarbank battery power (Watt) to sum up the energy (kWh). You can create it from the UI with following settings:
entity_id: sensor.solarbank_battery_energy
metric prefix: kilo
time unit: hours
source entity: sensor.system_bkw_sb_battery_power
Your solarbank battery power entity. For dual solarbank systems, you should select the system SB battery power entity to track the energy of both devices
method: left Riemann sum (most accurate)
precision: 3 (Wh resolution)
Since the battery power of the integration will show positive Watt for charging and negative Watt for discharging, the integral sensor will increase while charging and decrease while discharging.
Statistic sensor for Solarbank energy change in last hour
This sensor represents the actual charge or discharge rate of the last hour which we are interested in for the prediction.
Helper to define daily solar start and solar end
The actual time when your solar panels start and end their production does vary throughout the year since it depends from the sun level (elevation) and its angle (azimuth). This variation must be considered in the automations to adjust the borders of the day interval in the solarbank schedule accordingly.
I use datetime input helpers to record the start and end time each day based on various conditions. The recorded times will then be used to adjust the daily solarbank schedule intervals once per day at night. The durations between now and those recorded times will also be used for battery buffer and discharge predictions to switch the regulation mode accordingly.
Datetime helper for daily solar start and solar end
Create two datetime helpers via the UI using following:
Regulation mode helper
I created an Input Select helper to switch between two regulation modes I called 'moderate' and 'aggressive'. You can create it via the UI using following:
I decided for an input select sensor to have more than 2 options available, but discovered later that 2 are sufficient. So you can also create a simple switch helper for the regulation mode and adopt the automations code accordingly when using its state.
Helpers to delay first and subsequent solarbank preset increases
I implemented 2 different helpers to delay the first preset increase after a decrease or other 'reset' condition, and subsequent increases after a previous increase.
Timer helper to enforce wait time for subsequent increase
The solarbank preset can be increased only every 30 seconds. This is a restriction to limit the amount of Api requests since each change requires 2 requests. Furthermore the Solarbank needs some time to adjust to the new preset. 30 seconds allow the battery management system to adjust and settle for the new preset. The timer helper is required to block subsequent preset changes until the timer is finished. The timer helper can be created via the UI:
The duration of the timer will be set dynamically by the automations and vary depending on the regulation mode or other conditions. But it needs to be set to 30 sec as minimum to avoid subsequent preset errors with the solarbank system preset entity.
Switch helper to generally block or allow preset increases
Some situations may require an additional or first delay where quick increases do not make sense. With an additional switch helper, the normal increase capability can blocked or enabled with additional dynamic delays made in automations. It can be used to ignore short time consumption peeks as you can typically see in your house (modern cooking fields for example). So it acts an initial increase delay after an undefined period of time when the timer is not active anymore. The switch helper can be created via the UI:
Binary sensor to indicate a workday
I see different consumption patterns in my house depending whether it is a workday or weekend/holiday. This sensor can be used to consider different consumption forecast calculations and make various decisions on it in your automations. You can install the core HA integration workday and configure it to your needs to get a reliable sensor for working days in your area.
Selection helper to indicate home presence
Independent of the automations described here, I use a general Input Select helper that I set manually or via other automations to a meaningful automation mode. It can be used to disable your automations with a single entity when that is relevant for specific automations. Another way I use this is for different modes of shutter automations. For the solarbank automations I use it as well to better forecast the day and night consumptions in order to toggle the appropriate regulation mode. For example I have 2 modes indicating that nobody is at home (travelling or vacation) and then the daily consumption is typically much less, so aggressive mode could be used even with lower solar energy prediction. This is something you really need to adopt to your typical life and power consumption behaviour, or ignore it altogether in the automations. I describe it here, so you have an understanding how it is used in the automation code further below.
Daily solar cycle tracking for battery energy
This part is a little bit off topic for the power regulation, but relevant for proper battery energy tracking and integration into your Energy Dashboard. Many people are struggling with this topic and wonder why they cannot properly use the daily energy entities as provided by the Anker Solix integration.
On top of that, for proper tracking and comparison of daily energy entities, I realized that the standard reset cycles of the utility meter helpers are not very useful if you use a battery for your solar power, which can extend the daily solar energy usage into the next day. For example to create template sensors that track the daily efficiency of your charge and discharge energy, you have to consider a flexible end of the overall solar cycle for the meter reset. Therefore I created utility meter helpers which can be reset via a service that can be triggered by an automation. The reset service only works for utility meters that have a tariff option defined. With a tariff option specified, HA will create the main select.* entity for the meter and another sensor.* entity for each tariff, where the tariff name is appended to the common sensor name. So you can create a utility meter referring to the energy that you want to track and the tariff can be called for example 'solarcycle' to indicate that this is not a normal daily utility meter entity. In order to reset the counter of all tariff entities, you have to issue the utility meter reset service against the main select entity, which typically switches between mutliple tarifs. Only then you will have a valid last_reset timestamp and last_period value recorded automatically in the tariff entity along with the reset of the state value itself.
Create separate template entities for battery charge and discharge energy
You cannot utilize the daily energy entities as provided by the Anker Solix integration as is in your HA Energy dashboard, and I would never recommend this either. Those entities are reset on a daily base and may confuse energy recording, which works best with total increasing entities. Furthermore any integration or device entity in general may have to be replaced over lifetime and then you would loose their history in the dashboard. History data switch to another entity is possible, but requires manual SQL scripting and is painful. That is nothing you want to do if not familiar with SQL and the HA database structures. The integration's daily energy entities will also be reset at a fixed time each day and the values are provided as is from the cloud. For those reasons, I strongly recommend to create template entities for the integration provided appliance battery power, which can be positive (charging) and negative (discharging) power. You can use the UI to create one template entity for the charging power presenting only the positive values or 0, and another entity for the discharging power presenting only the negative values or 0. Those negative values can be multiplied by (-1) to convert them to positive numbers if desired. For each of those template entities, create a Rieman Integral helper entity from the UI to sum the charge and discharge power (W) separately into charge and discharge energy per hour (kWh). Those energy helpers are always increasing totals and can be used directly in your HA energy dashboard to represent the required battery energy entities. If you have to replace your integration entities in future, you just need to update the power template entities for the new source entity to properly represent the separated charge and discharge power and the rest will continue to work as is, without risk of loosing energy history data in the dashboard.
Following Rieman Integral helper example entities will be used here in the automations to demonstrate the tariff utility meter and daily solar cycle based reset:
Create utility meter with tariff for 'daily' charge and discharge energy
The required utility meters can be created from the UI with following settings:
Keep the defaults for the other settings. This will create 2 entities for each utility meter. Following entities will be available once finished:
Template sensor to indicate solar cycle restart
In order to have a unique trigger entity for the solar cycle restart, I created a trigger based template sensor. Maybe that can all be done in an automation itself, but here I show you an example how to create a sensor that changes once a day depending on triggers and conditions. Basically the sensor triggers when the solarbank changes into a state that indicates solar power. The other trigger comes from the inverter integration once the inverter becomes reachable, as well as a time trigger after midnight. This will ensure that the sensor is also reset when the solarbank is not installed over winter, as well as updating an entity attribute.
Note:
Trigger based sensors will be unknown until triggered the first time after initial reload.
Entities used in the template sensor
Following are the entities that you need to replace in the template code:
Template sensor code
Entity overview
The last but not least preparation step is to create an entity overview for the automations, scripts and templates that you are going to create. I pulled this together for all entities I used in this project. You need to understand what they are used for and how to replace each of them with your own appropriate entity. You may not need all, you may need more. Each setup, device integration and regulation requirement is different, so you will need to understand the described automations and the sense of the entities that are used. Following table will explain each of them to provide you a central reference.
Automation to set helper for the regulation mode
Explanation
The first automation will switch your helper entity to indicate which mode to be used for the power regulation. In this project I used two modes called 'moderate' and 'aggressive'. Based on my home presence pattern, the solar forecast and the expected house consumption, this entity is set to the appropriate mode. It is the base setting for other automations to distinguish between various parameter sets which they should apply. This is the automation you have to adopt the most to your particular setup and your power consumption behaviour. You may need to tweak this more often when you discover situations where the mode setting is not appropriate, either for daytime or nightime periods.
The automation separates both periods with their own rules, since the sun forecast is relevant for charging capability during the day, and the SOC and energy draw at evening is most important for the nighttime period. Therefore you clearly need to separate the conditional checks and actions between those two periods. Most of the parameter changes can be applied in the variables section. Those variables will be used by the actions and conditional steps to simplify necessary adoptions. I divided the automation into two choice options based on the mode setting. In each option I separate the conditional checks for the two periods. Since the variables are used in most places, except the entity replacements the required changes should be minimal in the rest of the actions and conditions.
Initially I struggled to find a good trigger when the mode setting should be re-evaluated. A time pattern may be used, but is not ideal. At the end it turned out that the solarbank battery SOC state change is the perfect trigger for automations that need to re-evaluate their setting conditions. It is not triggered too often during a daycycle, but triggered often enough and only when it makes sense to re-evaluate the conditions. Because when the SOC is not changing, your regulation parameters don't have to be changed either. Special cases can be covered by additional triggers as you see in the automation, for example when the solarbank operational mode is changing.
In order to simplify monitoring and debugging of the automation, I log any automation change to a single entity for later review via a logbook card. Typically the automation traces are wrapped too fast, so you cannot follow up why a change was made otherwise. I use the same in other automations, so I will not explain it for each automation.
Entities to be replaced
Following entities are used and need to be replaced:
Expand to see Automation Code
You need to review all variables and parameter settings to adjust them to your setup and consumption behaviour for various conditions to set your desired regulation mode. Especially for dual solarbank systems you need to adjust various calculations, but also conditions and actions if both devices must be considered separately instead of a corresponding appliance entity. Copy and paste the automation code into a new UI Automation using the YAML mode.
Automation to adjust daily solarbank schedule
Explanation
This automation adjusts your solarbank schedule, which I divided into a daytime period from solar production start until solar production end, and a nighttime period from solar production end until solar production start in the morning. Solarbank schedules must be defined for a full day from 00:00 until 24:00, therefore the two periods will require creation of 3 intervals in the schedule. The times for the period switch in the morning and evening will be adjusted once a day to the actual sun position. Basically you have to define proper sun elevation and eventually sun azimuth values that will trigger the automation when solar production typically starts for your setup and when it ends again. This will be different for everyone, and you may have to consider obstacles that may throw shadows to your panels in the morning or evening. Since I have no shadows on my panels, I can use only the sun elevation to define meaningful start and end triggers for this automation. You will have to adopt and test this with your trigger settings to work reliably.
I have chosen sun parameters to catch most of the solar power in the evening, while having the option to bring forward the nighttime period under certain conditions (low or no solar but charged battery earlier in the evening). This will maximise your possible solar energy production, but provides the option to start discharge earlier if it makes sense.
The same approach I found useful for the start of the daytime interval, which I defined late per default to allow a charged battery to discharge completely while solar production may start late on cloudy days for example. In case of early sun on nice days, the solarbank will switch automatically to solar production mode and does not waste possible solar energy. This approach ensures that charged batteries can discharge as long as possible, while the daytime interval can be brought forward upon solar production start to allow early adjustment of solarbank home load presets if necessary.
The times for the solarbank schedule will be rounded by 5 minutes. While the mobile app allows only 30 minute granularity for the schedule intervals, the HA integration supports 1 minute interval granularity. I use 5 minute granularity since that is typically sufficient and I haven't tested either full functionality with 1 minute schedule granularity.
Notes:
Entities to be replaced
Following entities need to be replaced:
Expand to see Automation Code
Copy and paste the automation code into a new UI Automation using the YAML mode. You will need to adjust the triggers for SunStart and SunEnd according to your solar panel environment. Please review also all other templates and variables for required parameter adjustments.
Automation to adjust home load export switch of solarbank system
Explanation
This automation will change the Solarbank appliance power export switch setting as required. Initially you may think this is not required since it could be set ON by the daytime schedule interval for allowing output preset changes all the time as needed. And you are right, this is the way it should be. However, you have to change it to limit some firmware flaws because the solarbank may change suddenly into a discharge mode during daytime with varying conditions. Each undesired switch to discharge will cost you about 30 minutes solar energy that is not produced because Solarbank 1 cannot discharge and produce at the same time, so it will discharge with the output preset for 10-30 minutes. Additionally, when switching back to solar production, the solar power may remain limited to 35 W for at least 10 minutes to allow various inverters to ramp up once the solar production starts. So this may end up in really bad efficiency for solar production, especially on partially cloudy days.
Initially I built this automation just to disable the export switch once discharge state is discovered at daytime interval to limit the solar energy loss as much as possible. Correspondingly I added triggers and rules to re-enable the export switch again when solar conditions justify the risk of re-enabling the switch. You need to consider that the power bypass is also working when the export switch is off, but it is limited to the defined inverter minimum power setting, which is 100 W for Anker inverters or 150 W for 3rd party inverters. This bypass limit is OK while there is not much more solar to expect. However, if you want to adjust the preset to higher values, it will be applied only when the export switch is enabled.
Note:
The minimum bypass usage with disabled Export switch does not work when Charge Priority with MI80 is applicable, or the 0 W switch is installed for 3rd party inverters. In both cases, deactivation of the home load export switch will cause 0 W bypassed to the house, which is NEVER the goal of these automations. Without active charge priority or 0 W Switch, a deactivation of the export switch has following major function:
In my journey to improve the automatic discharge behaviour of the Solarbank with Anker support, I got provided following rules that are supposed to be applied for automatic discharge as of firmware 1.6.2:
I factored in some automation rules to prevent these rules can kick in at all, but discovered that the 10 minute condition time is not always applied and discharge condition can happen sooner. Even when the export switch is off and discharge is not allowed, the firmware may still apply the rule, but then discover that discharge is not possible. However it still applies the 10 minute ramp up period for a solar start with solar limitation to 35 W even if much more solar power could be generated. My final automations have built in some improved rules to avoid the switch to discharge completely by lowering the presets if needed in the other automations, but also to disable the export switch when no regulation above the configured bypass minimum power is required.
Entities to be replaced
Following entities need to be replaced:
Expand to see Automation Code
Copy and paste the automation code into a new UI Automation using the YAML mode. You will need to adjust the triggers for SunStart and SunEnd according to your solar panel environment. Please review also all other templates and variables for required parameter adjustments.
Automation to adjust solarbank preset
Explanation
This is the main automation that makes the solarbank home preset adjustments under certain conditions and based on various parameters for the active regulation mode.
The algorithm used is an improvement from my former invert limit adjustment project described in the HA community. The parameters for the algorithm are typically defined in the variables section. For decreases I still used the calculation for the actual home consumption, since I want to react quickly on grid exports that exceed the defined lower range. For increases however, I found it beneficial to use the house consumption median value since that can flatten out short spikes in the home grid or the calculation. I also introduced a binary switch and a timer to delay the first increase and delay subsequent increases to follow a lazy increase approach. The reason for that is that it is not beneficial to regulate a short pulsing high peek consumption like some home consumers may use, for example modern cooking fields, washing machines etc.
Following closeup screenshot demonstrates the effectiveness of the algorithm for moderate changes using a fridge consumer.
The orange house consumption median is mainly fluctuating by the fridge power toggling off/on/off. The purple line shows the solarbank home load preset which reacts immediately when preset must be decreased, but reacts lazy when it can be increased again after the fridge toggled on. The result is that you see a short grid import bump when a consumer is switched on, which is no problem at all. But you see only a very short export glitch when a consumer is turned off again. For the rest of the time the grid power is close to 0 W, showing only micro fluctuations which you always have in your home grid. Therefore it is important that you regulate in a range of approximately 30 W only to avoid too many unnecessary toggling of your solarbank home load preset.
If you make the ac_efficiency progressive factor too low, this may overshoot the target and resulting in an quick adjustment into opposite direction which you should avoid. The limit curve will show that the new limit was overestimated. This factor is less significant for low power limits, but for higher limits it should adopt closely to your inverter DC/AC loss to ensure the AC output will be close to the house consumption value. The offset_factor is used to shift the target output towards conservative (positive) or aggressive (negative) values, resulting in no or minimal grid export. This factor is used in combination with the defined base that is used for rounding the new preset value. For the solarbank I use 10 W as base, which is identical to the mobile app granularity. Do not choose too small bases, since that may result in much more preset changes which are not beneficial at all and cause much more api requests.
The grid power ranges for the moderate and the aggresive modes should also be 30 W at least, otherwise your automation may also perform too many non-beneficial adjustments. At the end, you will need to spend time to monitor the algorithm efficiency closely in the beginning to ensure it works as desired. When you apply changes, make them small and verify the result. Changes can make the efficiency also worse in various situations.
Entities to be replaced
Following entities need to be replaced:
Expand to see Automation Code
Copy and paste the automation code into a new UI Automation using the YAML mode. You may need to adjust the parameters in the variables section according to your inverter or desired grid power ranges. Please review also all other templates and variables for required parameter adjustments.
Automation to adjust inverter limit
Explanation
This is the main regulation automation for the inverter limit, but not to be used at daytime interval. Unlike the automation to adjust the solarbank home load preset, the inverter regulation is a combination of an automation and a script which is only executed by the automation if a change may be required. It can also be combined into a single automation, but I split this in a past project when I implemented the inverter adjustment automation as described in the HA community.
A script works essentially the same as an automation, but without triggers. I used it for the action part of the regulation. The advantage of the split is that it simplifies the debugging. While the automation is triggered every 3-5 seconds, the script will just be called when a change may be necessary. Therefore the traces for a potential change wrap slower than for an automation, which makes it easier for real time debugging when and why changes have been applied.
This is an improved version of the algorithm along the changes and improvements I implemented for the solarbank home load preset algorithm explained earlier. Similar variable and parameter settings apply here. It is not using the same laziness as the solarbank algorithm because the hoymiles limit settings are applied quicker then solarbank power settings. However increases will now also use the home consumption median value to ignore any power or calculation spikes upon limit increases. It also supports the two regulation modes, where aggressive mode is to be used typically only for short nights in summer when battery is full and house consumption does not indicate full discharge capability. So in case of surplus charge as indicated by aggressive mode setting, minimal grid export is tolerated to keep the import down to 0 W most of the time.
Entities to be replaced
Following entities needs to be replaced in the automation and the script:
Expand to see Automation Code
Copy and paste the automation code into a new UI Automation using the YAML mode. You may need to adjust the parameters in the variables section according to your inverter or desired grid power ranges. Please review also all other templates and variables for required parameter adjustments.
Expand to see Script Code
The following script
script.inverter_regulation
is called by the inverter limit adjustment automation. Make sure that the script name will match the service name in the automation. Please also adjust the variable parameters as required.Automation to reset inverter and its limit
Explanation
This automation is mainly to reset the inverter limit to max. (600/800 W) in order to avoid potential reductions of solar production during the day. It will also be used to reset the inverter daily yields if needed.
Note:
I figured out that the daily inverter yields reported by your inverter integration (e.g. OpenDTU) may no longer be usable by HA for your daily solar yield tracking. One reason is that the inverter typically can switch off multiple times during cloudy/dark days when the solar panels do not produce sufficient power for the solarbank. Upon each inverter power cycle, the daily yields are reset. Another reason is that solar yield is no longer limited to a single day when you use batteries. The solar cycle can stretch over a day and you may want to consider that as well.
I strongly recommend to build your own Rieman Integral sensors from power entities. These power entities ideally are also template sensors from sensors provided by your devices/integration, so they can be used as an 'alias' to a physical device or integration bound sensor. The Rieman integral helper will create an always increasing energy template entity. From that energy entity, you can create your utility meter helpers with reset intervals as needed. They will only be reset at your controlled or manual reset interval and the power entity template provides the capability to switch to a new power entity whenever the used end device or integration entity must be replaced. So you never have to change your automations anymore when they all are based on the template entities instead of end device or integration entites.
Especially for the long term history tracking in the energy dashboard I would never recommend to use any end device or integration entities, since their replacement in the energy dashboard will cause a loss of history data typically.
Entities to be replaced
Following entities needs to be replaced in the automation and the script:
Expand to see Automation Code
Copy and paste the automation code into a new UI Automation using the YAML mode. Please review all templates and variables for required parameter adjustments. Especially the inverter reset depends on the used integration. I also included a sequence to reload the configuration entry for the inverter device id, since I had few occasions where entities remained unknown upon inverter start. You may disable or remove this section if not applicable to your inverter, but at least replace the device id with the one you have in your HA setup.
Beta Was this translation helpful? Give feedback.
All reactions