Coder Social home page Coder Social logo

pyhomematic's Introduction

pyhomematic

image

Python 3 Interface to interact with Homematic devices.

This library provides easy (bi-directional) control of Homematic devices hooked up to a regular CCU or Homegear. The focus is to be able to receive events. If you are only interested in actively controlling devices, you can use the Python-built-in xmlrpc.client.ServerProxy (Python 3). See pyhomematic._server.ServerThread.connect on how to connect to a CCU / Homegear as a client.

Included is a XML-RPC server to receive events emitted by devices. Multiple callback functions can be set for devices to handle events. You can choose to bequeath callbacks from devices to their channels or not. Channels can not bequeath to their parent devices. You can also pass a callback funtion when creating the server, which then will (additionally) receive all events emitted by any paired device.

You may specify a devicefile (JSON) to store known devices. This might speed up startup a bit. If you don't, paired devices will always be propagated upon startup. If devices get paired while the server is running, they should be automatically detected and usable. To get notified about such events, it is possible to pass a systemcallback(source, *args)-function while creating the server.

Compatibility currently is only given for Python 3, since this library is primarily intended to add Homematic to https://home-assistant.io/, wich is written in Python 3.

As of now, usage is as follows (you could leave away the listening and remote addresses when everything is running on one machine):

>>> def syscb(src, *args): >>> print(src) >>> for arg in args: >>> print(arg) >>> def cb1(address, interface_id, key, value): >>> print("CALLBACK WITH CHANNELS: %s, %s, %s, %s" % (address, interface_id, key, value)) >>> def cb2(address, interface_id, key, value): >>> print("CALLBACK WITHOUT CHANNELS: %s, %s, %s, %s" % (address, interface_id, key, value)) >>> from pyhomematic import HMConnection >>> pyhomematic = HMConnection(local="192.168.1.12", localport=7080, remote="192.168.1.23", remoteport=2001, systemcallback=syscb) # Create server thread >>> pyhomematic.start() # Start server thread, connect to homegear, initialize to receive events >>> pyhomematic.devices['address_of_rollershutter_device'].move_down() # Move rollershutter down >>> pyhomematic.devices_all['address_of_doorcontact:1'].getValue("STATE") # True or False, depending on state >>> pyhomematic.devices['address_of_doorcontact'].setEventCallback(cb1) # Add first callback >>> pyhomematic.devices['address_of_doorcontact'].setEventCallback(cb2, bequeath=False) # Add second callback >>> pyhomematic.stop() # Shutdown to finish the server thread and quit

This example connects to the Homegear-server running on the same machine, closes the window shutter using the rollershutter device, queries the state of a door contact, adds callbacks for the door contact, then stops the server thread because a sample doesn't need to do more. The server has to be stopped because otherwise Python might hang. An example.py can be found at https://github.com/danielperna84/pyhomematic

Theoretically all Homematic devices will be automatically detected and directly provide the getValue and setValue methods needed to perform any action. Additionally, implemented devices provide convenience-properties and methods to perform certain tasks.

For more information visit the Wiki: https://github.com/danielperna84/pyhomematic/wiki

If pyhomematic doesn't seem to be what you need to interact with your CCU, then https://github.com/LarsMichelsen/pmatic might be (if Homegear support is not required).

pyhomematic's People

Contributors

bimbar avatar buxit avatar cgeidt avatar ch-world avatar chr1st1ank avatar cyclingengineer avatar danielperna84 avatar dickesw avatar emkay82 avatar gomez avatar hanzoh avatar i-am-steve-oh avatar jannau avatar jazzaj avatar klada avatar krawadl avatar marconfus avatar maxm87 avatar mcdeck avatar munsio avatar noxhirsch avatar pascalhahn avatar peterrothert avatar pvizeli avatar rexyiy avatar smoldaner avatar thoscut avatar tosa27 avatar tringler avatar w194 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.