From 1ed68f4d1a3abdd0a75fc8e4e337c5391f15ce3d Mon Sep 17 00:00:00 2001 From: Trammell Hudson Date: Sun, 6 Feb 2022 15:21:01 +0100 Subject: [PATCH] hc2mqtt: format remaining time, print a publish message --- hc2mqtt | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/hc2mqtt b/hc2mqtt index 6070d91..b1d52e6 100755 --- a/hc2mqtt +++ b/hc2mqtt @@ -70,13 +70,26 @@ def client_connect(device_name, device): value = msg.get(topic, None) if value is None: continue - state[topics[topic]] = value + + # Convert "On" to True, "Off" to False + if value == "On": + value = True + elif value == "Off": + value = False + + new_topic = topics[topic] + if new_topic == "remaining": + state["remainingseconds"] = value + value = "%d:%02d" % (value / 60 / 60, (value / 60) % 60) + + state[new_topic] = value update = True if not update: continue msg = json.dumps(state) + print("publish", mqtt_topic, msg) client.publish(mqtt_topic + "/state", msg) except Exception as e: