Package: chattyraspi
Chattyraspi is a support library to connect your Raspberry Pi to Amazon
Alexa.Quick startConnect tothe configuration
consoleLogon using your Amazon credentialsAdd your device(s)Download your configuration fileStart the the example script:test_chattyraspi--configdevices_configuration.yamlInstall Chattyraspy skill on your AlexaDetect your new device(s) on AlexaTurn on/off your device(s) using AlexaCustom scriptChattyraspi allows you to intercept the following Alexa interface
commands:All the turn on/off requestsTemperature sensor commandsThermostat control commandsupon which you can freely react as you wish.For instance, you might decide to:Power control devices attached on your Raspi using Alexa interfaceReceive on Alexa temperature info from a sensor connected to your
RaspiHack the Alexa thermostat interface to control step motors rotationHack the Alexa thermostat interface to control brushless motors speedAssociate the Tun On/Off command to sysadmin tasks, such as starting
networking servicesThis snippet of code comes from thetest_chattyraspiscript, as an
example of how to implement custom logics when receiving Alexa commands:#!/usr/bin/env pythonfromlogging.configimportfileConfigimportclickimporttypingfromchattyraspi.clientimportClient,ThermostatModefromchattyraspi.deviceimportDevicesConfigurationdeftest_devices():# Optionally configure you logging systemlogging_conf_file='<youg logging configuration>'fileConfig(logging_conf_file,disable_existing_loggers=False)config=DevicesConfiguration('devices_configuration.yaml')client=Client(config)statuses=dict()temperatures=dict()thermostat_modes=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 somehowstatuses[device_id]=Truedef_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]=Falsedef_fetch_is_power_on(device_id:str)->bool:print('Device{}requested power status'.format(device_id))# Here Alexa is asking for the power status of your device.# Please be consistent with what you have done beforestatus=statuses[device_id]print('Returning',status)returnstatusdef_fetch_temperature(device_id:str)->float:# Here Alexa is asking for the current temperature.# This may happen both on status report or explicit temperature request.print('Device{}requested temperature'.format(device_id))temperature=temperatures[device_id]# Simulate a temperature that has not been reached yetiftemperatureisnotNone:temperature-=10print('Returning',temperature)returntemperaturedef_fetch_thermostat_mode(device_id:str)->ThermostatMode:# Here Alexa is asking for the thermostat mode.# This may happen both on status report or explicit thermostat mode request.print('Device{}requested thermostat mode'.format(device_id))thermostat_mode=thermostat_modes[device_id]print('Returning',thermostat_mode)returnthermostat_modedef_fetch_thermostat_target_setpoing(device_id:str)->float:# Here Alexa is asking for the current temperature.# This may happen both on status report or explicit temperature request.print('Device{}requested target setpoint'.format(device_id))temperature=temperatures[device_id]print('Returning',temperature)returntemperaturedef_on_set_temperature(device_id:str,temperature:float):# Here Alexa is asking to set the target temperature.# Please be consistent with what you have done beforeprint('Device{}set temperature at{}'.format(device_id,temperature))temperatures[device_id]=temperaturedef_on_adjust_temperature(device_id:str,temperature:float):# Here Alexa is asking to adjust the target temperature by a delta..# Please be consistent with what you have done beforeprint('Device{}adjust temperature by{}'.format(device_id,temperature))temperatures[device_id]+=temperaturedef_on_set_thermostat_mode(device_id:str,thermostat_mode:ThermostatMode):# Here Alexa is asking to set the thermostat mode.# Please be consistent with what you have done beforeprint('Device{}set thermostat_mode{}'.format(device_id,thermostat_mode))thermostat_modes[device_id]=thermostat_mode# Some boilerplate code: here we add the same callbacks for each configured# device.fordevice_idinmap(lambdad:d['device_id'],config.get_configuration()['Devices']):statuses[device_id]=Falseclient.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.set_fetch_temperature(device_id,_fetch_temperature)client.set_fetch_thermostat_mode(device_id,_fetch_thermostat_mode)client.set_fetch_thermostat_target_setpoint(device_id,_fetch_thermostat_target_setpoing)client.set_on_set_temperature(device_id,_on_set_temperature)client.set_on_adjust_temperature(device_id,_on_adjust_temperature)client.set_on_set_thermostat_mode(device_id,_on_set_thermostat_mode)client.listen()if__name__=='__main__':test_devices()DisclaimerThis software is provided “as is” and “with all faults.” I make no
representations or warranties of any kind concerning the safety,
suitability, lack of viruses, inaccuracies, typographical errors, or
other harmful components of this software. There are inherent dangers in
the use of any software, and you are solely responsible for determining
whether this software is compatible with your equipment and other
software installed on your equipment. You are also solely responsible
for the protection of your equipment and backup of your data, and I will
not be liable for any damages you may suffer in connection with using,
modifying, or distributing this software.