Danke, ich habe die Doku gelesen und den folgenden Python code fuer 3EM und fuer Mini PM Gen3 entwickelt. Funktioniert gut.
class Shelly3EM:
""" Interface to a shelly 3em power meter. """
# pylint: disable=too-few-public-methods
def __init__(self, host):
self.host = socket.gethostbyname(host) # cache the host IP
def get(self):
"""
Return the current power as an int [W].
Return None if the shelly could not be read.
"""
try:
return round(requests.get(f"http://%7bself.host%7d/status/",
headers={"Content-Type":
"application/json"},
timeout=2).json()["total_power"])
except (requests.exceptions.RequestException, KeyError) as details:
logging.error("%s on host %s.", details, self.host)
return None
class ShellyPMMiniGen3:
""" Interface to a shelly PM Mini Gen3 power meter. """
# pylint: disable=too-few-public-methods
def __init__(self, host):
self.host = socket.gethostbyname(host) # cache the host IP
def get(self):
"""
Return the current power as an int [W].
Return None if the shelly could not be read.
"""
try:
p = requests.get(f"http://%7bself.host%7d/rpc/PM1.GetStatus?id=0",
headers={"Content-Type": "application/json"},
timeout=2).json()["apower"]
return round(p)
except (requests.exceptions.RequestException, KeyError) as details:
logging.error("%s on host %s.", details, self.host)
return None