Scanning near RuuviTag beacons with python on Raspberry Pi3

I am trying to implement program with python on Raspberry Pi 3. Purpose is to scan near RuuviTag beacons automatically without hardcoding MAC addresses in code. I have studied and have been able to get data from beacon when MAC address is hardcoded.

Currently I’m wondering what would be best way to scan near beacons automatically and use their addresses. I have noticed that with command ruuvitag -l I can get MAC address and data of beacon. It seems I can’t use commands like ruuvitag -l | awk … or grep to get lines with json and mac address. Any ideas how to proceed with this? My purpose is to create app that automatically saves data from nearest beacons to text file.

import ruuvitag_sensor
from ruuvitag_sensor.log import log
from ruuvitag_sensor.ruuvi import RuuviTagSensor
from ruuvitag_sensor.ruuvitag import RuuviTag


datas = RuuviTagSensor.get_data_for_sensors(bt_device='')

for key, value in datas.items():
    # Beacon mac address
    sensor = RuuviTag(key)


key is the mac address

You may also try aioblescan

You can install it from pip, but it requires python >=3.5 (The github version requires >=3.4)