Presence detection with low cost BLE devices and Raspberry Pi/Zero W

you can test it there from master :

Don’t hesitate to give feedback.

Note also that last ESP32 env code is too big, take care of taking the revision pointed into the wiki.The BLE library to use should be taken from the repo here

How can I get the MAC address of BLE devices? I tried a various BLE scanners but don’t know how to find the MAC. For example if I purchase some TILE devices how can I get their MAC address?

I plan to use this device to track my cars so need to get the mac address from them also.
https://www.amazon.com/gp/product/B019G0VVZC/ref=oh_aui_detailpage_o01_s00?ie=UTF8&psc=1

How do I see the message sent to the broker?
I am starting with the default embedded mqtt server so my config is simply
mqtt:
and I have configured room assistant with my HA server, port 8080, userid:homeassistant and password as found here MQTT - Home Assistant

Does the default mqtt use mosquitto? I don’t have a mosquitto_sub command on my hassbian install. Or does this suggestion assume you are using mosquitto for your mqtt server on it’s own? If so how can I see if my system is setup correctly with the embedded mqtt server?

@smart use the excellent MQTTFx ( http://mqttfx.jensd.de/ ) to monitor your MQTT server.
Or if you prefer a Chrome extension : https://chrome.google.com/webstore/detail/mqttlens/olchecfhjakpabcillcpffnlmmlnlbgj

@sfgreenwood I bought a few iTags and three of them work fine, but one of them turns itself off after five minutes. Have you experienced this? I’ve seen some discussion online that this specific iTag is a later hardware revision and if it’s not paired up with a device it turns itself off? Obviously rendering it useless for what we want to do!

I’ve made some headway on getting BLE beacon tracking working on the ESP32. If anyone is interested in adding some more detection nodes to their room presence system, I’d love you to check it out.

The discussion thread is here, and you can get the code from the GitHub repo. Building and uploading is done via PlatformIO.

@smart you can use any number of beacon apps on your phone to get the ID of your beacons. I use NRF Connect on my Android phone. You can also use the app to configure the beacon to modify the default settings. For example, I changed the TX power setting on my key fob so it would report accurate distances.

I think I had one that did that and one that didn’t. I haven’t done much with them beyond that as Zanzito and Find provided better solutions (although still incomplete).

Thanks, I have had room assistant up and running for a while. I use the iBeacon tokens I listed above in my car to track my home arrival. Works perfect!

Is it possible to set up Room-Assistant to scan for the bluetooth on my phone? I always have it with me, and would prefer that over carrying around a beacon with me. Hard to find a place for it while walking around in my underwear lol, but I always have my phone close by.

I tried to just use my Android phone to detect beacons placed in rooms, but there doesn’t seem to be an Android app that works well and reliably enough to detect the beacon and communicate to HA via MQTT or http api.

@PlayedIn Because of the way phones will randomize their bluetooth mac addresses when advertising to any unpaired device, it’s a challenge to reliably detect the phone correctly.

However, you can emulate a beacon on your phone using an app. I’ve had the best success with Beacon Scope, but there are other beacon broadcasting apps available (such as Beacon Simulator). You can configure your phone to broadcast as an iBeacon, and then configure the beacon uuid on the phone and in your configuration.yaml.

I have this working but for some reason I cannot get it operating as a service. My steps are:

sudo nano /etc/systemd/system/room-assistant.service

[Unit]
Description=Room Assistant service

[Service]
ExecStart=/usr/bin/npm start
WorkingDirectory=/home/pi/room-assistant
Restart=always
RestartSec=10
User=pi

[Install]
WantedBy=multi-user.target

And then:

sudo systemctl enable room-assistant.service
sudo systemctl start room-assistant.service

The result I get is:

**pi@raspberrypi** : **~/room-assistant $** systemctl status room-assistant.service

● room-assistant.service - Room Assistant service

Loaded: loaded (/etc/systemd/system/room-assistant.service; enabled; vendor preset: enabled)

Active: activating (auto-restart) (Result: exit-code) since Fri 2018-11-23 11:32:04 AEDT; 6s ago

Process: 768 ExecStart=/usr/bin/npm start **(code=exited, status=203/EXEC)**

Main PID: 768 (code=exited, status=203/EXEC)

Nov 23 11:32:04 raspberrypi systemd[1]: **room-assistant.service: Failed with result 'exit-code'.**

Any ideas what the problem is?

Got this working.
Had to change to ExecStart=/usr/local/bin/npm start

[Unit]
Description=Room Assistant service

[Service]
ExecStart=/usr/local/bin/npm start
WorkingDirectory=/home/pi/room-assistant
Restart=always
RestartSec=10
User=pi

[Install]
WantedBy=multi-user.target

You say you “probably wouldn’t use it to switch lights on when you enter a room”… why not? Seems like the most logical use for this. What do you use it for?

In my experience it wouldn’t respond quickly enough - you could probably bring it down to 10-15 milliseconds but I don’t know how reliable that would be and you could end up standing in the dark :slight_smile:

I’m getting an error at step 13. Any idea what this could be?

docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.

EDIT: The issue was that the current version of Docker (18.09.0) was running an error and you needed to go back. See the comment here: https://github.com/moby/moby/issues/38175#issuecomment-439422785

I am having issues with getting the json file to work correctly on room assistant v2.4.0 any ideas?

It’s easier to use YAML with the new version in my opinion. Can you show your json file?

What size SD card is recommended for running room assistant on the Pi Zero W?

I don’t think there’s a recommended size, room-assistant itself uses almost no space.

I have 8 Gb cards in all my Pi Zero Ws.

Nearly everything that you use should work. But try to get something smaller than 32GB for a reasonable price… At Amazon the 16GB is more expensive than the 32GB…
Use what you get for a good price, I’m quite sure there is nothing on the market anymore, that would be to small. :slight_smile:

Hi I’m wondering if anyone can help, ive got a piZero running room assistant. Every now and again the pi crashes and I need to reboot. Ive found I can use a shell integration to send a reboot command and also also creates a switch in home assistant. what I need help with is changing this switch to a press button. this is the code ive used.

shell:
  sensors:
    - name: Kitchen Wifi Strength
      command: 'iwconfig wlan0 | grep -i quality'
      regex: 'Signal level=(-?[0-9]+) dBm'
      cron: '* * * * *'
      icon: mdi:wifi
      unitOfMeasurement: dBm
      deviceClass: signal_strength
  switches:
    - name: Onboard LED
      onCommand: 'echo mmc0 | sudo tee /sys/class/leds/led0/trigger'
      offCommand: 'echo none | sudo tee /sys/class/leds/led0/trigger && echo 1 | sudo tee /sys/class/leds/led0/brightness'
    - name: Reboot
      onCommand: 'echo none | sudo reboot'
      offCommand: 'echo none'