Coder Social home page Coder Social logo

notarne / sbhubrpi Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 16 KB

Acts as a hub to read and send SwitchBot meter data via mqtt to a broker.

License: GNU General Public License v2.0

Python 100.00%
autmation bluetooth-low-energy home linux meter python raspberry-pi smarthome switchbot

sbhubrpi's Introduction

SBHubRPI

Functionality:

This simple program reads the ble advertisements of the SwitchBot SmartMeter and sends them via mqtt to any mqtt broker. The program should run on a wide range of Linux-based systems as well as should be compatible to any mqtt broker and can so integrated in many home-automation softwares. I have tested it using a Raspberry Pi 3 and ioBroker`s Mqtt broker.

Supported Devices:

Only the Smart Meter by SwitchBot is supported by now, because I only can test with this device, yet.

Run:

The project needs the python packages bluepy and paho-mqtt as external dependencies. On a debian based systems you need the packages:

$ sudo apt-get install python-pip libglib2.0-dev

Then run:

$ sudo pip install bluepy paho-mqtt

Unfortunately BLE scan needs root permissions, so you can run the program by:

sudo python3 app.py [pathToConfigFile]

Configuration:

The program needs a configuration Json-file like the following in order to work.

{
  "brokerIP": "192.168.178.5",
  "brokerPort": 1883,
  "hubName": "RPI_HUB1",
  "brokerUsername": "test",
  "brokerPassword": "123456",
  "scanForSeconds": 10.0,
  "rescanTime": 60,
  "publishOnlyChanges": true,
  "devices": [
    {
      "bleMacAddress": "de:ea:db:ee:f1:23",
      "deviceDescription": "LivingRoom",
      "deviceType": "SB_Meter"
    }
  ]
}

Parameter Explanation:

  • scanForSeconds: Specifies the amount of seconds a ble active scan will be performed. This should not be to large and not to small.
  • rescanTime: Specifies the amount of seconds which will be waited between different ble active scan runs.
  • deviceDescription: Description of the device, can be set free but should be unique. Resulting values of the device will be pushed to deviceDescription/variable
  • deviceType: Must be "SB_Meter" by now, because now only the Smart Meter is supported. This might change in future.
  • publishOnlyChanges: If this parameter is set true, than only if a change is detected, the data will be published to the broker. If set to false, updates occur after every ble scan operation.

Restrictions/Hints:

  • sudo permissions are required to scan for ble devices
  • The temperature which will be sent is always in celsius!
  • If you get an python KeyError, please check the json config file. All parameters must be set!

sbhubrpi's People

Contributors

notarne avatar

Watchers

 avatar

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.