Package: pymee
pymeepymee is the backbone of theHome Assistant homee integration.pymee is an unofficial python library for interacting with thehomeesmart home/home automation platform. It uses thewebsocketslibrary to connect to a local homee cube and maintains a list of nodes (devices), attributes, groups and more that are updated whenever new data arrives from homee.Large parts of this library are directly ported from the awesomehomeeApijavascript library.InstallationInstall fromPyPI:pip install pymeeUsageGetting startedpymee should be used withasyncio:frompymeeimportHomeeimportasyncioimportlogging# Set debug level so we get verbose logslogging.getLogger().setLevel(logging.DEBUG)# Define a simple async entry point functionasyncdefmain():# Create an instance of Homeehomee=Homee("<HOMEE IP>","<USERNAME>","<PASSWORD>")# Connect and start listening on a new taskhomeeTask=asyncio.create_task(homee.run())# Wait until the connection is live and all data has been receivedawaithomee.wait_until_connected()# Do something here...# Close the connection and wait until we are disconnectedhomee.disconnect()awaithomee.wait_until_disconnected()# Start our entry point functionasyncio.run(main())Access devices and attributesDevices are represented as "nodes" in the api. All nodes are available in the listHomee.nodesand are represented by theHomeeNodeclass.
Each node has a list of attributes accessible fromHomeeNode.attributes. The attributes on a node represent the different attributes on a device, i.e. if a light is turned on or the target temperature of a thermostat. Attributes can be identified by theHomeeAttribute.typeproperty. You can compare the type with the values frompymee.const.AttributeTypeto figure out what each attribute represents. The value can be accessed with theHomeeAttribute.current_valueproperty.If you need to change the value of an attribute you can useHomee.set_value():# Get some node, for example using get_node_by_idnode=homee.get_node_by_id(5)# Turn on the device. You need to pass the id of the node and the attribute as well as the value.# Using get_attribute_by_type you can quickly find the desired attribute.awaithomee.set_value(node.id,node.get_attribute_by_type(AttributeType.ON_OFF).id,1)Receiving updatesTheHomeeclass can be inherited to receive events:classMyHomee(Homee):# Called once the websocket connection has been established.asyncdefon_connected(self):pass# Called after the websocket connection has been closed.asyncdefon_disconnected(self):pass# Called after an error has occurred.asyncdefon_error(self,error:str):pass# Called when the websocket receives a message.# The message is automatically parsed from json into a dictionary.asyncdefon_message(self,msg:dict):pass# Called when an 'attribute' message was received and an attribute was updated.# Contains the parsed json attribute data and the corresponding node instance.asyncdefon_attribute_updated(self,attribute_data:dict,node:HomeeNode):passYou can also add a listener to specific nodes to receive attribute updates:# A listener is just a function that takes a node and an attributedefmy_node_handler(node:HomeeNode,attribute:HomeeAttribute):logging.info(f"Attribute{attribute.id}of node{node.name}was updated!")node=homee.get_node_by_id(5)# Adding the listener will return a function that can be called to remove the listener againremove_listener=node.add_on_changed_listener(my_node_handler)# If you don't need the listener anymore...remove_listener()To manually request updates from Homee, you can use the following functions:homee.update_node(self,nodeId:int)"""Request current data for a node."""homee.update_attribute(self,nodeId:int,attributeId:int)"""Request current data for an attribute"""More examplesExample implementation that dumps all info into a json file and logs whenever a light is turned on or off:frompymee.constimportNodeProfile,AttributeTypefrompymee.modelimportHomeeAttributeclassJsonHomee(Homee):asyncdefon_message(self,msg:dict):# Homee sends an "all" message at the beginning of each connection# or after 'GET:all' was send.iflist(msg)[0]=="all":f=open("homee.json","w")f.write(json.dumps(msg))f.close()asyncdefon_attribute_updated(self,attribute_data,node):# Wrap the attribute data with the HomeeAttribute class for easier accessattribute=HomeeAttribute(attribute_data)# We only care for changesifattribute.current_value==attribute.target_value:return# Check node profile (the type of device) and attribute typeif(node.profile==NodeProfile.DIMMABLE_EXTENDED_COLOR_LIGHTandattribute.type==AttributeType.ON_OFF):self._log(f"[Light]{node.name}turned{'on'ifattribute.target_value==1else'off'}")LicenseMIT