Solar production/EV charging flow rate. Can NR control it?

I have a Tesla Model 3, Tesla Solar with a PowerWall, and a Tesla Wall Charger. I can control the charge rate on the car from 5A to 48A. At 48A, the draw is ~15kwh, and at 5A the draw is 1kwh.

I’m trying to let NR/HA control the charging rate to ensure that I’m using solar to charge the car as much as possible instead of letting it suck down the powerwall battery. My electric bill is not Time Of Use (TOU), so I can charge the car anytime, but I’d like to charge it with solar as often as possible. Even though I’m on NEM2.0, my sell rate to the elec co is low.

At any rate, I want to first check to see if the car is plugged in. If it is, measure the solar production against the current demand. If the current demand is low and production is high, then I’d like to activate the charger and charge the car with the sun, but I don’t want it to activate at 48A, I’d like it to do whatever it takes to break even (usually 5-20A, depending on the time of day).

I’ve exposed the sensors in HA to turn the charger on, to control the rate of charge, and to set the charge limit. I also have HA measuring solar demand, solar production, powerwall battery status (charging/not charging), charge level, and charge rate.

I’m pretty sure I’m going to need to write a function to measure (is solar production greater than home demand), but have no idea how to do this without concrete numbers. I also have no idea how I’m going to specify the exact kwh draw each amp is without hard coding it.

Does anyone have any ideas and/or has done this in the past?

Home assistant can do it on it’s own without node red required. See this thread for a lot more information: Optimizing use of unused Solar Power to charge a Tesla

There are many ways to go about it depending on your preferences. My Tesla is set to start charging when the sun comes up, and when HA sees it charging it adjusts the charge current to match solar excess (I can set a target export level, and to what degree it should let my myenergi eddi consume energy first, and a minimum charge current).

Thanks, this is awesome - would you mind sharing your automation, too?