Skip to content

Latest commit

 

History

History
72 lines (42 loc) · 2.33 KB

getting_started.rst

File metadata and controls

72 lines (42 loc) · 2.33 KB

Getting Started

Install

PySMA is available on pypi and can be installed using pip.

pip install pysma

Create SMA instance

The ~pysma.SMA class requires a ClientSession object, an URL and a password. The default user group is "user", but can be changed by passing it as the fourth group parameter.

session = aiohttp.ClientSession(connector=aiohttp.TCPConnector(ssl=False))
url = "https://device-hostname"
password = "MyPassword!"

sma = pysma.SMA(session, url, password)

Create Sensors

To retrieve values from the device you need a ~pysma.sensor.Sensors object. The easiest way is to generate one using the ~pysma.SMA.get_sensors method. This will query the device to figure out the device class and returns a ~pysma.sensor.Sensors object containing specific ~pysma.sensor.Sensor objects for your device.

sma_sensors = sma.get_sensors()

Alternatively this can be manually created by initializing an empty ~pysma.sensor.Sensors object and adding new ~pysma.sensor.Sensor objects to it using the ~pysma.sensor.Sensors.add method. Predefined sensors can be found in pysma.definitions. See also definitions.py at Github.

sma_sensors = Sensors()
my_sensor = Sensor("6300_12345678_0", "dummy_sensor") # This key won't work!
sma_sensors.add(my_sensor)
sma_sensors.add(pysma.definitions.pv_power_a)

Read Sensor values

Now you have a ~pysma.sensor.Sensors object, you can pass this to ~pysma.SMA.read to read the values from the device. The retrieved values are stored in the respective ~pysma.sensor.Sensor.

sma.read(sma_sensors)

for sma_sensor in sma_sensors:
    print(f"{sma_sensor.name}: {sma_sensor.value}")

Complete Example

A full example can be found in the Github repository