Mystrom Python3 Request Get Power Usage

tested with: python3, mystrom switch
required: requests: pip3 install requests

code:

import requests

def getMystromPower(ip):
    url = 'http://%s/report' %ip
    try:
        r = requests.get(url)
        data = json.loads(r.text)
        return data['power']
    except requests.exceptions.RequestException as e:
        print("getMystromPower connection exception: %s"%e)
        return 9999
    except Exception as e:
        print("getMystromPower generic exception: %s"%e)
        return 9999

power = getMystromPower('10.0.2.214')
print(power)

example output:

86

infos:

  • replace 10.0.2.214 with your own ip of the mystrom switch
  • output will be the current power usage in watt.
  • if something goes wrong, output will be 9999

what is a mystrom switch:
its a small power outlet switch from mystrom.com that can be used to switch mains (up to 2000 Watt) in the EU and in Switzerland. It has a cool and ultra easy to use REST API

myStrom device