onokje / node-red-contrib-tesla

Node red nodes to control Tesla vehicles and devices
MIT License
20 stars 11 forks source link

Powerwall 2 #4

Open frownbreaker opened 4 years ago

frownbreaker commented 4 years ago

I get the "Credential type 'tesla-config' is not registered" as well. I'm trying to list vehicles I'm in the UK and want to control 2 powerwalls

frownbreaker commented 3 years ago

Hi, I have a Car and 2 PW2s. I use this library to send surplus power to the Car and another library and Node-Red to divert surplus power to hot water - An immersion heater. For the PW2s I use https://pypi.org/project/tesla-powerwall/

I run a tiny web service (Flask below) on a $6 Orange Pi along with another home automation (all node-red) the data from the API is unpacked in Node-Red and used to turn on heaters and charge the car etc. Also, use Node-Red to generate a small dashboard. As you can see the Powerwall calls are local so can work even with no internet.

Much of the flux in the Tesla APIs have been Tesla separating things into the cloud and local but also the introduction of OAuth2 to the PW2s Dec 2020. I think the APIs are now stable (Vs Dec 2020 to March 2021) shout if you need any code can post to Gitlab.

image

#!flask/bin/python
from flask import Flask, jsonify
from tesla_powerwall import Powerwall
from tesla_powerwall import User

app = Flask(__name__)

@app.route('/pw2-api/get_pw_stat', methods=['GET'])
def get_pw_stats():

    powerwall = Powerwall("192.168.0.209")
    powerwall.login("secret", "elon.musk@tesla.com")
    meters = powerwall.get_meters()
    pw_stats = {
            'SoC'           : int(powerwall.get_charge()),
            'SolarActive'       : meters.solar.is_drawing_from(),
            'BatteryPoweringHouse'  : meters.battery.is_drawing_from(),
            'GridInUse'         : meters.site.is_drawing_from(),
            'SolarPowerFlowkW'  : meters.solar.get_power(),
            'BatteryPowerFlowkW'    : meters.battery.get_power(),
            'GridPowerFlowkW'   : meters.site.get_power(),
            'HousePowerUsekW'   : meters.load.get_power()
            }

    return jsonify({'pw_stats': pw_stats})

if __name__ == '__main__':
    app.run(host="0.0.0.0", port=5100, debug=True)