Package: elnasmartmeter
Elna SmartMeter LibraryHi and welcome! Click the button below if you enjoy this library and want to support my work. A lot of coffee is consumed as a software developer you know 😁Needless to say, this is completely voluntary.IntroductionA simple library for theE.ON ElnaAPI written in Python 3. Elna is a smart power meter that is plugged in to the HAN (Home Area Network) port of the electricity meter using an RJ12 connector.This library is using the built-in API in the Elna device to gather information, about your powerconsumptionand/orproduction, directly from the device itself.Elna is based on hardware from Net2Grid so it's probably also compatible with more devices from the Net2Grid family. Any feedback is welcome.DemoHere is a small command-line demo application showing the information that can be obtained by the library.Check out the source code to the demo here:smartmeter-demo.py.InstallationSetup the virtual environment:virtualenv venv
source venv/bin/activateInstall the latest version withpip:pip install elnasmartmeterBasicsSetupIn order to use the library you need to know the IP address of the Elna device. You can find it in the DHCP server of your router (or wherever you are running your DHCP server). The MAC address of Elna is printed on the back of the device.fromelnaimportsmartmeter# Connect the library to the Elna devicemeter=smartmeter.Connect('192.168.0.10')# Get general informationinfo=meter.get_info()# Get power readingselectricity=meter.get_electricity()It's as simple as that to fetch the power consuption/production of your household. In a moment we will be looking at how to access the information via theinfoandelectricityobjects.ExceptionsAll of the methods callable from the library will throw exceptions on failure. A full list of exceptions can be foundhere.fromelnaimportsmartmeterfromelna.exceptionsimport*...try:info=meter.get_info()exceptNewConnectionErrorase:print(e)Printing Objects and PropertiesThe objects representing various entities in the library can be output with theprint()method for easy inspection of its properties.As an example, you can output the properties of anInformationobject by passing it to theprint()method:print(info)# Output: <class 'elna.classes.Information'>: {'id': '01ab:0200:00cd:03ef', 'manufacturer': 'NET2GRID', 'model': 'SBWF4602', 'firmware': '1.7.14', 'hardware': 1, 'batch': 'HMX-P0D-123456'}Also, the properties are easily accessed from the object:print(f"Model    :{info.model}")print(f"Firmware :{info.firmware}")The same goes for all object classes in the library:Information,Electricity,PowerandWLANInformation.Access the DataThere are two pieces of data that can be fetched with this library: general deviceInformationandPowerstatistics.Device InformationTo get the general device information we just call theget_info()method.info=meter.get_info()Access the values via the class properties:info.id# Returns the device ID        : '01ab:0200:00cd:03ef'  (for example).info.manufacturer# Returns the manufacturer     : 'NET2GRID'info.model# Returns the model            : 'SBWF4602'info.firmware# Returns the firmware version : '1.7.14'info.hardware# Returns the hardware version : 1info.batch# Returns the batch number     : 'HMX-P0D-123456'Power ReadingsTo get the power readings we call theget_electricity()method. These readings are a bit more complex since the information gathered from the Elna device is divided in to sub-classes, but it's not that complicated:electricity=meter.get_electricity()NowGet thecurrentpower consumption:electricity.now.key# Returns the string  : 'now'electricity.now.value# Returns the power   : 453  (for example).electricity.now.unit# Returns the unit    : 'W'  (as in Watt)electricity.now.timestamp# Returns a timestamp : '2022-12-24 13:37:00'MinimumGet theminimumpower consumption in the period:electricity.minimum.key# Returns the string  : 'minimum'electricity.minimum.value# Returns the power   : 202  (for example).electricity.minimum.unit# Returns the unit    : 'W'  (as in Watt)electricity.minimum.timestamp# Returns a timestamp : '2022-12-13 13:37:00'MaximumGet themaximumpower consumption in the period:electricity.maximum.key# Returns the string  : 'maximum'electricity.maximum.value# Returns the power   : 14320  (for example).electricity.maximum.unit# Returns the unit    : 'W'  (as in Watt)electricity.maximum.timestamp# Returns a timestamp : '2022-12-31 13:37:00'The time frame (period) of which theminimumandmaximumvalues has been recorded is unknown (to me).ImportedGet theimportedpower. This would be total power comingintothe household:electricity.imported.key# Returns the string  : 'imported'electricity.imported.value# Returns the power   : 12345678  (for example).electricity.imported.unit# Returns the unit    : 'Wh'  (as in Watt hours)electricity.imported.timestamp# Returns a timestamp : '2022-12-31 13:37:00'ExportedGet theexportedpower. This would be total power comingout ofthe household:electricity.exported.key# Returns the string  : 'exported'electricity.exported.value# Returns the power   : 87654321  (for example).electricity.exported.unit# Returns the unit    : 'Wh'  (as in Watt hours)electricity.exported.timestamp# Returns a timestamp : '2022-12-31 13:37:00'Check out the smartmeter demo at the top to try it out.WLAN InformationWe can also get the WLAN information of the device by calling theget_wlan_info()method. The device can act as both a Wireless Client (Station) and an Access Point (AP) depending on if it has been connected to you WiFi network or not.wlan=meter.get_wlan_info()Access the WLAN information via the class properties of the object:wlan.mode# Returns the current WLAN modewlan.ap_ssid# Returns the Access Point SSIDwlan.ap_key# Returns the Access Point Passwordwlan.client_ssid# Returns the SSID of the AP Elna is connected towlan.join_status# Returns the number of clients joined to the Elna APwlan.mac# Returns the MAC address currently in usewlan.ip# Returns the IP addresswlan.subnet# Returns the Subnet maskwlan.gateway# Returns the Default gatewaywlan.dns# Returns the Primary DNS serverwlan.dnsalt# Returns the Secondary DNS serverwlan.n2g_id# Returns the Net2Grid ID numberwlan.sta_mac# Returns the MAC address of the WLAN Stationwlan.ap_mac# Returns the MAC address of the Access Pointwlan.eth_mac# Returns the Ethernet MAC address (?)Note: The descriptions following the WLAN properties above are estimated guesses.Legal DisclaimerThe product names, trademarks and registered trademarks in this repository, are property of their respective owners, and are used by the author for identification purposes only. The use of these names, trademarks and brands, do not imply endorsement or affiliation.