Little utility for control Awox BLE smartPlug. Test with Bluez 5 and Raspberry Pi. Also test on amd64 debian jessie.
Two scripts is provide here to deal with the plug(s): smartplugscan for find the plug address and smartplugctl to send command to it (on/off/read status). This 2 scripts use SmartPlugSmpB16 python module for manage Bluetooth Low Energy exchanges.
An older release of smartplugctl use bluez gatttool commmand line utility to do the stuff. In this script bluepy module is not require, it is available under old_scripts/.
Python module bluepy (https://github.com/IanHarvey/bluepy) is require. You can install it with :
sudo apt-get install -y python-pip libglib2.0-dev
sudo pip install bluepy
sudo apt-get install -y python-setuptools
git clone https://github.com/sourceperl/smartplugctl.git
cd smartplugctl
sudo python setup.py install
sudo smartplugscan
smartplugctl 98:7B:F3:34:78:52 on
smartplugctl 98:7B:F3:34:78:52 off
smartplugctl 98:7B:F3:34:78:52 status
smartplugctl 98:7B:F3:34:78:52 history_hour
smartplugctl 98:7B:F3:34:78:52 history_day
Turn off:
smartplugctl 98:7b:f3:34:78:52 light_enable off
Turn on:
smartplugctl 98:7b:f3:34:78:52 light_enable on
smartplugctl 98:7B:F3:34:78:52 set_time
This is required for good plug program schedule.
smartplugctl 98:7B:F3:34:78:52 program_update 0 - 13:23
Update first program for no switch on and switch off at 13h23.
smartplugctl 98:7B:F3:34:78:52 program_update 1 10:10 13:23
Update second program for switch on at 10h10 and switch off at 13h23.
smartplugctl 98:7B:F3:34:78:52 program_enable 0 on
Enable first program.
smartplugctl 98:7B:F3:34:78:52 program_enable 1 on
Disable second program.
smartplugctl 98:7B:F3:34:78:52 program_delete 0
Set plug on at 10:00 and off at 10:10 :
smartplugctl 98:7B:F3:34:78:52 set_time
smartplugctl 98:7B:F3:34:78:52 program_update 0 10:00 10:10
smartplugctl 98:7B:F3:34:78:52 program_enable 0 on
Check program list to ensure all is ok :
smartplugctl 98:7B:F3:34:78:52 program_read
smartplugctl -h
Alternatively to smartplug scripts you can directly use module from python code.
# cycle power then log plug state and power level to terminal
import pySmartPlugSmpB16
import time
# connect to the plug with bluetooth address
plug = pySmartPlugSmpB16.SmartPlug('98:7B:F3:34:78:52')
# cycle power
plug.off()
time.sleep(2.0)
plug.on()
# display state and power level
while True:
(state, power, voltage) = plug.status_request()
print('plug state = %s' % ('on' if state else 'off'))
print('plug power = %d W' % power)
print('plug voltage = %d V' % voltage)
time.sleep(2.0)