2017-12-11 20:30:57 +01:00
Platypush
2017-11-03 12:34:47 +01:00
=========
Execute any command or custom complex logic on your devices, wherever they are, using your PushBullet account.
2017-11-03 15:06:29 +01:00
Installation
------------
```shell
2017-12-11 20:30:57 +01:00
pip install platypush
2017-11-03 15:06:29 +01:00
```
2017-12-11 20:33:36 +01:00
### Manual Installation
```shell
2017-12-11 20:34:13 +01:00
git clone https://github.com/BlackLight/platypush
cd platypush
2017-12-11 20:33:36 +01:00
python setup.py install
```
2017-11-03 15:06:29 +01:00
Configuration
-------------
2017-12-11 20:30:57 +01:00
Copy /etc/platypush/config.example.yaml to /etc/platypush/config.yaml (system-wise settings) or ~/.config/platypush/config.yaml (user-wise settings).
2017-11-03 15:06:29 +01:00
Edit the file to include:
2017-12-11 16:48:28 +01:00
### For the PushBullet backend
2017-11-03 15:06:29 +01:00
* Your PushBullet access token (create one [here ](https://www.pushbullet.com/#settings/account ));
* The name of the (virtual) PushBullet device used to listen for events (create one [here ](https://www.pushbullet.com/#devices )).
2017-12-11 16:48:28 +01:00
### For the Apache Kafka backend
* The host and port of the Kafka installation
* The topic that will be used to deliver and process messages
### For the local socket backend
* The name of the local FIFO that will be used to deliver and process messages
### device_id
2017-11-03 18:17:47 +01:00
Each target device is identified by a unique device_id in the messages sent over your account. The device_id is the hostname by default, unless changed in config.yaml.
2017-11-05 01:11:13 +01:00
Shell interface
---------------
2017-12-11 20:30:57 +01:00
`platypush` installs `pusher` , a command-line tool to send PushBullet messages to the connected devices in the format used by platypush.
2017-11-05 01:11:13 +01:00
Some examples:
```shell
pusher --target laptop --action shell.exec --cmd "scp /home/user/photos/*.jpg backup_host:/mnt/hd/photos"
pusher --target raspberrypi --action music.mpd.play
```
The logic to execute is specified by the `--action` option, whose format is `package_name.method_name` (with method_name part of the package main class).
2017-11-05 01:00:03 +01:00
Available plugins
-----------------
2017-12-11 20:30:57 +01:00
* `platypush.plugins.shell` : The simplest and yet most versatile plugin. Executes a remote command on the host identified by the `--target` device_id. Example:
2017-11-05 01:00:03 +01:00
```shell
pusher --target laptop --action shell.exec --cmd "scp /home/user/photos/*.jpg backup_host:/mnt/hd/photos"
```
2017-12-11 20:30:57 +01:00
* `platypush.plugins.music.mpd` : Controls the playback on a mpd/mopidy music server. Requires the package `mpd2` on the target machine. Example:
2017-11-05 01:00:03 +01:00
```shell
2017-11-05 01:11:13 +01:00
pusher --target raspberry --action music.mpd.play
2017-11-05 01:00:03 +01:00
```
2017-11-05 01:11:13 +01:00
Configure the plugin through an entry like this in your `config.yaml` :
2017-11-05 01:00:03 +01:00
2017-11-05 01:11:13 +01:00
```yaml
music.mpd:
host: your_mpd_host
port: 6600
2017-11-05 01:00:03 +01:00
```
2017-12-11 20:30:57 +01:00
* `platypush.plugins.switch.wemo` : Controls a WeMo Switch smart switch device. Requires the package `ouimeaux` on the target machine. Example:
2017-11-03 18:17:47 +01:00
2017-11-05 01:11:13 +01:00
```shell
pusher --target raspberry --action switch.wemo.on
```
2017-11-03 18:17:47 +01:00
2017-12-11 20:30:57 +01:00
* `platypush.plugins.light.hue` : Controls a Philips Hue smart lights system. Requires the package `phue` on the target machine. Example:
2017-11-03 18:17:47 +01:00
```shell
2017-12-11 16:48:28 +01:00
pusher --target raspberry --action light.hue.scene --name "Sunset" --group "Living Room"
2017-11-03 18:17:47 +01:00
```
2017-11-03 20:18:10 +01:00
Writing your plugins
--------------------
2017-12-11 20:30:57 +01:00
Writing your own `platypush` plugin, that would execute your own custom logic whenever a bullet with your plugin name is received, is a very simple task.
2017-11-03 20:18:10 +01:00
2017-12-11 20:30:57 +01:00
1. Create your plugin directory under `platypush/plugins` (e.g. `light/batsignal` ).
2017-11-03 20:18:10 +01:00
2017-12-11 20:30:57 +01:00
2. In the case above, `platypush.plugins.light.batsignal` will be your package name.
2017-11-03 20:18:10 +01:00
2017-12-11 20:30:57 +01:00
3. Create an `__init__.py` under `platypush/plugins/light/batsignal` .
2017-11-03 20:18:10 +01:00
4. If your module is `light/batsignal` , then its main class should be named `LightBatsignalPlugin` .
5. The configuration for your module will be read from a section named `light.batsignal` from your `config.yaml` , the attributes are accessible in your class in `self.config` .
The `__init__.py` will look like this:
```python
2017-11-04 12:28:15 +01:00
import batman
2017-12-13 04:21:26 +01:00
from platypush.message.response import Response
2017-12-13 03:37:28 +01:00
2017-11-03 20:18:10 +01:00
from .. import LightPlugin
class LightBatsignalPlugin(LightPlugin):
def _init(self):
2017-11-04 12:28:15 +01:00
self.batsignal = batman.Batsignal(self.config['intensity'])
2017-11-03 20:18:10 +01:00
2017-11-04 14:02:56 +01:00
def on(self, urgent=False):
2017-11-05 00:50:41 +01:00
if urgent:
2017-11-04 14:02:56 +01:00
self.batsignal.notify_robin()
2017-11-03 20:18:10 +01:00
self.batsignal.on()
2017-12-13 03:37:28 +01:00
return Response('ok')
2017-11-03 20:18:10 +01:00
def off(self):
self.batsignal.off()
2017-12-13 03:37:28 +01:00
return Response('ok')
2017-11-03 20:18:10 +01:00
def toggle(self):
self.batsignal.toggle()
2017-12-13 03:37:28 +01:00
return Response('ok')
2017-11-03 20:18:10 +01:00
```
2017-12-13 03:37:28 +01:00
6. Rebuild and reinstall `platypush` if required and relaunch it.
2017-11-03 21:33:53 +01:00
2017-12-13 03:37:28 +01:00
7. Test your new plugin by sending some bullets to it:
2017-11-03 20:18:10 +01:00
```shell
2017-11-04 14:02:56 +01:00
pusher --target your_pc --action light.batsignal.on --urgent 1
2017-11-03 20:18:10 +01:00
```
2017-11-04 14:02:56 +01:00