add changeHomematicIP.py to check if a mqtt message is send
This commit is contained in:
parent
ea95ca8e4f
commit
51859d05ef
65
changeHomematicIP.py
Normal file
65
changeHomematicIP.py
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
# Homematic IP
|
||||||
|
import homematicip
|
||||||
|
from homematicip.home import Home
|
||||||
|
from homematicip.device import ShutterContact, WallMountedThermostatPro
|
||||||
|
# Import MQTT client.
|
||||||
|
import paho.mqtt.client as paho
|
||||||
|
|
||||||
|
# MQTT credentials
|
||||||
|
# mqtt_username = 'homeassistant' # MQTT client username
|
||||||
|
# mqtt_password = '3355' # MQTT client password
|
||||||
|
client_id = 'homematicip-pi' # unique client_id
|
||||||
|
mqtt_broker = "raspberrypi" # broker address, usually your HASS IP address
|
||||||
|
|
||||||
|
# create the MQTT client
|
||||||
|
client = paho.Client(client_id, protocol=paho.MQTTv31) # * set a random string (max 23 chars)
|
||||||
|
|
||||||
|
# client connection
|
||||||
|
# client.username_pw_set(mqtt_username, mqtt_password) # MQTT server credentials
|
||||||
|
client.connect(mqtt_broker, 1883, 60) # MQTT server address
|
||||||
|
|
||||||
|
# Homematic IP
|
||||||
|
config = homematicip.find_and_load_config_file()
|
||||||
|
|
||||||
|
home = Home()
|
||||||
|
home.set_auth_token(config.auth_token)
|
||||||
|
home.init(config.access_point)
|
||||||
|
|
||||||
|
topic = 'weathersensors/'
|
||||||
|
room = 'Leonie'
|
||||||
|
client.subscribe(topic + room + "/setHeatingProfile")
|
||||||
|
|
||||||
|
|
||||||
|
def on_message(client, userdata, msg): # The callback for when a PUBLISH message is received from the server.
|
||||||
|
global home
|
||||||
|
home.get_current_state()
|
||||||
|
for group in home.groups:
|
||||||
|
if group.label == room:
|
||||||
|
if group.groupType == "HEATING":
|
||||||
|
for profile in group.profiles:
|
||||||
|
if profile.name != "":
|
||||||
|
client.publish(topic + room + "/activeProfile", group.activeProfile.name)
|
||||||
|
client.publish(topic + room + "/heatingProfiles/" + profile.index, profile.name)
|
||||||
|
print(profile.index + ": " + profile.name)
|
||||||
|
print(profile.name)
|
||||||
|
print(msg.payload.decode("utf-8"))
|
||||||
|
if profile.name == msg.payload.decode("utf-8"):
|
||||||
|
print("Profile Index: " + profile.index)
|
||||||
|
print(group)
|
||||||
|
group.set_active_profile(profile.index)
|
||||||
|
print("%s %s" % (msg.topic, msg.payload.decode("utf-8")))
|
||||||
|
|
||||||
|
|
||||||
|
def heating_profile(group):
|
||||||
|
print("Active Heating Profile: " + group.activeProfile.name)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
client.on_message = on_message # Define callback function for receipt of a message
|
||||||
|
|
||||||
|
client.loop_forever() # Start networking daemon
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
Loading…
Reference in New Issue
Block a user