Slack Notification with BLE

This program will notify on Slack when you go out and return home.

An obniz is monitoring BLE advertising from your smartphone apps. If the obniz detect a BLE advertising, a message “In Home Now” will be sent on Slack. If it comes not to detect a BLE advertising, a message “Leaving” will be sent.


  • obniz x1
  • power supply for obniz x1
  • Slack account x1
  • smartphone app which BLE advertising available x1


At First, you get Webhook URL to send messages on Slack. Please get it from here.

Choose a channel messages will be sent and click “Add Incoming WebHooks integration.”

Replace the “WEBHOOK_URL_HERE“(line50) with displayed Webhook URL. Additionally, replace the “CHANNEL_NAME_HERE” with the channel name you chose. Remember to write a channel name with “#.”

var url = 'WEBHOOK_URL_HERE';
var data = {
  "channel": 'CHANNEL_NAME_HERE',
  "username": 'obniz-bot',
  "text": msg

Second, download a smartphone app which emits BLE advertisement such as LightBlue Explorer (→for iOS, →for Android).

Finally, connect an obniz to a power and emit BLE advertisement from your smartphone app.

If you execute the program below, you can get notification on Slack when you go out and return home.


<!DOCTYPE html>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
<script src=""></script>
<script src=""></script>
<div id="obniz-debug"></div>
<button id=startbutton >start</button>
<button id=stopbutton >stop</button>
<h1><div id=results >Leaving</div></h1>
var status = "undefined";
var scanTime = 1;
var obniz = new Obniz("OBNIZ_ID_HERE");
 obniz.onconnect = async function () {
    obniz.ble.scan.onfinish = ((results) => {
        var find = "Leaving";
        for (key in results){
          var beacon = results[key].iBeacon();
          if (beacon){
            if (beacon.uuid === "UUID_HERE"){
              find = "In home now";
     if(status === "undefined" || status !== find){
        var t = new Date();
        sendToSlack("" +  t.getHours() + ":" +( "00" + t.getMinutes()).slice(-2) + ":" + ("00"+t.getSeconds()).slice(-2) + "  " + find);
     status = find;
 function sendToSlack(msg){
    var url = 'WEBHOOK_URL_HERE';
    var data = {
      "channel": 'CHANNEL_NAME_HERE',
      "username": 'obniz-bot',
      "text": msg
	var dataJson = JSON.stringify(data);
      type: 'POST',
	  dataType: 'json',
      url: url,
      processData: false,
	  data: 'payload=' + dataJson
    }).then(function(data){}, function(XMLHttpRequest, textStatus, errorThrown){
		console.log("post to bot");