• Stars
    star
    271
  • Rank 151,717 (Top 3 %)
  • Language
    Python
  • License
    MIT License
  • Created about 7 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A versatile and extensible platform for automation with hundreds of supported integrations

Platypush

Build Status Documentation Status pip version License Last Commit Join chat on Matrix Contributions

Useful links

  • Recommended read: Getting started with Platypush.

  • The blog is a good place to get more insights and inspiration on what you can build.

  • The wiki also contains many resources on getting started.

  • Extensive documentation for all the available integrations and messages is available.

  • If you have issues/feature requests/enhancements please create an issue.

  • A Matrix instance is available if you are looking for interactive support.

  • A Reddit channel is available for general questions.

Introduction

Platypush is a general-purpose extensible platform for automation across multiple services and devices.

It enables users to create their own self-hosted pieces of automation based on events (if this happens then do that) and it provides a comprehensive and customizable user interface that collects everything you need to visualize and control under one roof.

It takes some concepts from IFTTT, Tasker, Microsoft Flow and Home Assistant to provide an environment where the user can easily connect things together.

It's built with compatibility and flexibility in mind, and it can easily run on any device that can run a Python interpreter - from a Raspberry Pi zero, to an old smartphone, to a beefy server.

What it can do

You can use Platypush to do things like:

Installation

System installation

Platypush uses Redis to deliver and store requests and temporary messages:

# Example for Debian-based distributions
[sudo] apt-get install redis-server

# Enable and start the service
[sudo] systemctl enable redis
[sudo] systemctl start redis

Install through pip

[sudo] pip3 install platypush

Install through a system package manager

Note: currently only Arch Linux and derived distributions are supported.

You can either install the platypush package (for the latest stable version) or the platypush-git package (for the latest git version) through your favourite AUR package manager. For example, using yay:

yay platypush
# Or
yay platypush-git

The Arch Linux packages on AUR are automatically updated upon new git commits or tags.

Install from sources

git clone https://git.platypush.tech/platypush/platypush.git
cd platypush
[sudo] pip install .
# Or
[sudo] python3 setup.py install

Installing the dependencies for your extensions

After installing the base platform, you may want to check the dependencies and configuration required by the extensions that you wish to use. There are a few ways to check the dependencies required by an extension:

Install via extras name

All the extensions that require extra dependencies are listed in the extras_require section under setup.py.

Install via manifest.yaml

All the plugins and backends have a manifest.yaml file in their source folder. Any extra dependencies are listed there

If you followed the extras or manifest.yaml way to discover the dependencies, then you can install them in two ways:

  1. pip installation:
[sudo] pip3 install 'platypush[extra1,extra2,extra3]'
  1. Sources installation:
cd $DIR_TO_PLATYPUSH
[sudo] pip3 install '.[extra1,extra2,extra3]'

Check the instructions reported in the documentation

If you follow this route then simply run the commands listed in the plugin/backend documentation to get the dependencies installed.

After installing the dependencies, create a configuration file under ~/.config/platypush/config.yaml (the application can load the configuration from another location through the -c option) containing the configuration of the backend and plugins that you want to use, and add any hooks and procedures for your use case.

You can then start the service by simply running:

platypush

It's advised to run it as a systemd service though - simply copy the provided .service file to ~/.config/systemd/user, check if the path of platypush matches the path where it's installed on your system, and start the service via systemctl:

systemctl --user start platypush

Virtual environment installation

Platypush provides a script named platyvenv that can parse a config.yaml and automatically create a virtual environment (under ~/.local/share/platypush/venv/<device_id>) with all the dependencies required by the configured integrations.

  1. Create the environment from a configuration file:

    platyvenv build -c /path/to/config.yaml
  2. Start the service from the virtual environment:

        # device_id matches either the hostname or the device_id in config.yaml
    platyvenv start device_id
  3. Stop the instance:

    platyvenv stop device_id
  4. Remove the instance:

    platyvenv rm device_id

Wiki instructions

Docker installation

You can also install Platypush in a container - the application provides a script named platydock that automatically creates a container instance from a config.yaml:

  1. Create the container from a configuration file:

    platydock build -c /path/to/config.yaml
  2. Start the container:

        # device_id matches either the hostname or the device_id in config.yaml
    platydock start device_id
  3. Stop the instance:

    platydock stop device_id
  4. Remove the instance:

    platydock rm device_id

Note that both the virtual environment and Docker container option offer the possibility to include extra YAML configuration files in the main config.yaml through the include directive (as long as they are in the same folder as the main config.yaml), as well as external Python scripts in a scripts directory in the same folder as the config.yaml.

Wiki instructions

Architecture

The architecture of Platypush consists of a few simple pieces, orchestrated by a configuration file stored by default under ~/.config/platypush/config.yaml:

Plugins

Full list

Plugins are integrations that do things - like modify files, train and evaluate machine learning models, control cameras, read sensors, parse a web page, control lights, send emails, control Chromecasts, run voice queries, handle torrent transfers or control Zigbee or Z-Wave devices.

The configuration of a plugin matches one-on-one that of its documented class constructor, so it's very straightforward to write a configuration for a plugin by reading its documentation:

light.hue:
  # Groups that will be controlled by default
  groups:
    - Living Room
    - Hall

Actions

Plugins expose actions, that match one-on-one the plugin class methods denoted by @action, so it's very straightforward to invoke plugin actions by just reading the plugin documentation. They can be invoked directly from your own scripts or they can be sent to the platform through any supported channel as simple JSON messages:

{
  "type": "request",
  "action": "light.hue.on",
  "args": {
    "lights": ["Entrance Bulb"]
  }
}

Backends

Full list

They are background services that listen for messages on channels (like an HTTP backend, an MQTT instance, a Kafka instance, Pushbullet etc.).

If a backend supports the execution of requests (e.g. HTTP, MQTT, Kafka, Websocket and TCP) then you can send requests to these services in JSON format. For example, in the case of the HTTP backend:

# Get a token
curl -XPOST -H 'Content-Type: application/json' -d '
{
  "username": "$YOUR_USER",
  "password": "$YOUR_PASSWORD"
}' http://host:8008/auth

# Execute a request
curl -XPOST -H 'Content-Type: application/json' \
    -H "Authorization: Bearer $YOUR_TOKEN" -d '
{
  "type": "request",
  "action": "tts.say",
  "args": {
    "text": "This is a test"
  }
}' http://host:8008/execute

Events

Full list

When a certain event occurs (e.g. a JSON request is received, or a Bluetooth device is connected, or a Flic button is pressed, or some speech is detected on the voice assistant service, or an RSS feed has new items, or a new email is received, or a new track is played, or an NFC tag is detected, or new sensor data is available, or a value of a Zigbee device changes, etc.), the associated backend will trigger an event.

Hooks

Event hooks are custom pieces of logic that will be run when a certain event is triggered. Hooks are the glue that connects events to actions, exposing a paradigm similar to IFTTT (if a certain event happens then run these actions). They can declared as:

event.hook.SearchSongVoiceCommand:
  if:
    type: platypush.message.event.assistant.SpeechRecognizedEvent
    phrase: "play ${title} by ${artist}"
  then:
    - action: music.mpd.clear
    - action: music.mpd.search
      args:
        filter:
          artist: ${artist}
          title: ${title}

    - if ${len(output)}:
      - action: music.mpd.play
        args:
          resource: ${output[0]['file']}
  • Stand-alone Python scripts stored under ~/.config/platypush/scripts and will be dynamically imported at start time. Example:
from platypush.event.hook import hook
from platypush.utils import run
from platypush.message.event.assistant import SpeechRecognizedEvent

@hook(SpeechRecognizedEvent, phrase='play ${title} by ${artist}')
def on_music_play_command(event, title=None, artist=None, **context):
  results = run('music.mpd.search', filter={
    'artist': artist,
    'title': title,
  })

  if results:
    run('music.mpd.play', results[0]['file'])

Procedures

Procedures are pieces of custom logic that can be executed as atomic actions using procedure.<name> as an action name.

They can be defined either in the config.yaml or as Python scripts stored under ~/.config/platypush/scripts - provided that the procedure is also imported in ~/.config/platypush/scripts/__init__.py so it can be discovered by the service.

YAML example for a procedure that can be executed when we arrive home and turns on the lights if the luminosity is lower that a certain thresholds, says a welcome home message using the TTS engine and starts playing the music:

procedure.at_home:
    # Get luminosity data from a sensor - e.g. LTR559
    - action: gpio.sensor.ltr559.get_data

    # If it's lower than a certain threshold, turn on the lights
    - if ${int(light or 0) < 110}:
        - action: light.hue.on

    # Say a welcome home message
    - action: tts.google.say
      args:
        text: Welcome home

    # Play the music
    - action: music.mpd.play

Python example:

# Content of ~/.config/platypush/scripts/home.py
from platypush.procedure import procedure
from platypush.utils import run

@procedure
def at_home(**context):
  sensor_data = run('gpio.sensor.ltr559.get_data')
  if sensor_data['light'] < 110:
    run('light.hue.on')

  run('tts.google.say', text='Welcome home')
  run('music.mpd.play')

In either case, you can easily trigger the at-home procedure by sending an action request message to a backend - for example, over the HTTP backend:

curl -XPOST -H 'Content-Type: application/json' \
    -H "Authorization: Bearer $YOUR_TOKEN" -d '
{
  "type": "request",
  "action": "procedure.at_home"
}' http://host:8008/execute

Cronjobs

Cronjobs are pieces of logic that will be run at regular intervals, expressed in crontab-compatible syntax. They can be defined either in the config.yaml or as Python scripts stored under ~/.config/platypush/scripts as functions labelled by the @cron decorator.

Note that seconds are also supported (unlike the standard crontab definition), but, for back-compatibility with the standard crontab format, they are at the end of the cron expression, so the expression is actually in the format <minute> <hour> <day_of_month> <month> <day_of_week> <second>.

YAML example for a cronjob that is executed every 30 seconds and checks if a Bluetooth device is nearby:

cron.check_bt_device:
  cron_expression: '* * * * * */30'
  actions:
    - action: bluetooth.lookup_name
      args:
        addr: XX:XX:XX:XX:XX:XX

    - if ${name}:
        - action: procedure.on_device_on
    - else:
        - action: procedure.on_device_off

Python example:

# Content of ~/.config/platypush/scripts/bt_cron.py
from platypush.cron import cron
from platypush.utils import run

@cron('* * * * * */30')
def check_bt_device(**context):
  name = run('bluetooth.lookup_name').get('name')
  if name:
    # on_device_on logic here
  else:
    # on_device_off logic here

Entities

Entities are a fundamental building block of Platypush. Most of the integrations will store their state or connected devices in the form of entities - e.g. the sensors detected by the Z-Wave/Zigbee/Bluetooth integration, or the lights connected to a Hue bridge, or your cloud nodes, or your custom Arduino/ESP machinery, and so on.

Entities provide a consistent interface to interact with your integrations regardless of their type and the plugin that handles them. For instance, all temperature sensors will expose the same interface, regardless if they are Bluetooth or Zigbee sensors, and all the media plugins will expose the same interface, regardless if they manage Chromecasts, Kodi, Plex, Jellyfin or a local VLC player.

Once you enable the HTTP backend and a few integrations that export entities and register a user, you can query the detected entities via:

curl -XPOST -H 'Content-Type: application/json' \
    -H "Authorization: Bearer $YOUR_TOKEN" \
    -d '{"type":"request", "action":"entities.get"}' \
    http://localhost:8008/execute

All the entities expose the same interface and can be manipulated through the same API. Also, when an entity is updated it always emits an EntityUpdateEvent, so you can easily create hooks that react to these events and act on multiple types of entities.

The web interface

If backend.http is enabled then a web interface will be provided by default on http://host:8008/. Besides using the /execute endpoint for running requests, the built-in web server also provides a full-featured interface that groups together the controls for most of the plugins - e.g. sensors, switches, music controls and search, media library and torrent management, lights, Zigbee/Z-Wave devices and so on. The UI is responsive and mobile-friendly.

The web service also provides means for the user to create custom dashboards that can be used to show information from multiple sources on a large screen.

Mobile app

An official Android app is provided on the F-Droid store. It allows to easily discover and manage multiple Platypush services on a network through the web interface, and it easily brings the power of Platypush to your fingertips.

Tests

To run the tests simply run pytest either from the project root folder or the tests/ folder.


Funding

If you use and love Platypush, please consider buying me a coffee/beer.

I've been working on Platypush all by myself in my spare time for the past few years, and I've made sure that it remains open and free.

If you like this product, please consider supporting - I'm definitely not planning to get rich with this project, but I'd love to have at least the costs for the server covered by users.

Issues and requests opened by donors will also be given priority over others.

More Repositories

1

nvim-http

An HTTP client for neovim inspired by vscode-restclient and the IntelliJ HTTP client
Python
58
star
2

micmon

A Python library and set of scripts to create labelled audio datasets from raw audio files and use them to train sound detection models.
Jupyter Notebook
39
star
3

Snort_AIPreproc

A preprocessor module for Snort that uses ML algorithms for pruning, clustering and finding correlation between alerts
C
27
star
4

leap-sdk-python3

Leap Motion SDK - Python 3 module builder
Makefile
17
star
5

fsom

A tiny C library for managing SOM (Self-Organizing Maps) neural networks
C
12
star
6

Takk

Speech recognition in Python made easy and flexible
Python
11
star
7

micstream

Stream an audio input device over HTTP as mp3
Python
10
star
8

fkmeans

A tiny library in C for managing kmeans clusterization algorithm over arbitrary data sets, both by manually specifying the number k of clusters and computing it automatically using Schwarz criterion
C
8
star
9

OhHaiMessages

A client-server mechanism for sending text messages through your Android device from your pc
Java
8
star
10

uSock

A smart high-level library for the manipulation of app (TCP/UDP) and raw sockets under Unix-like systems
C++
8
star
11

GuidaC

Il Linguaggio C - Guida pratica alla programmazione
7
star
12

imgdetect-utils

Python helpers and notebooks for image detection
Jupyter Notebook
7
star
13

theremin

Theremin synth emulator through a Leap Motion device
Python
6
star
14

gTuna

A cool chromatic nCurses tuner for guitar (and not only) for your cool Linux box
C++
6
star
15

blash

AJAX interface for a shell-oriented web browsing
JavaScript
6
star
16

ASMash

A tiny library for runtime disassembling/assembling binary/Assembly code
C
5
star
17

tcpsmash

Free, complete & cool packet sniffer for Unix-like systems
C
5
star
18

assistant-sample

Wrapper around Google's pushtotalk.py for assistant interaction without the google-assistant-library
Python
5
star
19

Armando

Connect everything to everything
Python
4
star
20

TaskerScripts

JavaScript scripts for my Android Tasker
JavaScript
4
star
21

madblog

A minimal platform for Markdown-based blogs [mirror of https://git.platypush.tech/blacklight/madblog]
Python
4
star
22

Voxifera

A little GNU/Linux software for vocal recognition and execution of arbitrary vocal commands
C
3
star
23

platypush-webext

Extension for interacting with Platypush instances from a browser
Vue
2
star
24

libCSP--

A library for managing CSP, constraint satisfaction problems in AI and more
JavaScript
2
star
25

nullBB

A cool minimal forum CMS. Just the coolest one you've ever wished
PHP
2
star
26

neuralpp

A multi-platform library for easily managing any kind of neural networks
C++
2
star
27

Jastegal

Just Another Steganography Algorithm
C++
2
star
28

nash

A tiny software that simulates the behaviour of a population in an environment in which each individual can adopt between two strategies (cooperating or being in competition)
C++
2
star
29

Grassmann

A cool library for easily managing matrices, vectors, linear systems, and other linear algebra structures
C++
2
star
30

symartists

Fetch the artist in your MPD music collection. Build a database finding similarities among them using Last.FM backend. Browse the graph of similarities through a web interface
Python
2
star
31

ultimate-guitar-mytabs

Browser script to scrape and download your saved UltimateGuitar tabs to CSV/JSON
JavaScript
1
star
32

PyOBEX

pyobex port for Python 3
Python
1
star
33

mlbook-code

Notebooks, datasets and exercises from the book "Computer Vision with Maker Tech"
Jupyter Notebook
1
star
34

NeuralPerl

A Perl module to create and manage neural networks in the easiest way. The API management is very similar to C++ Neural++ library
Perl
1
star
35

LeapMidi

Use your Leap Motion device as a MIDI music device
C++
1
star
36

vmctl

Script to automate the management of Arch Linux qemu-based VMs
Shell
1
star
37

FlexibleProfiles

Flexible profiles and rules management for Android
Java
1
star
38

mpdrand

A simple Python script which connects to an MPD/Mopidy server and starts playing a random album from your collection
Python
1
star
39

cutiepi-button-handler

Simple button handling service for the CutiePi button events
Python
1
star
40

cutiepi-lxpanel-battery

lxpanel plugin for the CutiePi battery
C
1
star
41

Hu-g-eLeap

Tune the Philips Hue lights in your house by moving your hand on your Leap Motion sensor
Python
1
star
42

WiiShake

A simple Python module that recognizes when you "shake" your Wii controller and associates a custom action when the event occurs
Python
1
star
43

CodeSterix

JavaScript
1
star