class PlugwiseOperator():

    def __init__(self, port,mac):
        stick = Stick(port)
        self.socket = Circle(mac, stick)
        self.socketActive = True
        self.socketUsage = 0

    def setStatus(self,status):
        if status == "true":
            self.socket.switch_on()
        else:
            self.socket.switch_off()
    def getStatus(self):
        if self.socketActive:
            try:
                pwUsage = round(self.socket.get_power_usage(), 2)
            except:
                print "socket not active"
                pwUsage = 0
                self.socketActive = False
        pwIsOn = "OFF"        
        if pwUsage > 0.1:
            pwIsOn = "ON"
            self.socketUsage = pwUsage
        else:
            pwUsage = self.socketUsage
        return pwIsOn
        
    def getData(self):
        if self.socketActive:
            try:
                pwUsage = round(self.socket.get_power_usage(), 2)
            except:
                print "socket not active"
                pwUsage = 0
                self.socketActive = False
        else:
            pwUsage = 0

        pwIsOn = "OFF"

        if pwUsage > 0.1:
            pwIsOn = "ON"
            self.socketUsage = pwUsage
        else:
            pwUsage = self.socketUsage
        return pwUsage
コード例 #2
0
ファイル: lamp.py プロジェクト: AdrikaMukherjee/Smart-Garden
for i in range(len(line3)):
    if line3[i] == ' SWITCH-ON-LAMP GARDEN LAMP1':
        c1.switch_on()
        cur = conn.cursor()
        #update the lamp1 status to "on" in the database
        updlamp1 = "update lamp_status set status = 'on' where id= 1"
        cur.execute(updlamp1)

    elif line3[i] == ' SWITCH-ON-LAMP GARDEN LAMP2':
        c2.switch_on()
        cur = conn.cursor()
        #update the lamp2 status to "on" in the database
        updlamp2 = "update lamp_status set status = 'on' where id= 2"
        cur.execute(updlamp2)

    elif line3[i] == ' SWITCH-OFF-LAMP GARDEN LAMP1':
        print('OFF LAMP')
        c1.switch_off()
        cur = conn.cursor()
        #update the lamp1 status to "off" in the database
        updlamp3 = "update lamp_status set status = 'off' where id= 1"
        cur.execute(updlamp3)

    elif line3[i] == ' SWITCH-OFF-LAMP GARDEN LAMP2':
        c2.switch_off()
        cur = conn.cursor()
        #update the lamp2 status to "off" in the database
        updlamp4 = "update lamp_status set status = 'off' where id= 2"
        cur.execute(updlamp4)
コード例 #3
0
from plugwise import Stick
from plugwise import Circle

# MAC ID for both the Circles
mac1 = "000D6F0004B1E1D6"
mac2 = "000D6F0003562BE1"

# Plugwise Stick port
plugwise_stick = Stick(port="/dev/ttyUSB0")

# Binding each circle to the stick
plugwise_Circle_1 = Circle(mac1, plugwise_stick) # for heater
plugwise_Circle_2 = Circle(mac2, plugwise_stick) # lamp

# turning off the devices conected to circles by default
plugwise_Circle_1.switch_off()
plugwise_Circle_2.switch_off()

# Configure thingsboard host and Access_token
THINGSBOARD_HOST = '141.58.216.26'
ACCESS_TOKEN = 'DHT-48Data'

# Home Sensor Data captured and uploaded interval in seconds.
INTERVAL=10

# Setting the Time Stamp for initial reading, later values are appended by INTERVAL
next_reading = time.time()

# Initialize the MQTT client
client = mqtt.Client()