Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solar charging #265

Open
maand75 opened this issue May 18, 2024 · 34 comments
Open

Solar charging #265

maand75 opened this issue May 18, 2024 · 34 comments
Labels
feature request Request of a new feature

Comments

@maand75
Copy link

maand75 commented May 18, 2024

Hi,
would be Nice to integrate solar power so the car starts to charge depending on how much solar power you are producing

I have done this already in my own integration but through it would be a Nice additional feature to add?

If you want i can show you how i have implemented it.

@AndersHoglund
Copy link

I would like to have this feature too.
@maand75 If you have a solution, implement it and issue a PR. This is how open source works.....
/A

@maand75
Copy link
Author

maand75 commented Jun 8, 2024 via email

@pluskal
Copy link

pluskal commented Aug 13, 2024

Hi guys, here is my automation to limit output current (A) for tesla it that helps in your effort.

I tried to keep it as simple as possible while extracting variables so it can be tested / verified while modeling different conditions.

alias: "[Tesla] Charge on solar power"
description: ""
trigger:
  - platform: state
    entity_id: sensor.rct_power_storage_grid_power
condition:
  - condition: state
    entity_id: binary_sensor.raven_charger
    state: "on"
  - condition: state
    entity_id: device_tracker.raven_location_tracker
    state: home
action:
  - variables:
      grid_usage: "{{ states('sensor.rct_power_storage_grid_power') | float }}"
      max_charging_amps: "{{ state_attr('number.raven_charging_amps', 'max') | int }}"
      min_charging_amps: 1
      current_charging_amps: "{{ states('number.raven_charging_amps') | int }}"
      grid_voltage: "{{ states('sensor.rct_power_storage_grid_voltage_p2') | float }}"
  - target:
      entity_id: number.raven_charging_amps
    data:
      value: >
        {% set available_amps = (-grid_usage / grid_voltage) / 3 %}  {% set
        proposed_charging_amps = (available_amps + current_charging_amps) %} {%
        set proposed_charging_amps = ([proposed_charging_amps,
        min_charging_amps] | max) %} {% set new_charging_amp =
        ([proposed_charging_amps, max_charging_amps] | min | round(0, 'floor'))
        %} {{ new_charging_amp }}
    action: number.set_value
mode: single

@jonasbkarlsson jonasbkarlsson added the feature request Request of a new feature label Aug 13, 2024
@jonasbkarlsson
Copy link
Owner

Same topic was discussed in #212. At that time, it was suggested to keep this outside of the integraton and use automations instead.

My concern is that there will be a lot of different installations that requires various variants of functionality. It will be diffiucult to verify and maintain.

One would need to find a simple enough usage that would make sense for enough people.

@jonasbkarlsson
Copy link
Owner

@pluskal, thanks for the automation. Have you noticed any instability problems with that solution?

In addition to grid_usage, max_charging_amps, min_charging_amps and grid_voltage, I would add

  • three_phase_charging (true for 3-phase charging and false for 1-phase charging)
  • solar_charging_on_to_off_delay (to handle the case when solar power is not enough to provide min_charging_amps, but wait a certain time to turn off. In order to not frequenctly turn on and off charging)

@pluskal
Copy link

pluskal commented Aug 13, 2024

@pluskal, thanks for the automation. Have you noticed any instability problems with that solution?

Not so far. I have been using it for a few months and is seems stable.

The only issue with automation is make it "smart"/"automatic". Cases such as:

  • charging without automation - I want to charge it during the daytime fully, not only on solar power (the need to turn off the automation)
  • handle case when charging stops, but charging Amps are set to low, typically 1A ... and charger reconnection during the night and "fast" charging
  • automation "stateless" - HA instance restart and error handling

It is also not convenient solve this using automation when I want to add possibility to lower charging amps when my FVE battery is not fully charged, or the tariff is high (I have high tariff only 4 hours a day but separate time intervals.).

three_phase_charging (true for 3-phase charging and false for 1-phase charging)

Tesla have ability to set only Amps and that is independent on 1 or 3 phase outlet. 3 phase charging is extremely inefficient because you either waste up to 3*240W, or using solar battery or grid power.

solar_charging_on_to_off_delay (to handle the case when solar power is not enough to provide min_charging_amps, but wait a certain time to turn off. In order to not frequenctly turn on and off charging)

I am using multiple automations in chain to enable / disable "smart" charging.

Using module would be more convenient because the FSM can easily store inner state making it more flexible to handle edge cases.

@jonasbkarlsson
Copy link
Owner

I will start looking into this. I note that in addition to #212, also #263 is related.

@jonasbkarlsson
Copy link
Owner

jonasbkarlsson commented Aug 31, 2024

First implementation of solar power based charging! See pre-release v2.1.0-dev1.

The core logic is what was suggested by @pluskal. Now this kind of closed-loop regulation can have problem with stability. It's important that the regulation is done slower than how fast the charger is reacting to new controls. In my case, I have a CTEK Chargestorm 2 charger. It takes about 20 seconds from off to full charging current, and it takes a few seconds to change the charging current. So in this version of the integration, I have included a 30 second delay from that the charger is turned on until the first change of charging current will happen, and changes of charging current will then happen at most once every 10 seconds.

The initial delay is maybe not so critical, but if someone has a charger that is slower than 10 seconds to update to a new charging current level, that will probably cause problems. What will happen is that the current will oscillate between the maximum and minimum levels. If this happens, please let me know.

@jonasbkarlsson
Copy link
Owner

Ping to @JakobEgPedersen, @RienduPre, @janneho, @AMajland, @tubalainen, @jonasgustavsson, @gijs007, who have showed interest in solar based charging.

@gijs007
Copy link

gijs007 commented Aug 31, 2024

Thanks for the heads up. If I understand correctly, this feature tries to match the grid export energy and adjust the charge speed on the EV charger accordingly? If so, my EV charger (Alfen) has a feature which matches my home's net solar energy export, and uses this data to makes real-time adjustments to the charging speed, to reduce import/export to a minimum.

What I'd like to see in EV smart charging, is a feature that takes the predicted solar energy generation in account (including perhaps solar export fees/negative energy prices), and adjust/optimize the planned charging moments accordingly.

@tubalainen
Copy link
Contributor

Tjenare! Ok. Thanks for the update.
Time for the "next step" then ;)
See if it is economically viable to solar charge, including based on subsidy's (like is Sweden, we will get 60 öre per kWh exported from the govn. on top of spot price) vs the total cost of importing a kWh to charge the car (not only based on the spot price, but in total, taxes, grid fees etc)... Yes - I know, one can tune the Nordpool sensor to include all of this data.

TL:DL - In Sweden it rarely economically viable to solar charge, hence you get more when you are exporting regardless of the spot price. There has been occasion's recently where the spot price has been like almost -1 kr.. Then yea... I boiled water, charged the car, house battery, ran the tumbler and cranked the AC.

Anyhooow... Thanks for the feature! Will give a try.

@janneho
Copy link
Contributor

janneho commented Sep 1, 2024

In finland it is almost always economical to charge in solar.

For import one pays spot price + transport price (to grid operator, price varies between operators but for me it is about 7,5c/kWh including vat).
For export you get only spot price (+vat). So it is only economical to sell, if spot price is under -7,5snt/kWh.

Many chargers can be toggled between 1 and 3 phases in middle of charge (mine does). So for under 4,2kW there should be automatical switching to 1 phase charging (from about 1,5kW to 3,7kW).

@jonasbkarlsson
Copy link
Owner

@janneho What input control is such a charger using? "Charging current" and "1 or 3 phases"? How fast can the number of phases be changed? Would it be reasonable to limit the change of number of used phases to once every 10 seconds, once every 30 seconds, or once every 5 minutes?

@janneho
Copy link
Contributor

janneho commented Sep 1, 2024

Hi,

Go-e has phase switch like this
363477411-b5a32b08-eaf0-43ae-9dfd-bf7be779af99~2

and current setting from 6 to 16A (or 32A for22kWh model)
363477526-51d4ebd1-fa96-4e66-8299-20234ba892a3~2

Maybe if you can add some entity for switch, and we can then use automation to finally do the phase switch according to that.

Minimum phase switch duration is configured in charger (10s default). It takes a while before car switches from 3-phase to 1-phase charging, so i would suggest that maybe once in 30-60 seconds would be max rate. Maybe this could be adjustable, some chargers may do it faster, or slower than go-e charger. Also car maybe can have its limits too.

@janneho
Copy link
Contributor

janneho commented Sep 1, 2024

Some chargers have allready option for this integrated, you just feed in total power, and it adjusts amps and does phase switching automatically. Atleast go-e and alfen does this (i do not remember if alfen can switch phases - really should, as its my employer :)

@jonasgustavsson
Copy link

Tack @jonasbkarlsson for working on this!
I just tested my charging in terms of changing charging power, and sharing this in case it gives a better idea of how different chargers work:
I'm with a Wallbox charger and a car that only handles 1-phase. Through OCPP I can adjust the amps of the charger. I can change in steps of 1 A, ranging from 6 A to 16 A. A switch takes about 3 seconds. If I set it to 5 A, the charging completely stops.
Looking forward to trying the automatic switch out!

@jonasbkarlsson
Copy link
Owner

jonasbkarlsson commented Sep 1, 2024

@janneho I have a major concern related to dynamically changing the number of phases. The OCPP specification points out that "Switching the number of used phases during a schedule or charging session should be done with care. Some EVs may not support this and changing the amount of phases may result in physical damage."

I recall that there are EVs (can't remember which one) that if you switch from 1-phase charging to 3-phase charging, the car's onboard charger will short-circuit and burn…

Note sure how to handle this. I don't want to contribute to such damage.

Edit: After some searching I found two Zappi forum post related to this issue.
https://myenergi.info/switching-between-1-phase-and-3-phase-loading-t3596-s120.html#p74061
https://myenergi.info/switching-between-1-phase-and-3-phase-loading-t3596-s130.html#p74315

Would it be reasonable to assume that if the charger support change of number of phases, then the charger is responsible to make sure it executes the change in such a way that no physical damage occurs?

@janneho
Copy link
Contributor

janneho commented Sep 1, 2024

I think that it is car that charges from 1 or 3 phases. Changing from 3 to 1 phase does not mean that phases are cut away in charger. Charger only signals to car that 1 phase charging is preferred. Same for changing charge current, charger sends signal to car for preferred charge current

@jonasbkarlsson
Copy link
Owner

There is a significant difference between changing the charge current and changing the number of phases used for charging. The way to perform change of the number of phases seems to be

  • Stop charging
  • Wait a certain time
  • Start charging with a different number of phases

The Zappi implementation uses 90 seconds waiting time.
https://support.myenergi.com/hc/en-gb/articles/17405875921041-Automatic-Phase-Switching

You wrote that the go-e charger has 10 seconds as the minimum waiting time. What instructions do they have regarding this setting? Have you used it yourself?

@enoch85
Copy link

enoch85 commented Sep 1, 2024

The Zappi implementation uses 90 seconds waiting time.

With Easee you can change Phase during charging, but it won't have any effect until the next charging session.

@woopstar
Copy link

woopstar commented Sep 1, 2024

You wrote that the go-e charger has 10 seconds as the minimum waiting time. What instructions do they have regarding this setting? Have you used it yourself?

Hi Jonas,

I also have the go-e and it just defaults to 10s. There is nothing in the documentation that states why / reason. But usually you have it set to auto switch phase based on load power in W. If it's above 4200W (defaults) it will switch from 1 to 3 phases.

I think the Solar integration here is almost there. What you COULD do is to have a phase sensor that is either 1 or 3 or on/off that indicates how many phases to use.

Remember it has to be 3 phases when normal charging is done as it always charges at max power, while on solar it should calculate.

Based on this sensor, one should create an automation that switches or sets phases on their charger.

@janneho
Copy link
Contributor

janneho commented Sep 1, 2024

There is a significant difference between changing the charge current and changing the number of phases used for charging. The way to perform change of the number of phases seems to be

  • Stop charging
  • Wait a certain time
  • Start charging with a different number of phases

The Zappi implementation uses 90 seconds waiting time. https://support.myenergi.com/hc/en-gb/articles/17405875921041-Automatic-Phase-Switching

You wrote that the go-e charger has 10 seconds as the minimum waiting time. What instructions do they have regarding this setting? Have you used it yourself?

Yes i have. It stops charging for 10s (or whatever time is configured), and starts again with newly configured phase setting.
It can also configured so, that charger simulates unplugging, change phase setting and simulate plugging in. I have not used this, as hyundai atleast works fine without it.

@janneho
Copy link
Contributor

janneho commented Sep 1, 2024

EVCC docs has good information about different chargers. HERE

Maybe it can help someone on this.

@jonasbkarlsson
Copy link
Owner

But usually you have it set to auto switch phase based on load power in W. If it's above 4200W (defaults) it will switch from 1 to 3 phases.

@woopstar What does the above mean? Can you use power in W as input, instead of current in A, to the go-e? Or does it mean that can set the current to less than 6 A, and if you do, it will automatically change to 1-phase (if you have set psm=auto)?

If it is the first case (charging can be controlled by wanted power instead of wanted current), then it would open up a different way to control the charger. Not sure if that is preferable, if it can only be used by some chargers.

If it is the second case (lower the 6 A desired current will make the go-e automatically switch to 1-phase), then the current implementatin (v2.1.0-dev1) will be sufficient for go-e, right?

@jonasbkarlsson
Copy link
Owner

jonasbkarlsson commented Sep 1, 2024

A possible solution that could worked with several chargers is

  • Replace switch.ev_smart_charging_three_phase_charging with select.ev_smart_charging_phase_switch_mode (Only 1-phase, only 3-phase, Auto)
  • If phase switch mode is Auto, the integration will use the Zappi implementation, i.e., stop charging, 90 second delay, start charging with different number of phase.
  • The number of phases could be an attribute in sensor.ev_smart_charging_charging_current. Or is it more appropriate to have a separate sensor? EDIT: Will make a new sensor sensor.ev_smart_charging_number_of_phases instead.

@janneho
Copy link
Contributor

janneho commented Sep 1, 2024

But usually you have it set to auto switch phase based on load power in W. If it's above 4200W (defaults) it will switch from 1 to 3 phases.

@woopstar What does the above mean? Can you use power in W as input, instead of current in A, to the go-e? Or does it mean that can set the current to less than 6 A, and if you do, it will automatically change to 1-phase (if you have set psm=auto)?

If it is the first case (charging can be controlled by wanted power instead of wanted current), then it would open up a different way to control the charger. Not sure if that is preferable, if it can only be used by some chargers.

If it is the second case (lower the 6 A desired current will make the go-e automatically switch to 1-phase), then the current implementatin (v2.1.0-dev1) will be sufficient for go-e, right?

It has PV-surplus charging in charger (eco mode). So you feed in your total input power (for whole house), and if it is negative (export), it starts charging and tries to keep export at zero (setting current and 1/3 phase). So it already has this function that we are here discussing buildt in.

See this, and PV-surplus example.

Not all chargers have this, so home assistant is used to automate this.

EDIT. I am thinking that maybe it would be better to use energy sensor. For now we have hourly balance and it is going to 15min in future. Just try to keep import and export equal for every hour (add amps if there is more export than import and vice versa), and hourly balance does rest,
This is propably not what most want, so im ok to do it on separate automation on home assistant.

@AMajland
Copy link

AMajland commented Sep 2, 2024

The Zappi implementation uses 90 seconds waiting time.

With Easee you can change Phase during charging, but it won't have any effect until the next charging session.

With easee you can also change it during charging. It only takes calls to set_dynamic_max with the current for each. If you set the current for all phases (above 6) my VAG MEB car vill charge with all phases. If i then set two of them to zero. it will stop charging and resume on one phase.

My automations has evolved a bit since this - but the principle is still the same https://gist.github.com/AMajland/6ffc6814df2a92e99cff2c901447efee

A helper that decides how charging is done. Automations to change the charge mode (ie from 1 to 3 phases and back) and another to set the current depending on the charge mode. I now also use EV smart charging as an input and have added a mode for negative spotprices

@AMajland
Copy link

AMajland commented Sep 2, 2024

EDIT. I am thinking that maybe it would be better to use energy sensor. For now we have hourly balance and it is going to 15min in future.

At least in Denmark we are charged immediately. The tarif's and spot prices are by the hour (and might switch to 15min) but with solar charging you wants to match the current so as close to zero goes trough the meter. Two principles are used in meters here. Either one that measures each phase independently and one that looks at the sum of them all. All with solar can get the second one (at their own cost) So if i i.e have 3 phased solar producing and the house appliances taking a bit i might have an export of 6,5,4 A

In that case i want to charge with as close as possible to 15A on a single phase. And it should drop as fast as possible when i make myself a cup of coffee or a cloud passes by

@AMajland
Copy link

AMajland commented Sep 2, 2024

I think that it is car that charges from 1 or 3 phases. Changing from 3 to 1 phase does not mean that phases are cut away in charger. Charger only signals to car that 1 phase charging is preferred. Same for changing charge current, charger sends signal to car for preferred charge current

As far as i know the charger only signals the max current by the pulse width signal, but do not have any way of signaling prefered phases.

It is my understanding that when you change the settings the easee charger will stop the charging and then change the relais arround before allowing the car to charge again.

It also allow to draw power for one phased charging from any of the 3 phases. Thats the reason that there is more than 3 relais so i.e 3 chargers on the same circuit can allow 3 cars to charge one phased and the same time with an even load on the circuit

@janneho
Copy link
Contributor

janneho commented Sep 2, 2024

I think that it is car that charges from 1 or 3 phases. Changing from 3 to 1 phase does not mean that phases are cut away in charger. Charger only signals to car that 1 phase charging is preferred. Same for changing charge current, charger sends signal to car for preferred charge current

As far as i know the charger only signals the max current by the pulse width signal, but do not have any way of signaling prefered phases.

It is my understanding that when you change the settings the easee charger will stop the charging and then change the relais arround before allowing the car to charge again.

It also allow to draw power for one phased charging from any of the 3 phases. Thats the reason that there is more than 3 relais so i.e 3 chargers on the same circuit can allow 3 cars to charge one phased and the same time with an even load on the circuit

So it is charger that cuts power from two phases then. That propably is the reason that charging is interrupted, then relays cut power to two phases before continuing.

If charger is dumb enough to just cut power from two phases middle if charging, i can understand that domething can gi wrong then.

@jonasbkarlsson
Copy link
Owner

jonasbkarlsson commented Sep 2, 2024

It is my understanding that when you change the settings the easee charger will stop the charging and then change the relais arround before allowing the car to charge again.

@AMajland Do you know how long the easee charger waits after stopping the charging until it starts charging again?

If charger is dumb enough to just cut power from two phases middle if charging, i can understand that domething can gi wrong then

@janneho The problem is when the charger turns on the two unused phases. Apperently there are some old versions of Hyundia/Kia cars that short-circuited the two unused phases during 1-phase charging, and did not remove the short-circuit in a proper way when the charging was stopped. So that's why Zappi have implemented a 90 second delay in order to give enough time for those cars to remove the short-circuit.

@janneho
Copy link
Contributor

janneho commented Sep 2, 2024

EDIT. I am thinking that maybe it would be better to use energy sensor. For now we have hourly balance and it is going to 15min in future.

At least in Denmark we are charged immediately. The tarif's and spot prices are by the hour (and might switch to 15min) but with solar charging you wants to match the current so as close to zero goes trough the meter. Two principles are used in meters here. Either one that measures each phase independently and one that looks at the sum of them all. All with solar can get the second one (at their own cost) So if i i.e have 3 phased solar producing and the house appliances taking a bit i might have an export of 6,5,4 A

In that case i want to charge with as close as possible to 15A on a single phase. And it should drop as fast as possible when i make myself a cup of coffee or a cloud passes by

That is different from what we have here. Your import and export is metered in hour level, then export is subtracted from import and that is what you pay for. Also it does not matter how import/export is divided in different phases. So here you can have 1 phase pv system, and export continuously in one phase, and have import in two phases. It still cancels out in hourly level.

@AMajland
Copy link

AMajland commented Sep 2, 2024

In my experience it takes around 20s for the whole process (ha scans every 10s and i don't se more than 10-20s drop in power consumption as read from my meter)

  1. api call to easee server to change the currents
  2. The server get the message to the charger
  3. The charger ask the car to stop charging
  4. Cars stops charging
  5. Charger changes the relais around for the new configuration
  6. Charger initiates the charging session again
  7. The cars starts charging again.

and my automation continues adjusting the max_dynamic current 3 times a minute forcing the car to follow.

If there is an residual current error or the car draws more power then allowed the chargecan open the relais. But in normal operation it should not do that

@Peethiplatsch
Copy link

It is my understanding that when you change the settings the easee charger will stop the charging and then change the relais arround before allowing the car to charge again.

@AMajland Do you know how long the easee charger waits after stopping the charging until it starts charging again?

If charger is dumb enough to just cut power from two phases middle if charging, i can understand that domething can gi wrong then

@janneho The problem is when the charger turns on the two unused phases. Apperently there are some old versions of Hyundia/Kia cars that short-circuited the two unused phases during 1-phase charging, and did not remove the short-circuit in a proper way when the charging was stopped. So that's why Zappi have implemented a 90 second delay in order to give enough time for those cars to remove the short-circuit.

I can only speak for my Easee charger with my MG5. I don't use the "switch" functionallity to switch beween 1 or 3 phase charging. I set the A on two phases to 0. When doing so it will stop the charging, waits a bit and then starts charging on one phase again as described earlier.
Since I have no idea if the charger and car are communicating about what they can provide (charger) or handle (car), I would assume some sort of communication or handshaking is happening.

But to make it safer for yourself, maybe you can include a switch like "my car supports switching between 1P and 3P charging". If this is opt-in, people wouldn't get their car shortened because of this automation.

What I think would be important to avoid constant changes between 1 and 3 phase charging is to account an existing home battery into account. Maybe you could let us decide which SOC we would like to retain for the battery. If SOC is above, charging can be a bit more aggressive. If below, charging should be less aggressive that the home battery also gets solar energy to charge.
Right now, I am playing a bit around with it, and if my home battery is full then i charge with 3p 16A to drain the home battery to maximize my personal consumption since the battery works as buffer in both directions. But if my home battery is relatively empty, I might only charge with 3p 6A to have some energy over for the battery. If there is not much sun, then I might switch to 1p, so far this was relatively rare.
And its also important the the automation is not switching immediately between the modes. My car or charger, don't know which of both, doesn't like to switch modes fast. If doing that, it will just not start to charge again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Request of a new feature
Projects
None yet
Development

No branches or pull requests