Fail to run pygatt via Shell Command

I am trying to retro-fit a bluetooth command set to a bluetooth device
My approach was to set several shell commands as python_script doesn’t allow python imports

Ran the BLE scan

 device_tracker:
   - platform: bluetooth_tracker
     interval_seconds: 3600
     consider_home: 150
     track_new_devices: yes

Got the device mac address in known_devices.yaml

ppp_p18240406:
  hide_if_away: false
  icon:
  mac: BT_D4:CA:6E:72:8D:31
  name: PPP-P18240406
  picture:
  track: true

then wrote this python file (ppp.py) directly to my config folder

import sys
import pygatt

adapter = pygatt.GATTToolBackend()

# Get command line arguments
mac_addr = str(sys.argv[1])
command = int(sys.argv[2])

try:
    # connect to device
    adapter.start()
    device = adapter.connect(mac_addr)

    if command == 1:
        # Restart Device
        device.char_write_handle('2456E1B9-26E2-8F83-E744-F34F01E9D703', '36375b322c2231222c22446174615472616e73666572222c7b2276656e646f724964223a224556426f78222c226d6573736167654964223a22657662425453686f77227d5d')

finally:
    adapter.stop()

then add the following to my config.yaml

shell_command:
  reset: 'python /config/python_scripts/ppp.py D4:CA:6E:72:8D:31'

Problem is that I get error when try to run the service. Went to test on the ssh terminal,
got the following error:
ModuleNotFoundError: No module named 'pygatt'

I expect that pygatt is already existing in my hassio! Thanks in advance for helping me with this issue

1 Like