Skip to content

Instantly share code, notes, and snippets.

@a0726h77
Last active September 29, 2018 15:46
Show Gist options
  • Save a0726h77/720039c1b7851ce53ff63fa1ee35025d to your computer and use it in GitHub Desktop.
Save a0726h77/720039c1b7851ce53ff63fa1ee35025d to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
'''
open-homeautomation/miflora
https://github.com/open-homeautomation/miflora
'''
from btlewrap import available_backends, BluepyBackend, GatttoolBackend, PygattBackend
from miflora.miflora_poller import MiFloraPoller, \
MI_CONDUCTIVITY, MI_MOISTURE, MI_LIGHT, MI_TEMPERATURE, MI_BATTERY
from miflora import miflora_scanner
if __name__ == '__main__':
backend = BluepyBackend
print('Scanning for 10 seconds...')
devices = miflora_scanner.scan(backend, 10)
print('Found {} devices:'.format(len(devices)))
for device in devices:
print(' {}'.format(device))
poller = MiFloraPoller(device, backend)
print("Getting data from Mi Flora")
print("FW: {}".format(poller.firmware_version()))
print("Name: {}".format(poller.name()))
print("Temperature: {}".format(poller.parameter_value(MI_TEMPERATURE)))
print("Moisture: {}".format(poller.parameter_value(MI_MOISTURE)))
print("Light: {}".format(poller.parameter_value(MI_LIGHT)))
print("Conductivity: {}".format(poller.parameter_value(MI_CONDUCTIVITY)))
print("Battery: {}".format(poller.parameter_value(MI_BATTERY)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment