Code Monkey home page Code Monkey logo

switchbot-meter-api's Introduction

SwitchBot Meter Readings

Python script to read temperature, humidity and battery from a Switchbot Meter device, and then make the data accessible via a API on your local network. The script has been tested on a Raspberry Pi Zero W using Raspberry Pi OS.

You will need:

  1. Python3
  2. SwitchBot Thermometer
  3. BluePy
  4. Flask
  5. TinyDb

Getting Started

Use Cases

Install

  1. Install Python3 and Pip3: sudo apt-get install python3 python3-pip
  2. Install BluePy (Bluetooth Framework): sudo pip3 install bluepy
  3. Install Flask (API Framework): sudo pip3 install -U Flask
  4. Install TinyDb (Storage): sudo pip3 install tinydb
  5. Run the script: sudo python3 meters.py

SwitchBot Configuration

To locate your SwitchBot Meter by Bluetooth in the local area, the MAC address and name of the meter reading is required. You can find this information within the SwitchBot mobile application. Once found, set the following variables with the values from your device.

# SwitchBot Meter Configuration
METER_ROOMS = ['Bedroom']
METER_MACS = ['e8:fe:50:d1:75:dd']

API Configuration

By default, the API will be accessible via the network port 5000. To change this, along with the hostname of the API server, set the following configuration with your values.

# API Configuration
API_HOST="localhost"
API_PORT=5000

API Methods

'/meters' - All Meter Devices

Request

GET /meters HTTP/1.1
Host: 192.168.1.233:5000

Response

[
    {
        "time": "2020-08-31 13:38:24",
        "room": "Bedroom",
        "temperature": "22.5",
        "humidity": "65",
        "battery": "100"
    }
]

'/meters/room' - Get Meter Device by Name

Request

GET /meters/Bedroom HTTP/1.1
Host: 192.168.1.233:5000

Response

{
    "time": "2020-08-31 23:40:03",
    "room": "Bedroom",
    "temperature": "24.4",
    "humidity": "65",
    "battery": "100"
}

switchbot-meter-api's People

Contributors

lukearran avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

switchbot-meter-api's Issues

Network freeze on getting values from meters

Hi,

Thanks for providing this script which does exavtly what i want. I only struggle with the issue, that my normal network connection gets lost each time the api pulls values from my meters. Network is away for about 5sec. Than everything works again. Each time for me 30 sec this happens.

Any idea if this is a script problem or some misconfiguration on my side?

Thanks for your help

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.