Wie liest man einen Mini PM Gen3 mit Python aus?

VPN/Proxy erkannt

Es scheint, dass Sie einen VPN- oder Proxy-Dienst verwenden. Bitte beachten Sie, dass die Nutzung eines solchen Dienstes die Funktionalität dieser Webseite einschränken kann.

  • Um einen 3EM mit Python auszulesen, kann man zum Beispiel

    requests.get(f"http://%7bself.host%7d/status/", headers={"Content-Type": "application/json"}, timeout=2).json()["total_power"])

    verwenden. Beim Mini PM Gen3 gibt es den "status" endpoint nicht (liefert 404). Auch meter, emeter, relay, settings werden nicht unterstuetzt. Welchen endpoint muss man verwenden?

  • 3EM ist ein Gen1

    Gen2/3 haben andere API

    https://shelly-api-docs.shelly.cloud/

    Shelly’s: 2x 1, 10x 1PM , 4x 2.5, 3x i3, 10x Plus 1PM, 22x Plug S, 11x UNI, 2x 1L mit PIR, 8x AddOn mit Temp/DHT22, 3x RGBW2, 2x Plus i4, 5x Plus 1, 4x Plus 2PM, 4x EM, 2x 3EM, 1x TRV, 3x Plus AddOn, 1x Pro 3EM, 2x BLU, 5xPlusPMmini, 1xPlus1PMmini, 4xPlusUNI

    Fritz!Box5690pro, 3x FRITZ!Repeater6000, 6x Fritz!Dect200

    HomeAssistant auf RaspberryPi5(8GB) mit NVMe, HomeAssistant auf Synology DS1019+, Backup HomeAssistant auf RaspberryPi4B(4GB)

    DHT21 (AM2301) oder (AM2320) für unter 0 Grad

  • 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