Ejemplo n.º 1
0
def main(argv):
    newmode = ''
    try:
        opts, args = getopt.getopt(argv, "hm:", ["mode="])
    except getopt.GetoptError:
        print_helptext()
        sys.exit(2)

    for opt, arg in opts:
        if opt == "-h":
            print_helptext()
            sys.exit(0)
        elif opt in ("-m", "--mode"):
            newmode = arg

    config = ConfigParser()
    configpath = get_script_path() + '/../etc/secrets.cfg'
    config.read(configpath)
    
    try:
        client = TeslaApiClient(config["api"]["email"], config["api"]["password"])

        energy_sites = client.list_energy_sites()
        assert(len(energy_sites)==1)
        if newmode == 'backup':
            energy_sites[0].set_operating_mode_backup()
            energy_sites[0].set_backup_reserve_percent(100)
        elif newmode == 'self_consumption':
            energy_sites[0].set_operating_mode_self_consumption()
            energy_sites[0].set_backup_reserve_percent(0)
        elif newmode == 'autonomous':
            energy_sites[0].set_operating_mode_autonomous()
            energy_sites[0].set_backup_reserve_percent(0)
        else:
            print("Invalid mode selected")
            sys.exit(2)
        sys.exit(0)
    except AuthenticationError as e:
        print("AuthenticationError: " + e)
        sys.exit(1)
Ejemplo n.º 2
0
from tesla_api import TeslaApiClient

client = TeslaApiClient('MY-USERNAME', 'MY-PASSWORD')

energy_sites = client.list_energy_sites()
print("Number of energy sites = %d" % (len(energy_sites)))
assert (len(energy_sites) == 1)
print energy_sites[0]

energy_sites[0].set_operating_mode('autonomous')

import json

start = '1800'
finish = '16200'

settings = '{Content-Type: application/json}\n'
settings = '{"tou_settings":{"optimization_strategy": "economics", "schedule":['
settings = settings + '{"end_seconds": ' + finish + ', "week_days": [6, 0], "target": "off_peak", "start_seconds": ' + start + '},'
settings = settings + '{"end_seconds": ' + start + ', "week_days": [6, 0], "target": "peak", "start_seconds": ' + finish + '},'
settings = settings + '{"end_seconds": ' + finish + ', "week_days": [1, 2, 3, 4, 5], "target": "off_peak", "start_seconds": ' + start + '},'
settings = settings + '{"end_seconds": ' + start + ', "week_days": [1, 2, 3, 4, 5], "target": "peak", "start_seconds": ' + finish + '}]}}'

jsonsettings = json.loads(settings)

energy_sites[0].set_tou_settings(jsonsettings)