Package description
Project description
Python Amazon Dash
Hack your Amazon Dash to run what you want. Without welders. For the entire family.
This program written in Python runs in daemon mode waiting for someone in the same network to press a configured Amazon Dash button. It is not necessary to know programming to use this program. Amazon-Dash executes commands by command line or calls a url. This program works well on a raspberry PI or on computers with few resources.
Install Amazon Dash:
sudo pip install amazon-dash
Use discovery mode to know the mac of your Dash (Run the program, and then press the button):
sudo amazon-dash discovery
Create a config file (amazon-dash.yml):
# amazon-dash.yml
# ---------------
settings:
delay: 10
devices:
0C:47:C9:98:4A:12:
name: Hero
user: nekmo
cmd: spotify
44:65:0D:48:FA:88:
name: Pompadour
user: nekmo
cmd: /opt/open-door kitcken
AC:63:BE:67:B2:F1:
name: Kit Kat
url: 'http://domain.com/path/to/webhook'
method: post
content-type: json
body: '{"mac": "AC:63:BE:67:B2:F1", "action": "toggleLight"}'
Run the daemon:
sudo amazon-dash[ --config amazon-dash.yml] run
By default, amazon-dash will use the amazon-dash.yml file in the current directory with sudo amazon-dash run. However, you can set the path to the file (for example, /etc/amazon-dash.yml) with --config parameter. Please note that --config must be before run.
The default level logging is INFO but you can change it using the --warning, --quiet, --debug and --verbose options. To see on screen every time a button is pressed you need to set the --debug option.
By default it is forbidden to execute commands as root in your configuration file. This is a security measure to avoid escalation privileges. If you are going to run amazon-dash as root it is highly recommended to define a user by each cmd config device. You can disable this security measure using --root-allowed.
Contents
Run at startup
This example is for systems with Systemd. The files of the services are in this link. If your system is not supported, feel free to do a pull request.
Copy amazon-dash.service to /etc/systemd/system/.
Create your config file in /etc/amazon-dash.yml.
Enable your service with sudo systemctl enable amazon-dash.
Start your service with sudo systemctl start amazon-dash.
Examples
Here are some examples of how to use your Amazon Dash button:
Random Episode: Play a random chapter of your favorite series, like The Simpsons, Futurama, Friends… https://github.com/Nekmo/random-episode
Config file
The configuration file can be found anywhere but if the program runs in root mode, it is necessary that only root can modify the file. This is a security measure to prevent someone from executing commands as root using the program.
To change the permissions:
sudo chmod 600 amazon-dash.yml sudo chown root:root amazon-dash.yml
The syntax of the configuration file is yaml. The configuration file has 2 main sections:
settings (optional): common options.
devices (required): The amazon dash devices.
The following options are available in settings:
delay (optional): On seconds. By default, 10 seconds. Minimum time that must pass between pulsations of the Amazon Dash button.
Each device is identified by the button mac. The mac can be obtained with the discovery command. In the configuration of each button, there may be a way of execution. Only one execution method is allowed for each device. The available exection methods are:
cmd: local command line command. Arguments can be placed after the command.
url: Call a url.
When the cmd execution method is used, the following options are available.
user: System user that will execute the command. This option can only be used if Amazon-Dash is running as root.
cwd: Directory in which the command will be executed.
When the url execution method is used, the following options are available.
method: HTTP method. By default GET.
content-type (*): HTTP Content-Type Header. Only available if Body is defined. If body is defined, default is form.
body: Request payload. Only if the method is POST/PUT/PATCH. In json or form mode, the content must be a valid json. It is recommended to use single quotes before and after content in json.
(*) Content type aliases: form = application/x-www-form-urlencoded. json = application/json. plain = text/plain.
An example of a configuration file can be found at the beginning of the documentation.
Changelog
v0.3.0
Unit testing.
Travis CI.
Config validation.
Help messages.
Request to URL.
Distinguish Amazon devices in discovery mode.
v0.2.0
Securize config file.
Systemd config file example.
Refactor imports.
Updated README.
v0.1.0
Execute commands.
Discovery mode.
Setup.py
README.
Troubleshooting
Requirements and installation
All dependencies are commonly used on a Linux system, but some may not be installed on your system. The dependencies are:
Python 2.7 or 3.4+.
Python-pip (pip).
Tcpdump.
Sudo
Why root is required
This program needs permission to open raw sockets on your system. You can set this permission using setcap, but you must be very careful about who can run the program. Raw sockets permission could allow scaling permissions on the system:
setcap cap_net_raw=eip ./scripts/amazon-dash setcap cap_net_raw=eip /usr/bin/pythonX.X setcap cap_net_raw=eip /usr/bin/tcpdump
http://stackoverflow.com/questions/36215201/python-scapy-sniff-without-root
References
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.