February 2022
Intermediate to advanced
182 pages
4h 25m
English
Now that you can power on Hue lights and plugs with a single line of Python code, let’s combine this newfound capability with a temperature sensor. When the temperature meets or exceeds 27 degrees Celsius (roughly 80 degrees Fahrenheit), turn on the fan connected to the smart plug. When the temperature drops below 27 degrees, turn the fan off.
Create a file called temperaturetest.py and write code to display the temperature reading from the SensorHub’s temperature probe once every second. The SensorHub initialization code was obtained from DockerPi’s wiki:[42]
| ① | import smbus |
| | import time |
| | |
| ② | DEVICE_BUS = 1 |
| | DEVICE_ADDR = 0x17 |
| | |
| | TEMP_REG = 0x01 |
| | LIGHT_REG_L = 0x02 |
| | LIGHT_REG_H = 0x03 ... |
Read now
Unlock full access