Getting Started¶
Create SMA instance¶
The 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 Sensors
object. The easiest way is to generate one using the get_sensors()
method. This will query the device to figure out the device class and returns a Sensors
object containing specific Sensor
objects for your device.
sma_sensors = sma.get_sensors()
Alternatively this can be manually created by initializing an empty Sensors
object and adding new Sensor
objects to it using the 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 Sensors
object, you can pass this to read()
to read the values from the device. The retrieved values are stored in the respective 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