Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shelly button in Smarthome / Einschaltgruppe #2236

Merged
merged 5 commits into from Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions runs/initRamdisk.sh
Expand Up @@ -208,6 +208,15 @@ initRamdisk(){
echo 0 > $RamdiskPath/device7_wh
echo 0 > $RamdiskPath/device8_wh
echo 0 > $RamdiskPath/device9_wh
echo 0 > $RamdiskPath/smarthome_device_minhaus_1
echo 0 > $RamdiskPath/smarthome_device_minhaus_2
echo 0 > $RamdiskPath/smarthome_device_minhaus_3
echo 0 > $RamdiskPath/smarthome_device_minhaus_4
echo 0 > $RamdiskPath/smarthome_device_minhaus_5
echo 0 > $RamdiskPath/smarthome_device_minhaus_6
echo 0 > $RamdiskPath/smarthome_device_minhaus_7
echo 0 > $RamdiskPath/smarthome_device_minhaus_8
echo 0 > $RamdiskPath/smarthome_device_minhaus_9
echo 0 > $RamdiskPath/smarthome_device_manual_1
echo 0 > $RamdiskPath/smarthome_device_manual_2
echo 0 > $RamdiskPath/smarthome_device_manual_3
Expand Down
29 changes: 23 additions & 6 deletions runs/mqttsub.py
Expand Up @@ -142,6 +142,23 @@ def on_message(client, userdata, msg):
if ( 1 <= int(devicenumb) <= numberOfSupportedDevices and len(str(msg.payload.decode("utf-8"))) > 6 and bool(re.match(ipallowed, msg.payload.decode("utf-8")))):
writetoconfig(shconfigfile,'smarthomedevices','device_ip_'+str(devicenumb), msg.payload.decode("utf-8"))
client.publish("openWB/config/get/SmartHome/Devices/"+str(devicenumb)+"/device_ip", msg.payload.decode("utf-8"), qos=0, retain=True)
if (( "openWB/config/set/SmartHome/Device" in msg.topic) and ("device_pbip" in msg.topic)):
devicenumb=re.sub(r'\D', '', msg.topic)
if ( 1 <= int(devicenumb) <= numberOfSupportedDevices and len(str(msg.payload.decode("utf-8"))) > 6 and bool(re.match(ipallowed, msg.payload.decode("utf-8")))):
writetoconfig(shconfigfile,'smarthomedevices','device_pbip_'+str(devicenumb), msg.payload.decode("utf-8"))
client.publish("openWB/config/get/SmartHome/Devices/"+str(devicenumb)+"/device_pbip", msg.payload.decode("utf-8"), qos=0, retain=True)
if (( "openWB/config/set/SmartHome/Device" in msg.topic) and ("device_pbtype" in msg.topic)):
devicenumb=re.sub(r'\D', '', msg.topic)
validDeviceTypespb = ['none','shellypb']
if ( 1 <= int(devicenumb) <= numberOfSupportedDevices and len(str(msg.payload.decode("utf-8"))) > 2):
try:
# just check vor payload in list, deviceTypeIndex is not used
deviceTypeIndex = validDeviceTypespb.index(msg.payload.decode("utf-8"))
except ValueError:
pass
else:
writetoconfig(shconfigfile,'smarthomedevices','device_pbtype_'+str(devicenumb), msg.payload.decode("utf-8"))
client.publish("openWB/config/get/SmartHome/Devices/"+str(devicenumb)+"/device_pbtype", msg.payload.decode("utf-8"), qos=0, retain=True)
if (( "openWB/config/set/SmartHome/Device" in msg.topic) and ("device_measureip" in msg.topic)):
devicenumb=re.sub(r'\D', '', msg.topic)
if ( 1 <= int(devicenumb) <= numberOfSupportedDevices and len(str(msg.payload.decode("utf-8"))) > 6 and bool(re.match(ipallowed, msg.payload.decode("utf-8")))):
Expand Down Expand Up @@ -185,13 +202,13 @@ def on_message(client, userdata, msg):
if ( 1 <= int(devicenumb) <= numberOfSupportedDevices and -100000 <= int(msg.payload) <= 100000):
writetoconfig(shconfigfile,'smarthomedevices','device_einschaltschwelle_'+str(devicenumb), msg.payload.decode("utf-8"))
client.publish("openWB/config/get/SmartHome/Devices/"+str(devicenumb)+"/device_einschaltschwelle", msg.payload.decode("utf-8"), qos=0, retain=True)

if (( "openWB/config/set/SmartHome/Device" in msg.topic) and ("device_deactivateper" in msg.topic)):
devicenumb=re.sub(r'\D', '', msg.topic)
if ( 1 <= int(devicenumb) <= numberOfSupportedDevices and 0 <= int(msg.payload) <= 100):
writetoconfig(shconfigfile,'smarthomedevices','device_deactivateper_'+str(devicenumb), msg.payload.decode("utf-8"))
client.publish("openWB/config/get/SmartHome/Devices/"+str(devicenumb)+"/device_deactivateper", msg.payload.decode("utf-8"), qos=0, retain=True)

if (( "openWB/config/set/SmartHome/Device" in msg.topic) and ("device_deactivateWhileEvCharging" in msg.topic)):
devicenumb=re.sub(r'\D', '', msg.topic)
if ( 1 <= int(devicenumb) <= numberOfSupportedDevices and 0 <= int(msg.payload) <= 2):
Expand Down Expand Up @@ -421,16 +438,16 @@ def on_message(client, userdata, msg):
client.publish("openWB/config/get/SmartHome/Devices/"+str(devicenumb)+"/device_nonewatt", msg.payload.decode("utf-8"), qos=0, retain=True)
else:
print( "invalid payload for topic '" + msg.topic + "': " + msg.payload.decode("utf-8"))

if (( "openWB/config/set/SmartHome/Device" in msg.topic) and ("device_idmnav" in msg.topic)):
devicenumb=re.sub(r'\D', '', msg.topic)
if ( 1 <= int(devicenumb) <= numberOfSupportedDevices and 1 <= int(msg.payload) <= 2 ):
writetoconfig(shconfigfile,'smarthomedevices','device_idmnav_'+str(devicenumb), msg.payload.decode("utf-8"))
client.publish("openWB/config/get/SmartHome/Devices/"+str(devicenumb)+"/device_idmnav", msg.payload.decode("utf-8"), qos=0, retain=True)
else:
print( "invalid payload for topic '" + msg.topic + "': " + msg.payload.decode("utf-8"))
print( "invalid payload for topic '" + msg.topic + "': " + msg.payload.decode("utf-8"))


if (( "openWB/config/set/SmartHome/Device" in msg.topic) and ("device_standbyDuration" in msg.topic)):
devicenumb=re.sub(r'\D', '', msg.topic)
if ( 1 <= int(devicenumb) <= numberOfSupportedDevices and 0 <= int(msg.payload) <= 86400 ):
Expand Down
17 changes: 17 additions & 0 deletions runs/smarthomemq.py
Expand Up @@ -186,6 +186,7 @@ def getdevicevalues():
# dyn daten einschaltgruppe
Sbase.ausschaltwatt = 0
Sbase.einrelais = 0
Sbase.eindevstatus = 0
mqtt_all = {}
for mydevice in mydevices:
mydevice.getwatt(uberschuss, uberschussoffset)
Expand Down Expand Up @@ -429,6 +430,8 @@ def resetmaxeinschaltdauerfunc():
readmq()
while True:
# update_devices()
mqtt_man = {}
sendmess = 0
loadregelvars()
resetmaxeinschaltdauerfunc()
getdevicevalues()
Expand All @@ -449,4 +452,18 @@ def resetmaxeinschaltdauerfunc():
logDebug(LOGLEVELDEBUG, "(" + str(i) + ") " +
mydevice.device_name +
" manueller Modus aktiviert, keine Regelung")
for i in range(1, (numberOfSupportedDevices+1)):
pref = 'openWB/config/set/SmartHome/Devices/' + str(i) + '/'
for mydevice in mydevices:
if (str(i) == str(mydevice.device_nummer)):
mydevice.updatebutton()
if (mydevice.btchange == 1):
sendmess = 1
mqtt_man[pref + 'mode'] = mydevice.newdevice_manual
if (mydevice.btchange == 2):
sendmess = 1
workman = mydevice.newdevice_manual_control
mqtt_man[pref + 'device_manual_control'] = workman
if (sendmess == 1):
sendmq(mqtt_man)
time.sleep(5)