Optimizing use of unused Solar Power to charge a Tesla

@icepicknz

when you plug in the charger, I don’t think it would change the car at 32A (even if that is what the car is set to). It slowly ramps up in a few seconds. You just have to make sure you automation kicks in just in time to change the AMPS. For that to work I would

  1. first add the charger sensor (binary_sensor.red3_charger_sensor) to trigger entities. So that the the automation gets triggered as soon as you plug in the charger (hopefully before it ramps up all the way up)
  2. in the main section put in the logic to check the status of the other car and set the AMPS to appropriate levels.

I’m guessing the charge rate is the max (32A for single phase), and powerwall_reserve is self explanatory. I dont however see in the script how you are changing the Amps to match solar production and only use what would normally be exported to the grid?

I dont need to do that because of my unique situation (solar prod = powerwall max delivery). Occasionally I change it manually by sliding the target_charge_rate slider. Anyway you can call the service as below. Its part of my start_tesla_charging in my code.

hass.services.call('tesla_custom','api', service_data={ 'command': 'CHARGING_AMPS', 'parameters': { 'path_vars': {'vehicle_id': vehicle_id }, 'charging_amps': target_charge_rate}})

OK, I think I’ve made progress - thanks for your tips cpuram. You were right the input number needed to be renamed to target_charge_rate. I missed the change in your python script.

I can now manually set the Amps charge rate via the ‘target_charge_rate’ input number.

I’m a little confused by your statement above, in relation to matching excess solar production to the Amp charge rate: “I dont need to do that because of my unique situation (solar prod = powerwall max delivery).”

Could you elaborate a bit on your situation and what you mean by this? Surely you would still want to optimise the use of excess solar to match your car charge rate?

Either way, I would like to expand this so that the Amp charge rate of the car is matched to the excess solar production. Being a newbie to Hass (and not a python coder) do you have any tips on how I could do this?

I assume I would have to utilise one of the powerwall HA sensors and match grid export power to set the target_charge_rate input number?

Any help appreciated :slight_smile:

@Chacsam
Have you changed anything to your coding or elsewhere since you’ve posted this ? I intend to create the exact same (also including homewizard p1)

Basically no.
As I have an old MCU1 model S, I didn’t get the API update allowing me to tune charging rate, I stuck with on/off :wink:

I have MCU2 and use and will keep on using on/off, for now. I drive enough so charging on the remaining of my solar panels wouldn’t bring me very far (literally :grin:).
Could be that this changes in summer (my max solar panel output on the best summer day is 40 kWh).
Have to say I don’t have a home battery.

Hmm I’d definitely need it to be able to also change the amperage automatically. I have 60kw days in the summer and it would be nice to push all excess on the car without suddenly having high peak if the sun is gone for a bit.

I first need to find a raspberry pi which is difficult given chip shortage, or an odriod n2+ which seems more easy to get (does it really matter?)

Good Morning,
I have just read in the 2022.2 release notes that HomeWizard has become an official integration.
Might be useful to start from that one at once:

I have tried to use (kind of all) options but i am still not there yet. I landed on the @Chacsam one for now which i inputted in the visual editor as putting the code in the YAML did not work so i must have done something wrong there

So now it works when i press ‘run action’, but it does not seem to trigger it on its own? Is there anyone who can help me with this? the below is what i have

alias: TeslaStartCharging
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.p1_meter_<notsureifIshouldshowthisid>_active_power
    below: '0'
    for:
      hours: 0
      minutes: 0
      seconds: 20
condition:
  - condition: state
    entity_id: device_tracker.tesla_model_3_location_tracker
    state: Away
  - condition: state
    entity_id: binary_sensor.tesla_model_3_charger_sensor
    state: 'on'
  - condition: state
    entity_id: switch.tesla_model_3_charger_switch
    state: 'off'
action:
  - service: switch.turn_on
    data: {}
    target:
      entity_id: switch.tesla_model_3_charger_switch
mode: single

alias: TeslaStopCharging
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.p1_meter_<notsureifIshouldshowthisid>_active_power
    above: '1500'
    for:
      hours: 0
      minutes: 0
      seconds: 20
condition:
  - condition: state
    entity_id: device_tracker.tesla_model_3_location_tracker
    state: Away
  - condition: numeric_state
    entity_id: sensor.tesla_model_3_charging_rate_sensor
    above: '2'
  - condition: not
    conditions:
      - condition: state
        entity_id: switch.tesla_model_3_maxrange_switch
        state: 'on'
action:
  - service: switch.turn_off
    data: {}
    target:
      entity_id: switch.tesla_model_3_charger_switch
mode: single

Once this works i would like to see if i can also change the amperage based on excess solar available

Your condition is on “Away”

condition:
  - condition: state
    entity_id: device_tracker.tesla_model_3_location_tracker
    state: Away

That means that the automation only kicks off when the car is not at home.
Could that be the issue? (You can also check the trace of the automation when clicking on the clock)

@Chacsam

I thought I explained that in my post but apparently I did not save that part.

The location always shows ‘away’ so I probably have to adjust some settings in the car itself

So I don’t think that is the issue at this point as it is constantly on ‘away’ in case.

Screenshot_20220205-182650_Home Assistant

I have a feeling I have just forgotten something very stupid here so that it actively checks every X seconds or minutes or so. Like a loop Function if that makes sense

OK, Slice the elephant.
As the condition is not relevant here, remove it from your automation.
The technical state for “Away” is “not_home”, so your condition should match “not_home” anyway.

A test you can do is manually activate the switch from the services tab in the development tools. Does that work?

Ok @Chacsam I sliced the elephant and took out the location condition

Yes?, I was able to run both automations in developer tools - services

How about the “Switch: Turn on” service, does it do what it should?
If yes, review your automation;
If no, then you have an issue with the Tesla integration, which might be more complex to solve.
Good luck

it seems like the problem was that the values of the P1 meter need to ‘cross’ the trigger point ie, it only triggers when the p1 meter goes from a level below my trigger point to above my trigger point (for stopping to charge) or from above to below (for starting to charge). I did not realize that this is how the trigger worked , and would have assumed it works more as a ‘if this then that’. So now it does seem to work

read it here

thanks you so much, now the next step is to figure out how to get the amperes settings to work

@Maart84 would you mind sharing your code and calculations?
3 phase 230v?

@markpurcell I thought i got it but for some reason the code that you use does not work for me. For now i have been trying just to get a fixed value inputted. I don’t get any error message, the values don’t seem to stick / be transferred to the car, but the car does react

So what i do is: i simply run the script in the scripts section, while the car is already charging
When I look in the tesla app one of two things happens:

  1. the value of the charging drops to 5A, and then within 30 seconds goes back to the value it initially had, e.g. 16A
  2. the value drops to 0A (charging 2km/hr) and moves to 5a 30 sec or a minute later or it stays at 0

So the value never goes to value i have asked for, in this case 9A. Would you or anyone else have any idea why this does not work?

service: tesla_custom.api
data:
  email: [redacted]
  command: CHARGING_AMPS
  parameters:
    path_vars:
      charging_amps: '9'
      vehicle_id: '{{ state_attr(''binary_sensor.tesla_model_3_online_sensor'', ''id'') }}'


If the command is getting across that means the service call is working correctly.

There must be s something else (another app) which is changing the setting

Do you use charge hq, teslafi or teslamate?

hi @markpurcell , no I don’t actually, have never used any of them. I only have the official tesla app itself, now HA, the tesla tokens app for the token. are there settings in the car that could impact this?

ok, edit: I have it now. the syntax on this thing is driving me insane :slight_smile:

main issue was that the ‘charging amps’ had to be on the same line as the ‘path vars’

service: tesla_custom.api
data:
  email: [redacted]
  command: CHARGING_AMPS
  parameters:
    path_vars:
      vehicle_id: '{{ state_attr(''binary_sensor.tesla_model_3_online_sensor'', ''id'') }}'
    charging_amps: '9'

thank you for your help

Maybe one more question: would anyone know what the value in the command section and in the parameter section should be in case of trying to set the charge limit? i would have assumed (command) ‘charge_limit’ in stead of ‘CHARGING_AMPS’ and in parameter section ‘percent’ in stead of ‘charging_amps’ but apparently i am not understanding the documentation well ( Charging - Tesla JSON API (Unofficial) (timdorr.com))