tlyakhov / python-decora_wifi

Python Library for Interacting with Leviton Decora Smart WiFi Switches & Dimmers
MIT License
37 stars 21 forks source link

Support Breaker Panels and Energy #17

Open adamurban opened 3 years ago

adamurban commented 3 years ago

Looks like the current API models included do support some breaker panel functionality already.

Eg, if I do something like this:

for residence in all_residences:
    for panel in residence.get_residential_breaker_panels():
        print("Panel: {}".format(panel))
        for breaker in panel.get_residential_breakers():
            print("Breaker: {}".format(breaker))
            print("Energy: " + str(breaker.energyConsumption))
            print(breaker.rmsVoltage)
            print(breaker.name)
            print(breaker.operationalState)
            attribs = {}
            #attribs['remoteTrip'] = True
            attribs['blinkLED'] = True
            breaker.update_attributes(attribs)
            print(breaker.operationalState)

I can successfully read live energy stats from my breakers, toggle the LEDs, and remotely trip them.

There do appear to be many more energy API endpoints that are not currently in the model however, for example:

residentialBreakerEnergy findByIdResidentialBreakerEnergy destroyByIdResidentialBreakerEnergy updateByIdResidentialBreakerEnergy getResidentialBreakerEnergy createResidentialBreakerEnergy deleteResidentialBreakerEnergy countResidentialBreakerEnergy createManyResidentialBreakerEnergy

Both the breaker and the residence objects have some energy metrics now too: energyConsumptionForDay energyConsumptionForWeek energyConsumptionForMonth energyConsumptionForYear

My hope is to be able to add support for Leviton smart breaker panels (including energy metrics) to Home Assistant so I can use them with the new energy feature as well as generally be able to view/control them.

Here's some example output from my panel/breaker using the current get_residential_breaker_panels and get_residential_breakers calls:

Panel: {
    'id': 'LDATA-ABCDE-12345-FGHIJ',
    'averageCurrentCount': 10,
    'breakerCount': 5,
    'commissioned': True,
    'dauReplaced': False,
    'dauReplacementData': {},
    'diagnosticData': {},
    'discoverBreakers': False,
    'discoverBreakersMode': 'start',
    'discoverBreakersStatus': '{}',
    'discoverBreakersTimeout': 20,
    'driverData': '',
    'errorCode': '',
    'factoryReset': False,
    'factoryResetBreaker': False,
    'factoryResetLSBMA': False,
    'installerCompany': '',
    'installerEmail': '',
    'installerPhoneNumber': '',
    'manufacturer': 'Leviton',
    'model': 'DAU',
    'name': 'Garage Subpanel',
    'orientation': 0,
    'overVoltage': False,
    'packageVer': '0.1.85',
    'panelSize': 30,
    'pollBreakers': False,
    'requestVersionHour': 0,
    'resetEnergyConsumption': False,
    'residenceId':,
    'rmsVoltage': 122,
    'rmsVoltage2': 121,
    'status': 'READY',
    'underVoltage': False,
    'updateAvailability': 'UP_TO_DATE',
    'updateStatus': '',
    'updateVersion': '0.1.85',
    'versionBCM': '0.0.10',
    'versionBCMRadio': '',
    'versionBSM': '0.1.47',
    'versionBSMRadio': 'FWB7553000122',
    'versionNCM': '0.2.260',
    'created': '2020-12-09T02:18:11.000Z',
    'online': '2021-08-14T03:55:03.000Z',
    'offline': None,
    'lastUpdated': '2021-08-14T03:55:03.000Z',
    'wifiMode': 'Client',
    'wifiRSSI': -64,
    'wifiSSID': 'My WiFi SSID',
    'customNotifications': [{
        'name': 'offFor',
        'title': 'OFF for more than',
        'comparisonType': '<',
        'thresholdValue': 0.5,
        'thresholdProperty': 'rmsCurrent',
        'thresholdDuration': 60,
        'beginTime': '2021-08-14T03:20:39.276Z',
        'notifiedTime': '2021-08-05T11:29:01.829Z',
        'alarmStatus': 'PENDING',
        'autoReset': True,
        'notificationLimit': 3,
        'notificationsSent': 150,
        'position': 10,
        'breakerId': '',
        'triggerType': 'HIGH_DRAW_FOR_DURATION_WHILE_ON',
        'thresholdDurationTranslation': '1 hour',
        'header': 'Notify me when there is NO current draw',
        'subHeader': 'below a typical standby value of',
        'subTitle': 'for more than',
        'enabled': True
    }, {
        'name': 'offFor',
        'comparisonType': '<',
        'thresholdValue': 0.5,
        'thresholdProperty': 'rmsCurrent',
        'thresholdDuration': 60,
        'alarmStatus': 'NORMAL',
        'autoReset': True,
        'notificationLimit': 3,
        'notificationsSent': 0,
        'breakerId': '',
        'triggerType': 'HIGH_DRAW_FOR_DURATION_WHILE_OFF',
        'thresholdDurationTranslation': '1 hour'
    }]
}
Breaker: {
    'id': '',
    'lastUpdated': '2021-08-14T03:55:23.000Z',
    'online': None,
    'offline': None,
    'bleRSSI': 15,
    'blinkLED': False,
    'branchType': 'None',
    'created': '2020-12-09T02:24:32.000Z',
    'currentRating': 50,
    'currentState': 'ManualON',
    'currentStatePrev': 'SoftwareTrip',
    'currentState2': 'UNDEFINED',
    'currentStatePrev2': 'UNDEFINED',
    'diagnostics': 0,
    'driverData': '',
    'energyConsumption': 15.6,
    'energyConsumption2': 15.7,
    'firmwareVersionBLE': 'FWB6180000105',
    'firmwareVersionMeter': 'FWB7108000100',
    'firmwareVersionSiLabs': '',
    'hwVersion': 'MTR-010',
    'lineFrequency': 60,
    'lineFrequency2': 60,
    'lsbmaId': '',
    'lsbmaId2': '',
    'manufacturer': 'LEVITON',
    'mfgDate': '030520',
    'mfgPlantCode': '08',
    'mfgProductionLine': 'L1',
    'mfgTesterVersion': 'T01',
    'meterChipOk': True,
    'model': 'LB250-0S',
    'name': 'NEMA 14-50',
    'operationalState': 'Off',
    'operationalState2': None,
    'overCurrent': False,
    'overCurrentThreshold': 0.9,
    'overCurrentThreshold2': 0.9,
    'overVoltage': False,
    'overVoltageThreshold': 132,
    'overVoltageThreshold2': 132,
    'pcbNumber': 'B6770-0A',
    'poles': 2,
    'position': 14,
    'power': 0,
    'power2': 0,
    'powerFactor': 0,
    'powerFactor2': 0,
    'powerQuality': 0,
    'powerQuality2': 0,
    'reactivePower': 0,
    'reactivePower2': 0,
    'remoteTrip': False,
    'residentialBreakerPanelId': 'LDATA-ABCDE-12345-FGHIJ',
    'residentialBreakerFirmwareId': None,
    'rmsCurrent': 0,
    'rmsCurrent2': 0,
    'rmsVoltage': 122,
    'rmsVoltage2': 123,
    'serialNumber': 'ABC123',
    'series': '',
    'status': None,
    'thresholdCount': 3,
    'underVoltage': False,
    'underVoltageCount': 0,
    'underVoltageThreshold': 102,
    'underVoltageThreshold2': 102,
    'updateAvailability': 'UP_TO_DATE',
    'updateStatus': '',
    'updateVersion': ''
}