My home is setup with Solar panels and connected to the grid. Unfortunately, Tesla has only got one variable for being able to start charging at a certain time which is a little light. I setup this piston to automagically charge my car using the home charger and prioritizing solar charging, then off-peak local electricity and as a last resort charging during more expensive times.
This piston utilizes the DarkSky https://github.com/project802/smartthings
Tesla Connect https://github.com/trentfoley/SmartThingsPublic/blob/master/devicetypes/trentfoley/tesla.src/tesla.groovy