-
-
Save natm/4981daba160738cb87f337fa35ea1aa7 to your computer and use it in GitHub Desktop.
An Evohome to MQTT bridge
This file contains 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
#! /usr/bin/env python3 | |
"""Uses the brilliant Evohome Client from Andrew Stock to query the status of | |
a Honeywell Evohome heat system and publishes the responses to an a MQTT broker. | |
Evohome Client available https://github.com/watchforstock/evohome-client | |
Run with your username and password | |
eventcmd = /home/pi/bin/evohomemqtt.py -u username -p password | |
""" | |
import argparse | |
import logging | |
import logging.handlers | |
from evohomeclient import EvohomeClient | |
import paho.mqtt.publish as mqtt | |
# Global Logger | |
_LOG = logging.getLogger('evohome') | |
_LOG = logging.getLogger() | |
_HANDLER = logging.StreamHandler() | |
_FORMATTER = logging.Formatter('%(asctime)s %(name)-12s %(levelname)-8s %(message)s') | |
_HANDLER.setFormatter(_FORMATTER) | |
_LOG.addHandler(_HANDLER) | |
def main(): | |
"""Main function, parse args and read alarm files, send resulting events to mqtt broker""" | |
parser = argparse.ArgumentParser(description="An Honeywell Evohome to MQTT inteface", | |
epilog="V0.1 by Dave Sargeant, Evohome Client by Andrew Stock") | |
parser.add_argument("-u", "--username", required=True, | |
help="Username/Email to log into mytotalconnectcomfort.") | |
parser.add_argument("-p", "--password", required=True, | |
help="Password for mytotalconnectcomfort.") | |
parser.add_argument("-v", "--verbose", action="store_true", | |
help="increase output verbosity") | |
parser.add_argument("-m", "--mqtt-broker", dest='mqtt_broker', default='localhost', | |
help="Relay events to mqtt server") | |
args = parser.parse_args() | |
syslog_handler = logging.handlers.SysLogHandler(address='/dev/log') | |
_LOG.addHandler(syslog_handler) | |
if args.verbose is True: | |
_LOG.setLevel(logging.DEBUG) | |
_LOG.info("Connecting to mytotalconnectcomfort as %s", args.username) | |
try: | |
client = EvohomeClient(args.username, args.password) | |
except Exception as error: # pylint: disable=broad-except | |
_LOG.error("Unable to connect to mytotalconnectcomfort %s", str(error)) | |
_LOG.info("client %s", str(client)) | |
msgs = [] | |
for device in client.temperatures(): | |
_LOG.info("device %s", str(device)) | |
# Remove spaces and lower case | |
topic = device['name'].replace(' ', '_').lower() | |
if device['thermostat'] == 'EMEA_ZONE': | |
topic = "whouse/evohome/temperature/{}".format(topic) | |
elif device['thermostat'] == 'DOMESTIC_HOT_WATER': | |
topic = "whouse/evohome/temperature/domestic_hot_water" | |
else: | |
_LOG.info("Unknown device: %s", str(device)) | |
continue | |
temp = float(device['temp']) | |
if temp > 50: | |
_LOG.error("For topic {} rejecting out of range temp {}".format(topic, temp)) | |
continue | |
payload = "{temp}".format(temp=device['temp']) | |
msg = {'topic':topic, 'payload':payload} | |
_LOG.debug("Adding (topic=%s) : %s to %s", topic, payload, args.mqtt_broker) | |
msgs.append(msg) | |
mqtt.multiple(msgs, hostname=args.mqtt_broker) | |
if len(msgs): | |
_LOG.debug("Sending %d messages to broker %s", len(msgs), args.mqtt_broker) | |
if __name__ == "__main__": | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment