WORK IN PROGRESS
-
Install it via PyPI:
pip install lywsd02
Note: use
pip3
instead ofpip
on Raspbian and other systems that default to Python 2. -
Or directly from the source code:
git clone https://github.com/h4/lywsd02.git python lywsd02/setup.py install
Note: use
python3
if your system defaults to Python 2.
Instantiate client with Lywsd02 mac address
from lywsd02 import Lywsd02Client
mac = '3F:59:C8:80:70:BE'
client = Lywsd02Client(mac)
Read data
print(client.temperature)
print(client.humidity)
client.temperature
– Sensor's temperature data in Celsius degrees. Updates with timeout (See below)client.humidity
– Sensor's humidity data in percent. Updates with timeoutclient.units
– Current temperature units displayed on screen. Returns'C'
for Celsius and'F'
for Fahrenheitclient.time
– Current time and timezone offset. Returns as tuple ofdatetime.datetime
andint
client.battery
– Sensor's battery level in percent (0 to 100).
client.units = 'C'
– Changes temperature units displayed on screenclient.time = datetime.datetime.now()
- Changes time using local timezone or tz_offset (if set)client.tz_offset = 1
- Sets timezone offset in hours that will be used when setting time
Client may be initialized with additional kwargs.
notification_timeout
– timeout to wait fortemperature
andhumidity
requests. If sensor responds slower then timeout data would not updated. Default value is 5 second.data_request_timeout
–temperature
andhumidity
are cached for this period. Default value is 15 second.
from lywsd02 import Lywsd02Client
mac = '3F:59:C8:80:70:BE'
client = Lywsd02Client(mac, notification_timeout=1.0, data_request_timeout=30.0)