Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Marek Kuziel: Python in Home Automation

Marek Kuziel: Python in Home Automation

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Marek Kuziel:
Python in Home Automation
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
@ Kiwi PyCon 2013 - Sunday, 08 Sep 2013 - Track 1
http://nz.pycon.org/

**Audience level**

Intermediate

**Description**

Using Python to build a Home Automation system by connecting various bits of (open) hardware with protocols such as MQTT, or XMPP. Creating web-based interfaces for HA systems.

**Abstract**

Protocols: brief introduction to MQTT and XMPP protocols. Introduction to related Python tools/libraries.

Hardware: using hardware such Arduino, or Beaglebone as components for a DIY home automation systems.

Low-level: serial communication, MQTT communication, XMPP communication using Python.

High-level: web-based interface(s) for a Home Automation system made in Python.

Connecting the dots: general overview of how Python can be used in Home Automation.

**YouTube**

http://www.youtube.com/watch?v=hXnDyHidDqo

6b880a0b67fac54c42c77fe70d97334d?s=128

New Zealand Python User Group

September 08, 2013
Tweet

More Decks by New Zealand Python User Group

Other Decks in Programming

Transcript

  1. Python in Home Automation Marek Kuziel

  2. TL;DR Everything you need is already out there Do NOT

    try to reinvent the wheel If it feels wrong, it is wrong
  3. /me Studied Automation & Robotics Building a House (kuziel.info/house) Like

    Open Source Software & Hardware
  4. Why (Home) Automation? Automate Repeatable Processes Command & Control Learn

    & Predict
  5. How It Works? Sensor – Button, Light, Sound, Smoke, Temp

    Controller – ATMega, ARM / C, Python Actuator – Relay, Servo Motor
  6. 5 Senses of Home Sight – Cam, Ultra-Sonic, Night, Motion

    Hearing – Sound Sensors Smell – Smoke Sensors Touch – Buttons, Tablet, Mobile, Web UI Temperature – Heating, Blinds, A/C
  7. Bonus Features Light Control Audio/Video Weather Station Garden

  8. B.uild Y.our O.wn Hardware Protocols Software

  9. /me invents Idea Proof of Concept Implementation

  10. /me sobers up Idea is NOT new Proof of concept

    ≠ production ready Production ready implementation already exists
  11. Hardware Arduino Freetronics BeagleBone CubieBoard RaspberryPi

  12. Protocols MQTT XMPP socket.io

  13. Software Python Mosquitto PyXmpp2 gevent-socketio Django (or any other framework)

  14. MQTT “MQTT is a machine-to-machine [sic] connectivity protocol. It was

    designed as an extremely lightweight publish/subscribe messaging transport.” – mqtt.org
  15. mosquitto - Python MQTT Term 1 $ cat << 'EOF'

    > my_test_client_publish.py > #/usr/bin/env python > import mosquitto > client = "my-test-client" > c = mosquitto.Mosquitto(client) > c.connect("127.0.0.1", 1883, 60) > c.publish("house/announce", "Hello, World! -- %s" % client) > EOF Term1 $ python my_test_client_publish.py Term1 $ mosquitto_pub -t "house/announce" -m "hello there" Term2 $ sudo apt-get install mosquito Term2 $ sudo apt-get install python-mosquitto Term2 $ mosquitto_sub -t "house/announce" Hello, World! -- my-test-client Hello there
  16. XMPP “The Extensible Messaging and Presence Protocol (XMPP) is an

    open technology for real-time communication, which powers a wide range of applications including instant messaging, presence, multi-party chat, voice and video calls, collaboration, lightweight middleware, content syndication, and generalized routing of XML data.” – xmpp.org
  17. PyXmpp2 – Python XMPP from pyxmpp2.simple import send_message send_message("bob@example.org", "bob's

    password", "alice@example.org", "Hello Alice")
  18. gevent-socketio – Socket.io Python “Socket.IO enables real-time web communications between

    a browser and a server, using a WebSocket-like API.” – github.com/abourget/gevent-socketio
  19. Control Systems Source: http://en.wikipedia.org/wiki/Control_theory

  20. PID Controller Proportional Integral Derivative http://examples.oreilly.com/9780596809577/CH09/PID.py

  21. Links • http://arduino.cc • http://freetronics.com • http://jajcus.github.io/pyxmpp2/ • http://kuziel.info/home-made/home-automation/mqtt/ •

    http://mqtt.org • http://mosquitto.org/man/mqtt-7.html • https://github.com/binarybucks/homA • http://en.wikipedia.org/wiki/PID_controller • http://seeedstudio.com • http://xmpp.org/
  22. Thank you! @marekkuziel

  23. Questions?