Git Product home page Git Product logo

RoButton

A REST API for Switchbots that allows to control actions, settings and timers.

Among other possibilities, setting up a webserver on a RaspberryPi in combination with an app capable of sending custom HTTP requests (e.g. HTTP-Shortcuts for Android), allows to control SwitchBots by phone outside of the BLE range (without a Hub).

The REST API uses the Switchbot Python API for BLE communication.

Getting Started

Prerequisites

The setup is tested on a RaspberryPi 3 with the Raspbian Buster OS in combination with SwitchBots running firmware 4.4 and 4.5

Installing

Install pipenv if you don't have it and then install the environment from the Pipfile (from the root directory):

pip install pipenv
pipenv install

Afterwards, Flask can be started with the following command:

pipenv run python robutton/main.py

Usage

The REST API uses the Python API to communicate with the SwitchBots.

The following endpoints are available:

Name Method Endpoint
Login (use password to receive token) POST /switchbot/api/v1/login
Perform Action (press, turn on, turn off) POST /switchbot/api/v1/bot/{bot_id}/actions
Find all SwitchBots GET /switchbot/api/v1/bots
Get Settings GET /switchbot/api/v1/bot/{bot_id}
Update Settings PATCH /switchbot/api/v1/bot/{bot_id}
Get all timers GET /switchbot/api/v1/bot/{bot_id}/timers
Add a timer POST /switchbot/api/v1/bot/{bot_id}/timers
Update multiple timers at once PATCH /switchbot/api/v1/bot/{bot_id}/timers
Update a timer PATCH /switchbot/api/v1/bot/{bot_id}/timer/{timer_id}
Delete Timer DELETE /switchbot/api/v1/bot/{bot_id}/timer/{timer_id}

To get more details about how to use the REST API, start the Flask app with: pipenv run python src/main.py and then use the endpoint /doc/openapi.json to obtain a OPEN API specification.

Additionally, I provide a Postman collection in the /postman folder which can be imported to try the API. (Start with the Login request to obtain a bearer token which is used for all other endpoints)

Deployment

For the deployment of the Switchbot REST API it is recommended to run the Flask application in combination with Nginx and Gunicorn.

Authors

robutton's Projects

robutton icon robutton

REST API to control multiple Switchbots

switchbotpy icon switchbotpy

A Python API for SwitchBots that allows to control actions, settings and timers (also password protected)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.