forked from Chaospott/Heizberry
Thermostat im Bällebad funktioniert.
This commit is contained in:
parent
a374a7c106
commit
a43b1726df
45
heizberry.py
45
heizberry.py
@ -10,15 +10,18 @@ import schedule
|
|||||||
import paho.mqtt.client as mqtt
|
import paho.mqtt.client as mqtt
|
||||||
from eq3bt import Thermostat
|
from eq3bt import Thermostat
|
||||||
|
|
||||||
|
thermostatBallpit = Thermostat('00:1A:22:0D:BE:EE')
|
||||||
thermostatBallpit = Thermostat('00:1A:22:0D:BE:EE')
|
thermostatBallpit = Thermostat('00:1A:22:0D:BE:EE')
|
||||||
|
|
||||||
global temperature_off = 12
|
temperature_off = 12
|
||||||
global temperature_on = 19
|
temperature_on = 19
|
||||||
|
|
||||||
|
|
||||||
def on_connect(client, userdata, flags, rc):
|
def on_connect(client, userdata, flags, rc):
|
||||||
log.debug("Connected with result code " + str(rc))
|
log.debug("Connected with result code " + str(rc))
|
||||||
|
|
||||||
|
client.subscribe("foobar/oben/baellebad/heizung/action")
|
||||||
|
|
||||||
sendReadings()
|
sendReadings()
|
||||||
|
|
||||||
|
|
||||||
@ -30,14 +33,14 @@ def on_message(client, userdata, message):
|
|||||||
msg = message.payload.decode("utf-8")
|
msg = message.payload.decode("utf-8")
|
||||||
log.debug('received message: %s from %s', format(msg), format(message.topic))
|
log.debug('received message: %s from %s', format(msg), format(message.topic))
|
||||||
|
|
||||||
if (message.topic == "foobar/oben/baellebad/heizung/action")
|
if (message.topic == "foobar/oben/baellebad/heizung/action"):
|
||||||
if (msg == "on"):
|
if (msg == "on"):
|
||||||
thermostatBallpit.target_temperature=temperature_on
|
thermostatBallpit.target_temperature=temperature_on
|
||||||
else
|
else:
|
||||||
if (msg == "on"):
|
if (msg == "off"):
|
||||||
thermostatBallpit.target_temperature=temperature_on
|
thermostatBallpit.target_temperature=temperature_off
|
||||||
else
|
else:
|
||||||
thermostatBallpit.target_temperature=msg
|
thermostatBallpit.target_temperature=int(msg)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -50,13 +53,15 @@ def sendReadings():
|
|||||||
|
|
||||||
# Send target temperatures
|
# Send target temperatures
|
||||||
temp=thermostatBallpit.target_temperature
|
temp=thermostatBallpit.target_temperature
|
||||||
if(temp == temperature_on)
|
if(temp == temperature_on):
|
||||||
temp = temp + " on"
|
temp = str(temp) + " on"
|
||||||
|
|
||||||
if(temp == temperature_off)
|
if(temp == temperature_off):
|
||||||
temp = temp + " off"
|
temp = str(temp) + " off"
|
||||||
|
|
||||||
client.publish("foobar/oben/baellebad/status", temp, qos=1, retain=True)
|
client.publish("foobar/oben/baellebad/heizung/status", temp, qos=1, retain=True)
|
||||||
|
|
||||||
|
log.debug('sent readings')
|
||||||
|
|
||||||
|
|
||||||
def terminate(signum, frame):
|
def terminate(signum, frame):
|
||||||
@ -88,12 +93,24 @@ if __name__ == '__main__':
|
|||||||
else:
|
else:
|
||||||
log.setLevel(logging.WARN)
|
log.setLevel(logging.WARN)
|
||||||
|
|
||||||
|
log.debug('start mqtt client')
|
||||||
client = mqtt.Client("Heizberry_oben")
|
client = mqtt.Client("Heizberry_oben")
|
||||||
client.on_connect = on_connect
|
client.on_connect = on_connect
|
||||||
client.on_message = on_message
|
client.on_message = on_message
|
||||||
client.connect("10.42.0.244", 1883, 60)
|
client.connect("10.42.0.244", 1883, 60)
|
||||||
|
log.debug('connected mqtt client')
|
||||||
|
|
||||||
client.loop_start()
|
client.loop_start()
|
||||||
|
|
||||||
log.debug('schedule periodic readings')
|
log.debug('schedule periodic readings')
|
||||||
schedule.every(1).minutes.do(sendReadings)
|
schedule.every(60).seconds.do(sendReadings)
|
||||||
|
|
||||||
|
time.sleep(10)
|
||||||
|
|
||||||
|
while True:
|
||||||
|
schedule.run_pending()
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
|
||||||
|
# sendReadings()
|
||||||
|
# time.sleep(60)
|
||||||
|
Loading…
Reference in New Issue
Block a user