Sumit Kumar
Published © GPL3+

Tuya Link SDK IoT Smart Environment Sensing and Humidifier

Within less than 15 minutes build smart Raspberry Pi based Smart Home Environment Sensing and Humidification device

BeginnerFull instructions provided2 hours1,096
Tuya Link SDK IoT Smart Environment Sensing and Humidifier

Things used in this project

Hardware components

Raspberry Pi 3 Model B+
Raspberry Pi 3 Model B+
×1
SparkFun Environmental Combo Breakout - CCS811/BME280 (Qwiic)
SparkFun Environmental Combo Breakout - CCS811/BME280 (Qwiic)
×1
Seeed Studio Water Atomization Module
×1

Software apps and online services

Tuya IoT Platform

Story

Read more

Schematics

Circuit

Code

quick.py

Python
from __future__ import print_function, division
import qwiic
import time
import sys
import time
import coloredlogs
from tuyalinksdk.client import TuyaClient
from tuyalinksdk.console_qrcode import qrcode_generate
import RPi.GPIO as GPIO

coloredlogs.install(level='DEBUG')

client = TuyaClient(productid='aat2td94fptlzhoh', uuid='tuyad1f130fd2d21fd1c', authkey='m7XFiWrTSktjBrMHSXl9teoF98xNeRwv')

bme = qwiic.QwiicBme280()
ccs = qwiic.QwiicCcs811()

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
humidifier= 26
GPIO.setup(humidifier,GPIO.OUT)

bme.begin()
ccs.begin()

def on_connected():
    print('Connected.')

def on_qrcode(url):
    qrcode_generate(url)

def on_reset(data):
    print('Reset:', data)

def on_dps(dps):
    print('DataPoints:', dps)
    if(dps == {'102':True}):
    	GPIO.output(humidifier, GPIO.HIGH)
    elif(dps=={'102':False}):
    	GPIO.output(humidifier, GPIO.LOW)
    # send environmental sensor data
    dps['103']= int(bme.get_temperature_celsius())
    dps['104']= int(bme.read_humidity())
    ccs.read_algorithm_results()
    dps['101']= int(ccs.get_co2())
    
    client.push_dps(dps)


client.on_connected = on_connected
client.on_qrcode = on_qrcode
client.on_reset = on_reset
client.on_dps = on_dps
client.connect()
client.loop_start()

while True:
    pressure = bme.get_reference_pressure() #in Pa
    altitudem = bme.get_altitude_meters()
    altitudef = bme.get_altitude_feet()
    humidity = bme.read_humidity()
    tempc = bme.get_temperature_celsius()
    tempf = bme.get_temperature_fahrenheit()
    dewc = bme.get_dewpoint_celsius()
    dewf = bme.get_dewpoint_fahrenheit()


    ccs.read_algorithm_results() #updates the TVOC and CO2 values
    tvoc = ccs.get_tvoc()
    co2 = ccs.get_co2()
#     print (time.strftime("%a %b %d %Y %I:%M:%S%p", time.localtime())) #12-hour time
# 
#     print ("BME Temperature %.1f C" %tempc)
#     print ("Humidity %.1f" %humidity)
# 
#     print ("Pressure %.2f Pa" %pressure)
#     print ("Altitude %.2f ft" %altitudef)
#     print ("Altitude % 2f mt" %altitudem)
# 
#     print ("TVOC %.2f" %tvoc)
#     print ("CO2 %.2f" %co2)
    
    time.sleep(0.5)

Credits

Sumit Kumar

Sumit Kumar

32 projects β€’ 97 followers
19 y/o. My daily routine involves dealing with electronics, code, distributed storage and cloud APIs.

Comments