Created
December 30, 2017 19:35
-
-
Save Breakerz/8e6a1011db3d67f40160eafc86581b1e to your computer and use it in GitHub Desktop.
Thermostat Honeywell Total Connect Comfort MQTT Wrapper to use with Home Assistant
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
import paho.mqtt.client as mqtt | |
import subprocess | |
import json | |
gmode = "0" | |
# The callback for when the client receives a CONNACK response from the server. | |
def on_connect(client, userdata, flag, rc): | |
print("Connected with result code %s" % (str(rc))) | |
# Subscribing in on_connect() means that if we lose the connection and | |
# reconnect then subscriptions will be renewed. | |
client.subscribe("hvac/central/#") | |
# The callback for when a PUBLISH message is received from the server. | |
def on_message(client, userdata, msg): | |
print("Topic: ", msg.topic+'\nMessage: '+str(msg.payload)) | |
{ | |
"hvac/central/temperature/set": set_temperature, | |
"hvac/central/mode/set": set_mode, | |
"hvac/central/fan/set": set_fan, | |
"hvac/central/status": get_status, | |
}.get(str(msg.topic), wrong_topic)(client, msg) | |
def wrong_topic(client, msg): | |
print(str(msg.topic)) | |
def set_temperature(client, msg): | |
print("set_temperature") | |
client.publish("hvac/central/temperature/state", str(msg.payload)) | |
cmd = "python /home/homeassistant/.homeassistant/scripts/therm.py -h %s" % str(msg.payload) | |
if (gmode == "3"): #cool mode | |
cmd = "python /home/homeassistant/.homeassistant/scripts/therm.py -c %s" % str(msg.payload) | |
print(cmd) | |
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) | |
out, err = p.communicate() | |
result = out.split('\n') | |
for lin in result: | |
if not lin.startswith('#'): | |
print(lin) | |
def get_status(client, msg): | |
print("status") | |
cmd = "python /home/homeassistant/.homeassistant/scripts/therm.py -j" | |
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) | |
out, err = p.communicate() | |
result = out.split('\n') | |
for lin in result: | |
if not lin.startswith('#'): | |
print(lin) | |
j = json.loads(result[0]) | |
client.publish("hvac/central/temperature/current", j['latestData']['uiData']["DispTemperature"]) | |
client.publish("hvac/central/temperature/state", j['latestData']['uiData']["HeatSetpoint"]) | |
fan_state = ("auto") if (j['latestData']['fanData']["fanMode"] == "0") else "always_on" | |
client.publish("hvac/central/fan/state", fan_state) | |
global gmode | |
mode = "stop" | |
gmode = j['latestData']['uiData']["SystemSwitchPosition"] | |
if (gmode == 0): | |
mode = "emheat" | |
if (gmode == 1): | |
mode = "heat" | |
if (gmode == 2): | |
mode = "cool" | |
client.publish("hvac/central/mode/state", mode) | |
def set_mode(client, msg): | |
print("set_mode") | |
client.publish("hvac/central/mode/state", str(msg.payload)) | |
mode = "2" | |
if (str(msg.payload).startswith('emheat')): | |
mode = "0" | |
if (str(msg.payload).startswith('heat')): | |
mode = "1" | |
if (str(msg.payload).startswith('cool')): | |
mode = "3" | |
client.publish("hvac/central/mode/state", str(msg.payload)) | |
cmd = "python /home/homeassistant/.homeassistant/scripts/therm.py -m %s" % mode | |
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) | |
out, err = p.communicate() | |
result = out.split('\n') | |
for lin in result: | |
if not lin.startswith('#'): | |
print(lin) | |
def set_fan(client, msg): | |
print("set_fan") | |
client.publish("hvac/central/fan/state", str(msg.payload)) | |
cmd = "" | |
if str(msg.payload).startswith('auto'): | |
cmd = "python /home/homeassistant/.homeassistant/scripts/therm.py -f 0" | |
else: | |
cmd = "python /home/homeassistant/.homeassistant/scripts/therm.py -f 1" | |
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) | |
out, err = p.communicate() | |
result = out.split('\n') | |
for lin in result: | |
if not lin.startswith('#'): | |
print(lin) | |
client = mqtt.Client() | |
client.on_connect = on_connect | |
client.on_message = on_message | |
client.connect("192.168.1.111, 1883, 60) | |
# Blocking call that processes network traffic, dispatches callbacks and | |
# handles reconnecting. | |
# Other loop*() functions are available that give a threaded interface and a | |
# manual interface. | |
client.loop_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment