Skip to content

Commit

Permalink
Merge pull request #1565 from okaegi/smart200
Browse files Browse the repository at this point in the history
mqtt smarthome openWB 2.0
  • Loading branch information
LKuemmel committed Apr 18, 2024
2 parents 8cbb5f1 + d354fd3 commit 5f4c879
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 53 deletions.
24 changes: 5 additions & 19 deletions packages/modules/smarthome/mqtt/off.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
#!/usr/bin/python3
import sys
import os
import time
import paho.mqtt.client as mqtt
import logging

log = logging.getLogger(__name__)
numberOfSupportedDevices = 9 # limit number of smart home devices


def on_connect(client, userdata, flags, rc):
client.subscribe("openWB/LegacySmartHome/set/Devices/#", 2)
def on_connect(client, userdata, flags, rc) -> None:
client.subscribe("openWB/set/LegacySmartHome/Devices/#", 2)


def on_message(client, userdata, msg):
def on_message(client, userdata, msg) -> None:
global numberOfSupportedDevices


Expand All @@ -31,23 +27,13 @@ def on_message(client, userdata, msg):
elapsedTime = time.time() - startTime
if elapsedTime > waitTime:
break
client.publish("openWB/LegacySmartHome/set/Devices/"+str(devicenumber)+"/ReqRelay", "0", qos=0, retain=True)
client.publish("openWB/set/LegacySmartHome/Devices/"+str(devicenumber)+"/ReqRelay", "0", qos=0, retain=True)
client.loop(timeout=2.0)
client.publish("openWB/LegacySmartHome/set/Devices/"+str(devicenumber) +
client.publish("openWB/set/LegacySmartHome/Devices/"+str(devicenumber) +
"/Ueberschuss", payload=str(uberschuss), qos=0, retain=True)
client.loop(timeout=2.0)
client.disconnect()
named_tuple = time.localtime() # getstruct_time
time_string = time.strftime("%m/%d/%Y, %H:%M:%S mqtt off.py", named_tuple)
# standard
file_string = '/var/www/html/openWB/ramdisk/smarthome_device_' + str(devicenumber) + '_mqtt.log'
file_stringpv = '/var/www/html/openWB/ramdisk/smarthome_device_' + str(devicenumber) + '_pv'
if os.path.isfile(file_string):
f = open(file_string, 'a')
else:
f = open(file_string, 'w')
log.debug('%s devicenr %s ueberschuss %6d /ReqRelay = 0' % (time_string, devicenumber, uberschuss), file=f)
f.close()
pvmodus = 0
f = open(file_stringpv, 'w')
f.write(str(pvmodus))
Expand Down
23 changes: 5 additions & 18 deletions packages/modules/smarthome/mqtt/on.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
#!/usr/bin/python3
import sys
import os
import time
import paho.mqtt.client as mqtt
import logging

log = logging.getLogger(__name__)
numberOfSupportedDevices = 9 # limit number of smart home devices


def on_connect(client, userdata, flags, rc):
client.subscribe("openWB/LegacySmartHome/set/Devices/#", 2)
def on_connect(client, userdata, flags, rc) -> None:
client.subscribe("openWB/set/LegacySmartHome/Devices/#", 2)


def on_message(client, userdata, msg):
def on_message(client, userdata, msg) -> None:
global numberOfSupportedDevices


Expand All @@ -31,22 +27,13 @@ def on_message(client, userdata, msg):
elapsedTime = time.time() - startTime
if elapsedTime > waitTime:
break
client.publish("openWB/LegacySmartHome/set/Devices/"+str(devicenumber)+"/ReqRelay", "1", qos=0, retain=True)
client.publish("openWB/set/LegacySmartHome/Devices/"+str(devicenumber)+"/ReqRelay", "1", qos=0, retain=True)
client.loop(timeout=2.0)
client.publish("openWB/LegacySmartHome/set/Devices/"+str(devicenumber) +
client.publish("openWB/set/LegacySmartHome/Devices/"+str(devicenumber) +
"/Ueberschuss", payload=str(uberschuss), qos=0, retain=True)
client.loop(timeout=2.0)
client.disconnect()
named_tuple = time.localtime() # getstruct_time
time_string = time.strftime("%m/%d/%Y, %H:%M:%S mqtt on.py", named_tuple)
file_string = '/var/www/html/openWB/ramdisk/smarthome_device_' + str(devicenumber) + '_mqtt.log'
file_stringpv = '/var/www/html/openWB/ramdisk/smarthome_device_' + str(devicenumber) + '_pv'
if os.path.isfile(file_string):
f = open(file_string, 'a')
else:
f = open(file_string, 'w')
log.debug('%s devicenr %s ueberschuss %6d /ReqRelay = 1' % (time_string, devicenumber, uberschuss), file=f)
f.close()
f = open(file_stringpv, 'w')
f.write(str(1))
f.close()
23 changes: 7 additions & 16 deletions packages/modules/smarthome/mqtt/watt.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
#!/usr/bin/python3
import sys
import os
import time
import json
import paho.mqtt.client as mqtt
import re

import os
numberOfSupportedDevices = 9 # limit number of smart home devices


def on_connect(client, userdata, flags, rc):
def on_connect(client, userdata, flags, rc) -> None:
global devicenumber
client.subscribe("openWB/LegacySmartHome/set/Devices/"+devicenumber + "/#", 2)
client.subscribe("openWB/set/LegacySmartHome/Devices/"+devicenumber + "/#", 2)


def on_message(client, userdata, msg):
def on_message(client, userdata, msg) -> None:
global numberOfSupportedDevices
global aktpower
global powerc
if (("openWB/LegacySmartHome/set/Device" in msg.topic) and ("Aktpower" in msg.topic)):
if (("openWB/set/LegacySmartHome/Device" in msg.topic) and ("Aktpower" in msg.topic)):
devicenumb = re.sub(r'\D', '', msg.topic)
if (1 <= int(devicenumb) <= numberOfSupportedDevices):
aktpower = int(msg.payload)
if (("openWB/LegacySmartHome/set/Device" in msg.topic) and ("Powerc" in msg.topic)):
if (("openWB/set/LegacySmartHome/Device" in msg.topic) and ("Powerc" in msg.topic)):
devicenumb = re.sub(r'\D', '', msg.topic)
if (1 <= int(devicenumb) <= numberOfSupportedDevices):
powerc = int(msg.payload)
Expand All @@ -33,13 +32,6 @@ def on_message(client, userdata, msg):
devicenumber = str(sys.argv[1])
ipadr = str(sys.argv[2])
uberschuss = int(sys.argv[3])
file_string = '/var/www/html/openWB/ramdisk/smarthome_device_' + str(devicenumber) + '_mqtt.log'
if os.path.isfile(file_string):
fx = open(file_string, 'a')
else:
fx = open(file_string, 'w')
named_tuple = time.localtime() # getstruct_time
time_string = time.strftime("%m/%d/%Y, %H:%M:%S mqtt watt.py", named_tuple)
client = mqtt.Client("openWB-mqttsmarthomecust" + devicenumber)
client.on_connect = on_connect
client.on_message = on_message
Expand All @@ -51,7 +43,7 @@ def on_message(client, userdata, msg):
elapsedTime = time.time() - startTime
if elapsedTime > waitTime:
break
client.publish("openWB/LegacySmartHome/set/Devices/"+str(devicenumber) +
client.publish("openWB/set/LegacySmartHome/Devices/"+str(devicenumber) +
"/Ueberschuss", payload=str(uberschuss), qos=0, retain=True)
client.loop(timeout=2.0)
client.disconnect()
Expand All @@ -66,4 +58,3 @@ def on_message(client, userdata, msg):
f1 = open('/var/www/html/openWB/ramdisk/smarthome_device_ret' + str(devicenumber), 'w')
json.dump(answer, f1)
f1.close()
fx.close()

0 comments on commit 5f4c879

Please sign in to comment.