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

Paulus Schoutsen - Awaken your home: Python and...

Paulus Schoutsen - Awaken your home: Python and the Internet of Things

People are acquiring more and more connected devices for their homes. With no standard in place for communication, vendors are shipping their own platforms. This results in devices unable to work together. This talk shows people how to take control of their houses, their data and their privacy using Python – no cloud attached. Enter the world of Home Assistant.

https://us.pycon.org/2016/schedule/presentation/1752/

PyCon 2016

May 29, 2016
Tweet

More Decks by PyCon 2016

Other Decks in Programming

Transcript

  1. Awaken Your Home: Python and the Internet of Things Home

    Assistant Paulus Schoutsen PyCon 2016, Portland 1
  2. What’s the essence of a hub? • Devices have a

    state ◦ Light = on ▪ Brightness: 60% ▪ Color: red ◦ Media player = playing ▪ Volume: 80% ▪ TV Show: Game of Thrones Home Assistant · 3 Information (ie. light is on) Commands (ie. turn light on) Home Control Internet of Things • There are events happening: ◦ State of light has changed ◦ Motion detected
  3. What’s the core of home automation? Automation rules are: •

    Triggered by an event. • Optional conditions based on the current state of devices. • Action can control a device or external service. Home Assistant · 4 User Home Automation Commands Rules Information Commands Information Home Control
  4. Responsive web app that runs great everywhere. Track the state

    of your house over time. 5 Home automation platform running on Python 3. Open-source, MIT license. Runs on tiny computers like $35 Raspberry Pi. Host it yourself so your data stays yours. Track people and things on a map. 286 built-in components and platforms that add support for a wide range of devices and services.
  5. • Event driven system. Home Assistant · 6 State Machine

    Event Bus State changed events Timer Time changed events Service Registry Call service events Service executed events Core Architecture • State Machine has no notion of lights or switches. Just entities and their state. • Service Registry to track available services. • Timer to notify time changed.
  6. Service Registry State Machine Event Bus State changed events Set

    state Light Bulb Light Component Poll state Automation Component Motion detected events Motion Detector Motion Detector Component Motion detected events Call service turn light on Turn on Interaction between Home Assistant core, components and the Internet of Things Home Assistant · 7 Turn on Call service turn light on
  7. Support for devices in Home Assistant • An entity component

    per device type: light, switch, etc • Each protocol/cloud/etc implemented as a platform • Exports abstract base class (ABC) that connects to Home Assistant core. ◦ Defines information to be exposed (is_on, rgb_color, brightness) ◦ Defines methods to be called (turn_on, turn_off) Home Assistant · 8
  8. Create file as: <config>/custom_comp onents/sensor/exampl e.py In configuration.yaml file: sensor:

    platform: example Sensor platform For source code, see: https://gist.github.com/balloob/3e8ae00a2354f4e889c0
  9. • Based on existence file. • Configurable File path Switch

    platform For source code, see: https://gist.github.com/balloob/3e8ae00a2354f4e889c0 Create file as: <config>/custom_componen ts/switch/example.py In configuration.yaml file: switch: platform: example file_path: /tmp/switch
  10. Automation Component • Keep two entities in opposite states. Home

    Assistant · 11 For source code, see: https://gist.github.com/balloob/3e8ae00a2354f4e889c0 Create file as: <config>/custom_compone nts/xor_automation.py In configuration.yaml file: xor_automation: entity_1: switch.ac Entity_2: switch.air
  11. Try the demo on your phone at home-assistant.io/demo On your

    computer with Python 3: pip3 install homeassistant hass --open-ui Visit our website for more information and tutorials: home-assistant.io Join our community: community.home-assistant.io gitter.im/home-assistant/home-assistant Home Assistant · 12 Home Assistant
  12. • Device Types (light, etc) • Presence Detection • Entity

    Organization • Automation • History / Export Data • Third-Party Service Integrations Find all 286 components and platforms on home-assistant. io/components There’s a component for that. Home Assistant · 13
  13. • Turn light on 1 hour before sunset if anyone

    is home. • Using automation component. Example automation configuration Home Assistant · 14 • 1 or more triggers. • 0 or more conditions. ◦ Time ◦ Event ◦ State ◦ Sun ◦ Zone (GPS) ◦ MQTT