Using Iammeter to charge Tesla only from excess solar

I thought I would share my latest use of Iammeter. With the assistance of a couple of Iammeter's I have been able to configure the Tesla to only charge from excess solar, and to accurately match the charge rate to achieve that over time. eg if at any one time, you only have 230W of free solar, you can set the charger to your 230W. Note : the granularity you can set the charging of the Tesla is down to 1A. So with 230V supply the minimum charge is 230W (single phase charger). So effectively assuming 230V supply, I can charge at 230W, 460W, 690W, 920W etc up to the maximum charge rate of the charger.

This is an excellent way to use excess and of cheap or free electricity to charge your Tesla and significantly reduces the costs of doing do.

There are other ways to achieve this. eg Chargers that have this functionality if you are prepared to pay and premium for them (eg Zappi chargers), or even some applications that do this if you have a supported solar inverter/battery etc (eg https://chargehq.net/). However, if you don't have the right products, this can be a dead end and/or add significant expense. In may case, because I am already using Iammeters and using the other tools required, effectively I could implement this for free with the tools I already have. But if you had to start from scratch, the bill of materials required are all available for modest up front cost, and nothing I have done requires any on going charges so I believe for a lot of people this will be a very cost effective solation.

A summary of how this works :-

1.    Iammeter to monitor your grid usage (~us$90 - us$160 depending on if you need 3 phase power). This is needed to constantly monitor for grid exports so the system knows when and how much energy is available to charge the Tesla.

2.    Second Iammeter to measure to power the charger is currently using so this can be factored into how much power is free to increase or decrease the charge rate to match grid exports. Though with the right coding, and a VERY small decrease in accuracy, you can probably implement this without this 2nd meter.

3.    I run Home Assistant to controll all of this. This is free and opensource software, so this will always be free. However, you will need some sort of PC to run it on. In my case, I run it on an existing VMWare virtual host, so there is no significant additional expense. If you don't have this, lots of people run this on a Raspberry Pi which is a very low cost option.

In truth the main "expense" of this project for people not familair and using Home Assistant already will be the investment in time to get up to speed with that. This is not hard, and this project is very well supported with lots of documentation and free support. But it is not trivial and does take some time. And for the completely non IT litterate, this is probably going to be a bridage too far. But for those that do invest, they will probably discover a tool that is incredibly useful and be able to deliver and real smart and automated home and you will find yourself wanting to use it for all sorts of things you have never thought about. So well worth the investment.

The good news is I have pulled this together from components that are already delivery and documented, so in this post, I will try and point you at the individual components and references so you can build apon that.

1.    You will need to get Iammeter to measure your grid export and get it installed. If you have 3 phase power, you will need the 3 phase version. Install this and set it up as part of the standard Iammeter documentation. While not mandatory, I would highly recommend getting the latest firmware version which supports ModbusTCP as this allows 1 second reads of the meter (at least i.75.97.9.bin), and this will allow more accurate and granular adjustments to the charge rate as loads in the home and solar output fluctuate over time. See https://imeter.club/topic/11 and https://www.iammeter.com/docs/firmware-upgrade. The other reason for this is if you have 3 phase. The basic Iammeter integration into Home Assitant did not expose a value for the Net metering of the 3 phases whereas the ModbusTCP implementation did allow this. Again, there are likely other ways to achieve this, but this is the way that worked best for me. The final element if you have 3 phase power, AND like Australia, you Energy authorities bill for "Net Metered" power, you will want to make charges as outlined here https://www.iammeter.com/docs/net-energy-meter. "Net Metering" means the energy authority will only bill you for the "Net" usage across the 3 phases in total, rather than billing you for each of the phases individually. This is certainly how 3 phase is billed in Australia for residential users, and I suspect this will apply to other parts of the world as well with 3 phase.

2.    While we are on Iammeter, while probably not mandatory, I would recommend an Iammeter to measure the power to the Tesla charger. If it is 3 phase, you will need a 3 phase Iammeter. If it is single phase, you only need single phase Iammeter. I myself built and tested all this with the Tesla Mobile Connector charger that plugs into any power point. So I used a single phase Iammeter and built that into a box so it couple plug into any power point before the charger. But in most cases, I suspect this would be permanently installed before whatever charger you are using.

3.    Install Home Assistant on your prefered platform. This is a big topic, so probably best to refer you here https://www.home-assistant.io/

4.    You will need to run and install the Tesla integration in Home Assistant to get access to all the Tesla details and be able to set a charge rate. See https://github.com/alandtse/tesla. Your will probably want to install and get up to speed with HACS to get this going. See the previous links for details on this.

5.    You will want to get the Iammeter integrated with Home Assistance. There is more than 1 way to do this. For an overviews of different options to do this, see https://www.iammeter.com/docs/summary-home-assistant#modbustcp-sensor. My strong recommendation is to use the ModbusTCP implementation to give you 1 second readings, and also access to the combined energy totals for the 3 phase meters. This is probably not as well and clearly documented as I would like that is an easy way to find. But the summary you need to add them manually to you configuration.yaml configuration file for the Iammeter meters. There are example files here : https://github.com/lewei50/Solar-PV-Monitoring/tree/master/Yaml%20in%20Home%20Assistant/ModbusTCP  . The Modbus.yaml is the extract for the 3 phase meter. The Modbus1.yaml is for the single phase meter. Adjust for your devices. But I would also recommend adding "scan_interval: 1" to the end of the Modbus_Power_SUM section or the Modbus_Power section. This will allow 1 second interval readings.


6.    How you have all the data and knobs to put this together. The only thing needed now is to automate it. What I put together was basically gleaned from this rather long thread https://community.home-assistant.io/t/optimizing-use-of-unused-solar-power-to-charge-a-tesla/340818/70. But in thruth, the begging of the thread is outdated, and if you go through you will see there are significant improvements. But the summary of what I did, was create a script in scripts.yaml that simple subtracts the power from the charge Iammeter from the Grid export power and does some sums to convert that to Amps and then uses that to set the charging Current for the Tesla. My script is as follows :-


```

tesla_set_charge_rate:
  alias: Tesla set charge rate
  description: set Charger rate
  sequence:
     - alias: set charger Rate
        service: tesla_custom.api
        data:
           command: CHARGING_AMPS
           parameters:
             path_vars:
                vehicle_id: 'xxxxxxxxxxxxxxxxxxxxx'
             charging_amps: '{{ (((states(''sensor.Modbus_Grid_Power_SUM''))| float -(states(''sensor.modbus_plugin1_power''))| float)| float *-0.0039 )| int }}'

  mode: single

```

Note : In the thread I reference above, they had a programatic way of getting the Vehicle_id which is probably better. However that did not work for me, so I manually set it. In truth I can't remember where I got this from. But I suspect it was from somewhere on the main screen of the car.

Whenever the script above runs, it will set the charge rate to try and use and spare solar. Things to note about this :-

-    Setting a negative charge rate (ie we are probably importing power to the home), just sets the charge rate to zero, and no charging is happening while is what we want. Though I suspect because it is still charging zero A, the car does not go to sleep, and I think if you left it like this over night, there would be slightly more vampire drain on the battery than actually stopping the charge. So suggest addressing this is the automations to turn off the charging at least after sunset.

-    There will be times where there more excess solar than the charger can use. In this case, the script will set the Amps higher than the charger can delivery. This does not seem to be an issue, and it will just charge at the max rate of the charger, so I have never bothed to address it in the script (ie if charge rate is above max charge rate of the charger, only set max charge rate of the charger).

7.    The final step is to automate the running of the script. So I create and "Automation" which does the following :-

-    triggers every 2 seconds

-    Has 2 conditions to make sure the car is at home and Confirm it is between Sun up and Sun Down.

-    If the conditions above are met, it sets the charge rate.

8.    I also have a script the turns the charger on at Sunrise, and Off and Sunset.


Then it is just a matter of plugging the car in when I get home. If it is after sunset, I need to turn the charger off to stop it charging over night (or leaving it on if I want to manually top it up over night).

You could expand on this to suit your own circumstances. eg I might set some rules to charge the car to 40% if less than 40% to give some range for the next day if it is used before solar can do its thing.

I hope this is useful to someone.




Thread Status
16
1583
5
10
8

Sort replies by:

Hi Matthew Swainston:

I have just reread your solution. It is very cool.
We have been looking for solutions (with our energy meter or system) to help customers use the excess solar output effectively, like this topic.


1 I want to let more people know about this solution, if you do not mind, I want to add some content about this solution in our next notification, is it OK?

2 Have you used the IAMMETER-cloud, if so, please check the difference of the "direct self-use rate" in this report, before and after this solution had been implemented. It should be an interesting attempt to try to quantify the optimization results with this parameter("direct self-use rate").



3 This activity still continues

https://www.iammeter.com/newsshow/activity-210618

I think this article can win the 2nd prize(one WEM3080)
Please contact us in your feedback system(https://www.iammeter.com/docs/feedback-and-notification), my colleague will help you to send the award out.


Thanks again.

Jason

@laoliu

1.    Yes, I am happy for you to share. That is why I posted it. In truth, there is probably plenty of scope to improve my documentation, as I put that together pretty quickly. So happy for you to do that as required.


2.   Yes, this is the ideal type of load to help with "Direct self use" because 1) it is a significant load and thus able to soak up a LOT of solar, and 2) because unlike lots of other loads, I can set it very granularly in terms of size of the load (with my current charger from 230W to 3500W....and when I get a 3 phase charger I expect that to be from 690W to about 11kW), but also how often I can adjust the load so I can pretty presicsly match and use any excess solar. The other advantage this sort of load will have in improving sell use, is because it is a very large load and for a lot of people will be one of the largest loads in the typical house. I suspect I will need about 20kWh a day on average, and this will soak up a lot of solar. Of course, some of that won't come from solar, as the car is often away at work during the day, so unable to use solar in these times. But I still use Iammeter/Home Automation to help with that as well. I am on TOU pricing here in Australia. For context, my peak rate is about 58c, Shoulder 28c and off peak about 21c, with solar export at just 7.5c. So obviously, my cheapest time to charge is from solar, and thus the intergration to match charging to excess solar. But I have also setup Automations to cover any charging I can't meet from solar from off peak power. I will outline that in another post.

And yes, of course, I can see improvements in the direct self use % in the cloud report. But there are other integrations I have also done to help with that, such as automating my pool pump to run based on the solar which I might make a seperate post about. When my off peak power was very cheap (in fact cheaper that my solar FiT), there was no need to do this, as I could run at night. But now the tarrifs have risen, and Solar FiT have dropped there is a good economic benefit in getting things to run more from solar. The nice thing about the pool pump running is it is well suited to being run when there is solar as the amount of pool run time required to generate chlorine from a salt water pool, is proportional to the amount of sun because it is the sun that destroys the chlorine. So on overcast days, you need less run time to replace the Chlorine that is burnt off, and on long sunny days you need more, but you have more solar to run the pump with.

3. Thanks for that. I can always use more meters to build useful things with. In fact what i really need is a 3 phase meter, so scale my project up from the single phase charger, to the 3 phase charger which will turbo charge this.

 

Hi Matthew Swainston:I have just reread your solution. It is very cool.We have been looking for solutions (with our energy meter or system) to help customers use the excess solar output effectively, like this topic.1 I want to let more people know about this solution, if you do not mind, I want to add some content about this solution in our next notification, is it OK?2 Have you used the IAMMETER-cloud, if so, please check the difference of the "direct self-use rate" in this report, before and a

@laoliu


I should throw out 1 more suggestion for you guys. My Iammeter/Home Assistant/Tesla intergration is very powerful and flexible and customisable which makes it perfect for someone like me. But in truth, getting all this up a running is complex, and will be out of reach of some of your customers. With that in mind, can I suggest you consider looking at https://chargehq.net/ and more specifically working with them to get your Iammeter integrated into their solution. Their solution is nice, because at this stage it is free and I suspect will largely eliminate the complex Home Assistant setup. The prize for everyone is a simple, cost effective solution to do what I have done in this post without the complexity of Home Assistant and not trivial integration of Tesla and Iammeter. I suspect if you can do that, it will be an easy path to sell you meters to a whole new base of less technical users.

In fact, it sounds like that are actively look for partners like you as I suspect you solve a problem for them in that they only have limited support via specific inverters and batteries. From https://chargehq.net/partners, they say "New partners with stand alone, solar compatible energy monitors are actively being sought to enable compatibility with solar inverters we're unable to integrate with". They do support Solar Analytics which opens there solutions up to more offerings. But solar Analytics is more expensive than your offering. 

Anyway, I think this is definitely worth you considering. And of course, it probably would not be beyond your reach to implement this on you own cloud platform :). 

I should mention, that once you have Iammeter/Home Assistant/Tesla integration, what I have put above is just scratching the surface of what you can do. For example, charging an EV only from solar for most people will have its limits as the car is often not at home when the solar is available. Charging overnight is the easy solution to this. But from a financial point of view, you really only want to do this just enough to get you to the point where the car is at home for the solar to charge it. And for this, it is nice to use some of the other automatics you can configure to provide more intelligence to this.


For background, in my particular case, my tarrifs for power and feedin is peak rate is about 58c, Shoulder 28c and off peak about 21c, with solar export at just 7.5c. So obvously, the more charging from solar the better. But next best is for me to automate the charging to only happen off peak which for me is 10pm to 7am. Fortunately with Home Assistant this is relatively to setup whatever way you want. The way I have set this up is as follows :-

1.    I have a numeric slider input control on my dashboard which allows me to set a minimum charging range that I want to charge up over night. The automations I setup will use this to start charging if the charge is below this, and stop charging when it charges up to this range. eg If I know I need 100km tomorrow before the solar will have a chance to charge it, I might set this to 200km (100km for the driving plus 100km for surprises and prevent running battery 2 low). But if I know the car is going to be at home tomorrow and able to charge from solar, I might set this to 50km so it does not charge over night and can do all the charging from solar.


2.    I then setup an automation that runs at 10pm (start of off peak), and if the car is at home, and battery is below the treshold, turn the charger on at full power.

3.    I then setup another automation which turns off the charger when the battery hits the charge threshold.


Putting it all together :-

1.    from sunrise to sunset, charger charges from excess solar (which their may or may not be at any point in time).

2.    from 10pm to 7am, it charges to a defined threshold that can be adjusted each day based on expected usage and other factors.

3.    Home Assitant has all sort of 3rd party intergrations for things like solar forecasts for the coming hours and days as well as other tools which can tell you how much CO2 your energy is requiring. The solar forecasting can be used to refine how much charging you want to do over night (eg if it is very overcast the next day, you might decide to do more charging at night.

The use of the input slider, means it can be very much set and forget with the right values, or if you want you can optimise it every day.

Anyway, it is all totally customisable to suit your own individual requirements.

 

Hi, swainstm:


Could you please help us to provide some pics for this article?
The content of this article is very consistent with the original intention of our product, helping customers to maximize the use of solar power to save money.

we want to use it as one of the solutions that use the IAMMETER energy meter + Open source platform(Home Assistant).


Thanks

Jason

Happy to help with the articule. Lety me know what you want. Happy share more specific config.

What I have already works pretty well. Here is what happened today with a day that was patchy overcast all day and is a natural challenge to anything trying to balance solar and loads to try and eliminate grid import because the patchy nature means solar output is constantly fluctuating. 


"Modbus_Plugin1" is the meter that is measuring the Tesla charger. Modbus_Grid_power is the grid import/export. The goal is to keep this below zero while also maximising charging rate. Modbus_Solar_Power_SUM is the solar output which you can see is extremely variable due to conditions. As you can see, allow significant charging, almost all from solar despite it being a challenging day. Today I only have a little 3.5kW mobile charger. I intend to get the 11kW 3 phase solar which will significantly increase the rate of charge, and the excess solar I can use.

Below is the same thing, but zooming in on an area where solar is marginal requiring the solar to work hard to maximise the solar and charging.



Hi, swainstm:Could you please help us to provide some pics for this article?The content of this article is very consistent with the original intention of our product, helping customers to maximize the use of solar power to save money.we want to use it as one of the solutions that use the IAMMETER energy meter + Open source platform(Home Assistant).ThanksJason

Hi swainstm:

We have just had a meeting and all agree to send you a 3-phase energy meter(WEM3080T-150), which can be used to monitor your three-phase charger.
They may contact you in our feedback system later.
My colleagues are preparing a tutorial like
"how to efficiently use your excess solar inverter output through HA and IAMMETER`s energy meter"
The content may introduce your post as an example and abstract the specific implementation process (such as controlling the charger of the EV) as a "black box".
Thanks again.

laoliu

Thanks. I will put that to good use as I install the 3 phase charger.

Let me know what you need from me to help with your put together your tutorial.


Hi swainstm:We have just had a meeting and all agree to send you a 3-phase energy meter(WEM3080T-150), which can be used to monitor your three-phase charger.They may contact you in our feedback system later.My colleagues are preparing a tutorial like"how to efficiently use your excess solar inverter output through HA and IAMMETER`s energy meter"The content may introduce your post as an example and abstract the specific implementation process (such as controlling the charger of the EV) as a

Absolutely amazing!

Sure does make sense with such a low feed back tarriff and integrating ChargeHQ into iammeter would make life easier for a lot of folks.

Thanks for posting in so much detail, appreciate it.


This post brings us a very interesting idea, simulate the load profile and try different control algorithms to get a better result.
So we develop a simulator like this.

https://www.iammeter.com/docs/simulator-intro

Great solution but it is a bit less efficient that I've done in my home.

On Home Assistant as a platform, I implemented IamMeter (modulus option) and TWCManager (mqtt option) (https://github.com/ngardiner/TWCManager) for charging of my 2 Tesla's.

This combination working amazing.

This is how it looks like on a ⛅️ cloudy day.


Thanks for this. I was looking to exactly that but opted for the python option. Here is a novice script which I'm using below. 

Apologies the imeter forum removes the indents. 


## set tesla charging current https://pypi.org/project/TeslaPy/
## based on measured power at meterbox
## iammeter https://www.iammeter.com/newsshow/news-modbus-tcp-energy-meter
## dependent on the meter instant kW value.
## Charger current is modulated between
## 5A
## 16A
## Written by S.Willesee
## Last update 29/10/2022

print("EV charger script. Adjusts current charging rate per Meterbox power")

ldval = 10

import time
import pymodbus
from pymodbus.client.tcp import ModbusTcpClient as ModbusClient
from pymodbus.constants import Endian
from pymodbus.payload import BinaryPayloadDecoder
import teslapy
with teslapy.Tesla('elon@tesla.com') as tesla:
tesla.fetch_token()
vehicles = tesla.vehicle_list()
vehicles[0].sync_wake_up()
vehicles[0].command('CHARGING_AMPS', charging_amps=ldval)


PowerMonitor = ModbusClient(host='192.168.0.202', port=502)
PowerMonitor.close()


while(True):
#time.sleep(10) # delays for 10 second
try:
PowerMonitor.connect()
pr = PowerMonitor.read_input_registers(3, 1)
decoder = BinaryPayloadDecoder.fromRegisters(pr.registers, Endian.Big) #get from power meter
W = decoder.decode_16bit_int()
print (str(W) + " WATTS")

if(W < -300)and(ldval < 16): #if less than 16A charging and exporting more than 300W
ldval =ldval + 1
#print ('ldval', ldval)
with teslapy.Tesla('elon@telsa.com') as tesla:
tesla.fetch_token()
vehicles = tesla.vehicle_list()
vehicles[0].sync_wake_up()
vehicles[0].command('CHARGING_AMPS', charging_amps=ldval)
print ("charging at " + str(ldval) + " AMPS")
time.sleep(3)

elif(W > -10)and(ldval > 5): #min charge rate 5A
ldval =ldval - 1
#print ('ldval', ldval)
with teslapy.Tesla('elon@tesla.com') as tesla:
tesla.fetch_token()
vehicles = tesla.vehicle_list()
vehicles[0].sync_wake_up()
vehicles[0].command('CHARGING_AMPS', charging_amps=ldval)
print ("charging at " + str(ldval) + " AMPS")
time.sleep(3)

elif(W > 0)and(ldval == 5): #min charge rate 5A
print ("at min sleeping for 60 sec")
time.sleep(60)

else:
pass
print("nothing to do")
time.sleep(30)

PowerMonitor.close()

except:
time.sleep(10) # delays for 10 second
pass
print ("pass")

@usmanhayat. Yes, 100% agreed. I have not use ChargeHQ. But I suspect if ChargeHD / Iammeter could get Iammeter supported in chargeHQ, or have one of the supported solar inverters, batteries or monitors this looks like the easiest solution. The main downside is at some stage I am guessing that they will want to monitise it, and at that stage the end user is likely to end up paying.


HomeAssistant/Iammeter/Tesla Integration option I outlined is extremely powerful, infinitely flexible to configure to your requirements. Downside is unless you are already running HA there is a bit of a learning curve.


But I thought I would give everyone here an update. The Tesla Home Assistant has undergone a major upgrade. This makes it simpler and easier. But does change the config required. I have also upgraded my 1st attempt to suit the new integration, but also make improvments in a range of areas.  Performance is excellent with all Tesla charging happening almost entirely from spare solar all the way up to the max charge speed of your charger (and of course the excess solar available to you). Right now I am limited to the portantly 3.5kW portable charger. But once I get the new charger installed that should go all the way to 11kW and increase utilisation of spare solar and charging speed. I say "almost entirely" because all these solutions are always trailing any changes big changes in both power usage in the home and changes in solar output. So performance in accurately tracking grid exports will always be limited by how fast you read all the respective meters, and how quickly you can implement the changes. As we can read the Iammeter every second (which is pretty good compared to the granularity of some other solutions), there will be 0 - 1 seconds of delay there. Calculations in HA would be almost instant, but I have an automation that samples every second. So that adds 0-2 seconds. But I suspect the slowest but might be the update of the Tesla API in the cloud and then I assume that sending update to the Tesla and I suspect there is a small rampup/rampdown there. I have analysed that, and I it looks like even on massive power swings, there is only a small overshoot either way, and any associated imports tend to be small and short (maybe 2-8 seconds max). So this is very granular tracking, that in truth most solutions would not even be granular enough to notice.


I have outlined this in some details in a thread on the HA community forum on the issue. So rather than repeating here, have a look at 2 posts on did 23/11/2022 here :-

https://community.home-assistant.io/t/optimizing-use-of-unused-solar-power-to-charge-a-tesla/340818/147


Hi:

Could you mind showing us some more?
what would the self-use rate be now?
we are planning to support smart ev chargers in the IAMMETER system , 

https://imeter.club/topic/461

looking forward to hearing about your thoughts and suggestion

BR

Laoliu

@usmanhayat. Yes, 100% agreed. I have not use ChargeHQ. But I suspect if ChargeHD / Iammeter could get Iammeter supported in chargeHQ, or have one of the supported solar inverters, batteries or monitors this looks like the easiest solution. The main downside is at some stage I am guessing that they will want to monitise it, and at that stage the end user is likely to end up paying.HomeAssistant/Iammeter/Tesla Integration option I outlined is extremely powerful, infinitely flexible to configure
Looks like you are new here. Register for free, learn and contribute.