Starting a new thread as this was getting lost in the Hints, Tips & Troubleshooting thread.
Post details of your integration with Home Assistant etc.
Havent got around to doing the PR on git hub yet, but I have been dabbling with doing the whole thing in home assistant.
I havent started with the python code yet, but its what I'm planning on doing, having short scripts to do a specific task.
Have it boiled down to 2 automations, controlled by 2 helpers, A boolean one, as a switch to turn off overnight discharge, (and by side effect enable overnight charge) This will change the end hour of the timed charge.
The second helper is a slider, to set the overnight SOC, and that will change the charge current rate.
Both automations read the current values and only run if a value needs to be changed.
they are currently configured to change test helper values for now though, but the proof of concept is there.
Here's the Yaml file im using to pull in the extra registers.
What is your current settings in your hybrid, they could be all set to 0.
@graememk was thinking about this over the weekend, perhaps it would be handy to also have a slider for SOC too so that instead of charging for x hours set the SOC slider to what you want the battery to be at when the night rate ends as you might not want to go to 100% based on next day prediction.
That's the way I have it planned,
The switch sets the time to 9(well will be 8 when dst stops) or 0(23) and the charging will be controlled by setting the amps to say 50 or 0
That's for that! Mine looked the same but clearly something missing or slightly off. I replaced my config with yours and it's working now.
Looking to automatically publish the solcast todays forcast to an MQTT broker every morning @ 7am.
I can manually publish the value using the built-in Mosquitto broker integration in HA but struggling to achieve this via yaml or an automation.
Any pointers?
Assuming you are using the Solcast integration within HA and want to publish to MQTT for an external client to consume, use an automation;
alias: Solcast Publish description: "" trigger: - platform: time at: "07:00:00" condition: [] action: - service: mqtt.publish data: topic: solcast payload_template: "{{states('sensor.solcast_forecast_today')}}" mode: single
Thanks @Jonathan I was missing the “data:”line. You saved me a few hairs!
Will this work or will I cause a mess? Looking to set the charge rate with a slider in my "Timed Charge" card
I'm not sure it's useful to any of you, but I automated the auto-charge of my Pylontech battery using the pysolarmanv5 library for Python, which talks to my Solis inverter. The code is mostly in R and Python and is available on my GitHub page (toledobastos). Apparently I can't post links to this forum, so Google is your friend to find it.
Loving the remote charge integration with HA that many people on this thread helped out with, fair play and thanks to all.
Now if I could "leverage" more of your code so I don't have to reinvent the wheel 😁
This month the predictions have been brutal so I'm looking to do something like a one button press/or toggle to set the following up in HA:
Any better way to do it?
Not to my knowledge, I have my automations triggered by the update time
But I don't set it repeatedly, I check that needs to be set. So if it's already 0 it doesn't do anything
And how about your automations based on predictions? Care to share what works for you? (20kwh battery)
What do you guys use? forecast.solar has let me down time and time again.
I'm using met eireann and solcast. I'm finding met eireann one to be more accurate but it's manual and I'm still trying to figure out how to get it into homeassistant. I'm just doing it in excel. The solcast one is a bit off so I'm hesitant to rely on it for automation.
If the question is whether you can use templates to form the value, then Yes, that's fine, it should work.
Setting a charge current in a UI may be a little tedious to get used to, especially if you have to do all the calculations in your head to get from SOC to deci-amps.
Maybe you could look at having a "target SOC" slider, and do all the calculations automatically in code/template.
I think that's what Graeme is looking at above too.
@SD_DRACULA , perhaps this would work well for you too? Especially considering you've a large battery, and you're not happy with the solar forecasting. (championc mentioned this earlier too). Basically, it'd get your battery to a certain level for the morning (e.g. 8am).
You could:
Have an input_number for "target SOC", that you can leave at 50% the whole time, or slide it up and down each day if you want, or move it automatically based on forecast (if you have any confidence in forecasts). Or set it via forecast in the early evening, but you could override it yourself in the later evening (i.e. let forecasting set it most of the time, but if you have a different feeling about tomorrow, or you know you're going to have unusually heavy usage tomorrow, you can move it)
Have a single automation that runs just before your cheap electricity time starts (or just after you normally go to bed, so your house usage is probably more constant from then until morning).
When this automation runs, it calculates the charge current and sets register 43141, based on:
For doing the calculations, it may be easier to take each part as a template sensor, and build them up that way.
Note: instead of having a "target SOC", you could have "target kWh usable": so you can set how many usable kWhs you want in your battery in the morning (they're essentially the same thing, just looking at it a slightly different way)
yup. I got these done with the code I mentioned above. Will take the averages of a range of forecasts, check if it’s winter or DST, and charge the battery accordingly. There’s also options to calibrate the charge based on SOC and a few other variables. Have a look at it and you should be able to do it.
Had a look yeah but that's just the python code, looking for a bit of yaml for home assistant I guess, I can get it to work for sure but if someone already has the code it would save me many reboots of my HA server 😀
@connesha that's what I started doing basically
I have automations that start/stop the charge based on time value right now, i.e. start at 1am and stop at 4am if I want a 10 kwh charge @60A
Might increase this so I can charge slower but probably no point since each battery can sustain 50-75A and 60A / 4 batteries means 15A to each battery which is quite low.
My night baseload seems to be around 3kwh so the way I see it no point charging to whatever % and then let the house drain that, might as well pause until day rate kicks in (need to pause any night that I charge the car anyway)
No automation on the forecast unfortunately. Forecast.solar and Met.ie. My Conversion from hourly wh to actual kwh is crude, but its "good enough" (basically its solar panel area * global radiation * 0.18
the marginal months are hard to predict, as a brief window of sun and boom 6kw!
Then I decide, whether to not discharge or charge to a certain % and set my switches accordinly.
I like your code, Already in too deep with home assistant and node red for me to up ship now
How are you getting the met eireann stuff into a useable prediction may I ask. I started to dabble with working out the "effective area" of panels so the prediction can be adjusted as the sun moves around. but my crude one was "good enough" so i stuck with that.
So far I have my Eddi boosting at 6am if Solcast is below 10kWh for the following day (It's about 80% effective). I'll probably add an "if below 5kW boost to max temp" at some point. Triggers on time, condition of the solcast forecast for today, then send boost of specified time to the eddi.
Still don't have the inverter/battery connected (Huawei), but when I do, i'll set up a similar to boost the battery.
The car charger triggers on excess solar, but I've added a button to HA for boosting overnight if I think I'll be out before the sun charges it again. I'll probably add a solcast based boost at some point, but WFH, the "boost if going somewhere" is good enough for now.
Yea, that's what I meant about a single automation: If you want to wait until day rate, just set a lower charge current, and let that run until 8am, instead of having to change current to "charge" and then "pause" at different times. So:
To put in 10kwh over the 9 hours its 21A approx (assuming charge voltage of 53V). My automations have often set 0A or a couple of Amps to get as far as morning.
I wouldn't be separating grid_charge and Pause_battery_drain, as they are the same thing really.
The base-load question only comes into it if deciding whether to charge at all. e.g. IF you have 14kwh usable in you battery at night, AND you know you'll use approx 3kwh before morning, THEN set storage_mode to 33 (charge disable) because you don't need to charge at all.
UI-wise, it could be a single input_number slider "target SOC".
And optionally a second input_boolean "charge tonight" (which maps to setting storage_mode to 33 or 35)
@SD_DRACULA Do you still have that Ethernet data logger? It seems that it does support Modbus TCP.
This would mean that you could use the Home Assistant Modbus Integration directly, bypassing pysolarmanv5.
The pause would be to say charge until SOC = 80% for example (or also to stop drain while I charge EV) but yeah maybe I'll use something like charge X kwh (5% SOC = 1 kwh) for the times I don't want the battery to be 100% in the morning else if the sun comes out will export right away, which is not what I want ofc.
I guess I could work out some formula that says well I need to charge 9kwh in 9 hours so 1kw/h is about 20A like you mentioned
Since I have the timed charge values on the inverter, I think that technically I don't even need to turn off the charge in the morning as the inverter does it anyway right?
I was able to get that to work one time only, and then I think I broke it after trying to update its FW.
After that I couldn't for the life of me get the LAN logger to connect to Solis so it can dump that data too and the modbus calls also stopped working. FW needed to be updated as it was throwing mad values in the hundreds of kwh generated into the solis portal.
Shame really as I much prefer wired over wifi.
The UI has amps and the formula above is multiplying by 10 to get the deciamps that the inverter wants. :)
The automation starts at 2am if the switch is on, and will charge to the SOC set and at the rate set. Default is 50% and 25A.
Completely untested YAML is below for the automation. I have delays in there just to give time for the inverter to process the previous request. I'd say 20 seconds is probably being generous. Not sure if there's a better way to do it but I've been making a request at a time.
alias: Solis Timed Charge description: "" trigger: - platform: time at: "02:00:00" condition: - condition: state entity_id: input_boolean.solis_timed_charge state: "on" action: - service: script.inverter_write_holding_register data: register_addr: 43141 register_value: "{{states('input_number.solis_timed_charge_rate') | int *10}}" - delay: hours: 0 minutes: 0 seconds: 20 milliseconds: 0 - service: script.inverter_write_holding_register data: register_addr: 43110 register_value: 51 - wait_for_trigger: - platform: template value_template: >- {{ states('sensor.solis_battery_soc')|float > states('input_number.time_charge_soc')|float -1 }} - service: script.inverter_write_holding_register data: register_addr: 43141 register_value: 0 - delay: hours: 0 minutes: 0 seconds: 20 milliseconds: 0 - service: script.inverter_write_holding_register data: register_addr: 43110 register_value: 49 mode: single
Got solar installed and looking at solis cloud app and trying to make sense of what the percentage under the battery represents, say I see the following at battery icon
19%
0.12kW
The other items are 0.003 being generated, 1.17kW consumption and 1.047 from the grid,
I assume it means that of the 1.17kW taking 0.12 from battery, this is 19% of total consumption coming from battery?
Is it as simple as that, thanks in advance
Thanks @silver_sky not too far from what I was thinking of:
Toggle grid charge sets 43110 to 51 for on and 49 for off, handy as it doesn't start charging right away due to the charge times I have set on the inverter itself.
Then one automation for stop charging (set charge amps to 0) once it reaches the SOC slider value above (hoping this value actually works: above: input_number.grid_charge_to_soc)
alias: Solar - Night time charging off by SOC trigger: - platform: numeric_state entity_id: sensor.solar_battery_soc above: input_number.grid_charge_to_soc condition: [] action: - service: script.inverter_write_holding_register data: register_addr: 43141 register_value: 0 mode: single
And another one if I want to be charging right until day time (not based on SOC)
alias: Solar - Night time charging off trigger: - platform: time at: "08:00:00" condition: [] action: - service: script.inverter_write_holding_register data: register_addr: 43110 register_value: 49 mode: single
Or just toggle the grid charge tonight switch (instead of automation above) since it already writes the registers itself
switch: - platform: template switches: grid_charge_tonight: friendly_name: Toggle Grid Charge Tonight value_template: "{{ is_state('sensor.battery_grid_charge', '51') }}" turn_on: service: script.inverter_write_holding_register data: register_addr: 43110 register_value: 51 turn_off: service: script.inverter_write_holding_register data: register_addr: 43110 register_value: 49
This should give you the parts needed to implement a "Target SOC" based charging implementation:
1) it decides whether you need to charge or not (i.e. if your current SOC, minus night usage, is greater than target SOC)
2) if you do need to charge, then what current to set (including 0A to pause discharging if you "nearly" have enough)
Note, I just threw this together now. Its not tested at all (and its not what I'm using myself as I'm doing in python), so test it fully before you use it
Put this into the Developer Tools -> template
{## Change these for your system: ##} {% set charge_voltage = 53 %} {% set charge_hours = 9 %} {% set night_usage_wh = 3000 %} {% set battery_capacity_wh = 20000 %} {% set lower_soc_limit = 20 %} {% set now_soc = states('sensor.battery_soc') |int %} {% set target_soc = states('input_number.target_soc') | int%} {## Dont change from here down ##} {% set soc_to_wh = (battery_capacity_wh / 100) | int %} {% set now_battery_usable_wh = ((now_soc - lower_soc_limit) * soc_to_wh )| int %} {% set target_battery_usable_wh = ((target_soc - lower_soc_limit) * soc_to_wh )| int %} {## This is just printing stuff, for debugging purposes ##} now_battery_usable_wh: {{ now_battery_usable_wh }} target_battery_usable_wh: {{ target_battery_usable_wh }} {% if (now_battery_usable_wh - night_usage_wh) > target_battery_usable_wh %} Have enough to get to target SOC at morning; dont need to charge TODO: Set storage_mode (43110) to 33 here to turn off "charging", and let the battery discharge as normal {% else %} Dont Have enough to get to target SOC at morning, so we need to charge (even it its at 0A) TODO: Set storage_mode (43110) to 35 here to turn on charging {% set charge_needed_wh = target_battery_usable_wh - (now_battery_usable_wh) %} charge_needed_wh: {{ charge_needed_wh }} {% set current_needed_a = ((charge_needed_wh/charge_hours) / charge_voltage) %} {% if current_needed_a < 0.1 %} Only need to "pause" (i.e. stop discharging for the night to reach the target) {% set current_needed_a = 0 %} {% endif %} current_needed_a: {{ current_needed_a }} {% set current_needed_deci_amps = (current_needed_a * 10) | int%} current_needed_deci_amps: {{ current_needed_deci_amps }} {## Doubly make sure its a safe value ##} {% if current_needed_deci_amps < 0 %} {% set current_needed_deci_amps = 0 %} {% endif %} {% if current_needed_deci_amps > 1000 %} {% set current_needed_deci_amps = 1000 %} {% endif %} TODO: set charge current (43141) to {{ current_needed_deci_amps }} {% endif %}
Change the values in the top section to match your system. The initial values I've set are for a 9 hour charge duration (i.e. full d/n window), on a system with a 20kwh battery that has a 20% SOC lower threshold.
And put this is as your input_number:
target_soc: name: Target SOC min: 40 max: 100 step: 5 initial: 50
Tip: on your phone, move the target_soc slider, and then you can see the values change on your laptop when looking at the template, like the "deci_amps"
To start with, see that its printing out the values you'd expect. Then, break it up into a script/automation. And then set the register values as per the TODOs.
Nice one, I believe that will do just fine for the over night charge
now_battery_usable_wh: 8600 target_battery_usable_wh: 10000 Dont Have enough to get to target SOC at morning, so we need to charge (even it its at 0A) TODO: Set storage_mode (43110) to 35 here to turn on charging charge_needed_wh: 1400 current_needed_a: 2.935010482180293 current_needed_deci_amps: 29 TODO: set charge current (43141) to 29
And not only that but it means if the battery is charging for 9 hours then the car can just charge from grid in that time and won't pull from the battery.
Exactly. Keep it simple :-)
Personally, I wouldn't like to be looking at lots of toggles in UI, and I certainly wouldn't want to be looking at a UI that is asking me to calculate or set a charge current. Code can do all that so much better than I can. What is easy to understand is battery SOC, so IMO that's the only thing that the UI should show/ask for, ... and the rest is done behind the scenes...
For your case, with an EV that you may want to charge on many nights, you may want to stop battery discharge every night (so you don't forget and end depleting battery).
So, you could remove this condition completely from my above post and you will always "charge", even at 0A (which just means stop discharging)
{% if (now_battery_usable_wh - night_usage_wh) > target_battery_usable_wh %}
Or, even better, you could create an input_boolean to "Force Always Charge".
Check the register values for 43110 for yours. I think mine is different as I have a backup discharge limit in place or something like that. Someone else explained it better before. 😅
And here is the full thing if you want an extra that toggle to "force_always_charge", so you're free to use any appliance (incl EV charger) at night, as long you set the toggle to On.
{## Change these for your system: ##} {% set charge_voltage = 53 %} {% set charge_hours = 9 %} {% set night_usage_wh = 3000 %} {% set battery_capacity_wh = 20000 %} {% set lower_soc_limit = 20 %} {% set now_soc = states('sensor.battery_soc') |int %} {% set target_soc = states('input_number.target_soc') | int%} {## Dont change from here down ##} {% set soc_to_wh = (battery_capacity_wh / 100) | int %} {% set now_battery_usable_wh = ((now_soc - lower_soc_limit) * soc_to_wh )| int %} {% set target_battery_usable_wh = ((target_soc - lower_soc_limit) * soc_to_wh )| int %} {## This is just printing stuff, for debugging purposes ##} now_battery_usable_wh: {{ now_battery_usable_wh }} target_battery_usable_wh: {{ target_battery_usable_wh }} {% if (now_battery_usable_wh - night_usage_wh) > target_battery_usable_wh and is_state('input_boolean.force_always_charge', 'off') %} Have enough to get to target at morning; dont need to charge TODO: Set storage_mode (43110) to 33 here to turn off "charging" {% else %} Dont have enough, or force charge. We need to charge (even at 0A) TODO: Set storage_mode (43110) to 35 here to turn on charging {% set charge_needed_wh = target_battery_usable_wh - (now_battery_usable_wh) %} charge_needed_wh: {{ charge_needed_wh }} {% set current_needed_a = ((charge_needed_wh/charge_hours) / charge_voltage) %} {% if current_needed_a < 0.1 %} Only need to "pause" (i.e. stop discharging for the night to reach the target) {% set current_needed_a = 0 %} {% endif %} current_needed_a: {{ current_needed_a }} {% set current_needed_deci_amps = (current_needed_a * 10) | int%} current_needed_deci_amps: {{ current_needed_deci_amps }} {## Doubly make sure its a safe value ##} {% if current_needed_deci_amps < 0 %} {% set current_needed_deci_amps = 0 %} {% endif %} {% if current_needed_deci_amps > 1000 %} {% set current_needed_deci_amps = 1000 %} {% endif %} TODO: set charge current (43141) to {{ current_needed_deci_amps }} {% endif %}
input_number:
input_boolean:
force_always_charge: name: Force Always Charge
That was my first approach too and I still have the switches on HA, but there’s no point in doing this manually. Hence the automation. Let the system work for you and not the other way around. Agreed that you don’t want the battery to discharge overnight. Hence why calculating the required charge (current) is important, even if the charge is 0A, in which case nothing is charged nor discharged overnight.