Created
February 8, 2019 18:11
-
-
Save osaether/875fcfd3e96358e3623248da5595d233 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from time import sleep | |
import ssl | |
import json | |
import os | |
from paho.mqtt.client import Client | |
username = "your VRM email" | |
password = "your VRM pasword" | |
portal_id = "your VRM portal ID" | |
def on_message(client, userdata, message): | |
val = json.loads(message.payload) | |
print message.topic, " = ", val["value"] | |
val = json.loads(message.payload) | |
if val["value"] == 0: | |
client.loop_stop() | |
client.disconnect() | |
os._exit(0) | |
def on_connect(client, userdata, rc, *args): | |
client.subscribe("N/%s/system/0/Relay/0/State" % portal_id) | |
client.publish("W/%s/system/0/Relay/0/State" % portal_id, json.dumps({"value": 0})) | |
client = Client("P1") | |
client.tls_set(cert_reqs=ssl.CERT_NONE) | |
client.tls_insecure_set(True) | |
client.username_pw_set(username, password=password) | |
client.connect("mqtt.victronenergy.com", port=8883) | |
client.on_connect = on_connect | |
client.on_message = on_message | |
client.loop_start() | |
while True: | |
sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment