Created
May 3, 2020 00:34
-
-
Save neilgupta/4b8be9a1cbb7af5af3caf56149322bc7 to your computer and use it in GitHub Desktop.
Hiome MQTT example
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
import paho.mqtt.client as mqtt | |
import json | |
def onConnect(client, userdata, flags, rc): | |
client.subscribe('hs/1/com.hiome/#/occupancy', qos=1) | |
def onMessage(client, userdata, payload): | |
topic = payload.topic.split('/') | |
room_id = topic[3] | |
msg = json.loads(payload.payload) | |
occupancy_count = msg['val'] | |
# do something when occupancy changes in this room | |
return | |
client = mqtt.Client() | |
client.on_connect = onConnect | |
client.on_message = onMessage | |
client.connect('hiome.local', 1883, 60) | |
client.loop_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment