Copy over other files from christoph

This commit is contained in:
Sven Koehler
2024-01-16 22:10:54 +01:00
parent 65340158b3
commit 7b1fe5f7fd
12 changed files with 307 additions and 16 deletions

View File

@@ -0,0 +1,10 @@
[Unit]
Description=Sending the MachbarSchalter status into a Signal group
After=multi-user.target
[Service]
Type=simple
ExecStart=/usr/bin/python /usr/bin/schalter_listener
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,34 @@
import os
import paho.mqtt.client as mqtt
import logging
logging.basicConfig(level=logging.DEBUG)
# If you want to use a specific client id, use
# mqttc = mqtt.Client("client-id")
# but note that the client id must be unique on the broker. Leaving the client
# id parameter empty will generate a random id for you.
mqttc = mqtt.Client()
lastmessage = ""
def onConnect(client, userdata, flags, rc):
print("Connected with result code "+str(rc))
mqttc.subscribe("/sensors/spaceschalter/status", 0)
def messageReceived(client, userdata, message):
print("received topic" + str(message.topic) + "with payload:" + str(message.payload))
global lastmessage
if (str(message.payload) == lastmessage):
print("already got message " + lastmessage + ", skipping.")
return
lastmessage = str(message.payload)
print("sending Message via signal…")
os.system("signal-cli --config /home/christoph/.local/share/signal-cli/ -u +491639709611 send -m \"Machbar: %s\" -g 4itR+98YIW1Xc4BJwKKoew==" % message.payload.decode("utf-8"))
mqttc.username_pw_set("christoph","dNppWZ2nukh+RQ")
mqttc.on_message = messageReceived
mqttc.on_connect = onConnect
mqttc.connect("ccc-p.org", 1883, 60)
mqttc.loop_forever()