I am trying to set up an automation to charge my Tesla with excess power from my solar panels. Every 30 seconds (in the daytime, and if the car is plugged in) the export or excess power from the house electricity meter (pow_k) is measured. The idea is to keep the export power close to 0, by adjusting the charging amps of the car. If it is above 688w, the Tesla charging amps will be increased by 1. If it is below, they will be decreased by 1.
HA gives the error message Message malformed: expected float for dictionary value @ data[āvalueā]. Any assistance to this novice would be greatly appreciated.
alias: Charging EV (T-Ray) with excess solar power
description: ""
trigger:
- platform: time_pattern
seconds: "30"
condition:
- condition: sun
before: sunset
after: sunrise
- type: is_plugged_in
condition: device
device_id: b4929c45bca6cfb24b68e22f7f0f9977
entity_id: binary_sensor.t_ray_charger
domain: binary_sensor
action:
- if:
- type: is_power
condition: device
device_id: 5ab015508a4f0ce2f17d992b8f68c3f0
entity_id: sensor.pow_k_po
domain: sensor
above: 688
then:
- device_id: b4929c45bca6cfb24b68e22f7f0f9977
domain: number
entity_id: number.t_ray_charging_amps
type: set_value
value: {{ (states.number.t_ray_charging_amps.state | int ) + 1 }}
else:
- device_id: b4929c45bca6cfb24b68e22f7f0f9977
domain: number
entity_id: number.t_ray_charging_amps
type: set_value
value: {{ (states.number.t_ray_charging_amps.state | int ) - 1 }}
mode: single
Hi! Iām looking to create an automation to do the same thing.
A couple of questions:
I think your automation will constantly adjust 1 A up or down every 30 seconds. Currently there is no option for it to leave the charging current as it is.
The Tesla app has a minimum set charging current of 5 A. Does the API allow it to go lower? Edit: it does! I thought you had to do a minimum of 5 A charging. Thatās cool!
Seeing the current to 0 (zero) amps and turning it on seems to draw around 400-500 Watts, but Iām not sure it charges the car. I think it just powers on the onboard charger. So I think the efficiency will be very low at low amps.
My electrical bill is net metering per hour (if import == export within a clock hour, my bill will be zero), so I might want to do things in bursts of 5A for low solar surplus, if that increases charging efficiency.
I will post my automation here when I get it woeking, either with or without burst charging.
True. I just had troubles to make the value statement (+/- amps) working. Now I start building the complete set of triggers, conditions etc. around the +/- amp function.
Also agree on the probably low efficiency at low amps, but want to try it and see how it works.
I will post as I progress and appreciate your thoughts.
Currently Iām charging my car with 6 amps. And āsensor.omcsbln02t_export_to_gridā is below 0.6 so it should change the amps to 5, which it actually seems like its trying, but nothing happens.
There is something in value: called ācurrent_ampsā. Iām not sure what this value/sensor is, and maybe this could be the issue. I just thought that as soon as it gives the right value, it would change number.charging_amps to this value?
I wondered why you made the long list of conditions. Is there any obvious reason that you couldnāt just calculate the number you want to adjust the charging current with?
E.g:
And another thing: Did you choose the 30 seconds interval for some specific reason?
I donāt have a better value, but I choose every 5 minutes and made the export value a 5 minutes moving average.
Just because I thought it was too often to adjust the charging current more often than this. But I have no strong considerations behind my choice.
Thanks for your input. Calculating the charging current adjustment is definitely more rational. I just got down another avenue and blindsighted on that obvious improvement to the code.
The 30 second interval is because I want to adjust close to real time, so that any change in solar production (for instance a cloud passing) and house consumption (for instance a thermostat turning on the electric heating in my garage) is (almost) immediately reflected in the charging amps. Thus minimizing the import of power from the grid.
Here is my updated code:
alias: T-Ray solar charging
description: ""
trigger:
# Time interval for triggering set
- platform: time_pattern
seconds: "30"
condition:
# Continue if T-Ray is plugged in charger (or exit)
- type: is_plugged_in
condition: device
device_id: b4929c45bca6cfb24b68e22f7f0f9977
entity_id: binary_sensor.t_ray_charger
domain: binary_sensor
# Continue if T-Ray SOC is below 1% of charge limit (or exit)
- condition: template
value_template: >-
{{(states('number.t_ray_charge_limit') | int -
states('sensor.t_ray_battery') | int) > 1}}
action:
# Continue if more than 688w EXPORT power is available (else)
- if:
- type: is_power
condition: device
device_id: 5ab015508a4f0ce2f17d992b8f68c3f0
entity_id: sensor.pow_k_po
domain: sensor
above: 688
then:
# Turn ON charger if it is OFF and continue (or just continue)
- if:
- condition: device
type: is_off
device_id: b4929c45bca6cfb24b68e22f7f0f9977
entity_id: switch.t_ray_charger
domain: switch
then:
- type: turn_on
device_id: b4929c45bca6cfb24b68e22f7f0f9977
entity_id: switch.t_ray_charger
domain: switch
# Calculate number of charging amps to add relative to current EXPORT power (Note: If current EXPORT power is below 688w -> no change)
- service: number.set_value
data_template:
entity_id: number.t_ray_charging_amps
value: >-
{% set current_amps = states('number.t_ray_charging_amps') | int %}
{% set add_amps = (states('sensor.pow_k_po') | int / 688) | round(0,'floor') %}
{{ current_amps + add_amps }}
else:
# Check if power is being imported
- if:
- type: is_power
condition: device
device_id: 5ab015508a4f0ce2f17d992b8f68c3f0
entity_id: sensor.pow_k_p
domain: sensor
above: 0
then:
# Turn OFF charger if power is being imported, but current charging power is below 550w and exit
- if:
- type: is_power
condition: device
device_id: 3efa4551c778fefe170f4c0c7b4dad6f
entity_id: sensor.go_echarger_110504_nrg_12
domain: sensor
below: 550
then:
- type: turn_off
device_id: b4929c45bca6cfb24b68e22f7f0f9977
entity_id: switch.t_ray_charger
domain: switch
else:
# Calculate number of charging amps to subtract relative to current IMPORT power (Note: If current IMPORT power is below 688w -> no change)
- service: number.set_value
data_template:
entity_id: number.t_ray_charging_amps
value: >-
{% set current_amps = states('number.t_ray_charging_amps') | int %}
{% set sub_amps = (states('sensor.pow_k_p') | int / 688) | round(0,'floor') %}
{{ current_amps - sub_amps }}
mode: single
Hi there,
Many thanks for all your work. I am a full novice to coding
Got enphase solar, a shelly that shows the net total returned to the grid (positive value) or negative value if I import.
Also go 2 tesla home.
Got an issue: amps rapidly rocket to the max (32A) and then stop, but it seem to not adapt.
Here is the code, if you could help
OP, is 688 the standard power draw for your house? I keep getting errors saying 17 is out of the range, which it is. 16 is the max ampage for my house.
Iām trying to work out where the math is going wrong.
Hello everyone Iām new here, Iām trying to figure things out ! (Sorry for my bad English, Iām french !).
I just bought 6 solar panels for 2.88kw (plug and play), and of course, I would like to charge my tesla with the excess power instead of putting it into the grid. Home Assistant seems to be awesome and I canāt wait to get it (just bought a raspberryPi). You code is awesome, but how you car is connected, I mean with an EvStation (Mine is 7kw/h) ? Through a connected plug (max 3kw/h) ? Thank you !