-
-
Save ersingencturk/03cefaf7736c73be1c6b72ddb0136a9d 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"] == 1: | |
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": 1})) | |
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