Slide 1

Slide 1 text

Awaken Your Home: Python and the Internet of Things Home Assistant Paulus Schoutsen PyCon 2016, Portland 1

Slide 2

Slide 2 text

Home Assistant · 2

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

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.

Slide 6

Slide 6 text

● 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.

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

Create file as: /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

Slide 10

Slide 10 text

● Based on existence file. ● Configurable File path Switch platform For source code, see: https://gist.github.com/balloob/3e8ae00a2354f4e889c0 Create file as: /custom_componen ts/switch/example.py In configuration.yaml file: switch: platform: example file_path: /tmp/switch

Slide 11

Slide 11 text

Automation Component ● Keep two entities in opposite states. Home Assistant · 11 For source code, see: https://gist.github.com/balloob/3e8ae00a2354f4e889c0 Create file as: /custom_compone nts/xor_automation.py In configuration.yaml file: xor_automation: entity_1: switch.ac Entity_2: switch.air

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

● 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

Slide 14

Slide 14 text

● 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