Allows interaction between Alexa and your Raspberry Pi
Project description
Chattyraspi is a support library to connect your Raspberry Pi to Amazon Alexa.
Quick start
Connect to the configuration console
Logon using your Amazon credentials
Add your device(s)
Download your configuration file
Start the the example script: test_chattyraspi --config devices_configuration.yaml
Install Chattyraspy skill on your Alexa
Detect your new device(s) on Alexa
Turn on/off your device(s) using Alexa
Custom script
Chattyraspi allows you to intercept all the turn on/off requests from Alexa, upon which you can freely react as you wish.
This snippet of code comes from the test_chattyraspi script:
#!/usr/bin/env python
from logging.config import fileConfig
import click
import typing
from chattyraspi.client import Client
from chattyraspi.device import DevicesConfiguration
def test_devices():
# Optionally configure you logging system
logging_conf_file = '<youg logging configuration>'
fileConfig(logging_conf_file, disable_existing_loggers=False)
config = DevicesConfiguration('devices_configuration.yaml')
client = Client(config)
statuses = dict()
def _turn_on(device_id: str):
print('Device {} turned ON'.format(device_id))
# Here you have received a turn on request.
# Feel free to do whatever you want, but please remember
# to mark your device as ON somehow
statuses[device_id] = True
def _turn_off(device_id: str):
print('Device {} turned OFF'.format(device_id))
# Here you have received a turn off request.
# Here you are free to do whatever you want, but reasonably
# you would do the opposite as turn on callback.
# Finally, please remember that your device is OFF.
statuses[device_id] = False
def _fetch_is_power_on(device_id: str) -> bool:
print('Device {} requested power status'.format(device_id))
# Here Alexa is asking for the the power status of your device.
# Please be consistent with what you have done before
status = statuses[device_id]
print('Returning', status)
return status
# Some boilerplate code: here we add the same callbacks for each configured
# device.
for device_id in map(lambda d: d['device_id'], config.get_configuration()['Devices']):
statuses[device_id] = False
client.set_on_turn_on(device_id, _turn_on)
client.set_on_turn_off(device_id, _turn_off)
client.set_fetch_is_power_on(device_id, _fetch_is_power_on)
client.listen()
if __name__ == '__main__':
test_devices()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
chattyraspi-0.0.1.tar.gz
(5.9 kB
view hashes)