# Import time (for delay) library (for SmartHome api) and GPIO (for raspberry pi gpio)
from library import SmartHomeApi
import RPi.GPIO as GPIO
import time

# 7  -> RED
# 11 -> GREEN
# 12 -> BLUE

# Create the client with pre-existing credentials
api = SmartHomeApi("http://localhost:5000/api/0.1", id=10, api_key="api_eMxSb7n6G10Svojn3PlU5P6srMaDrFxmKAnWvnW6UyzmBG")

GPIO.setmode(GPIO.BOARD)
GPIO.setup(7, GPIO.OUT)
GPIO.setup(11, GPIO.OUT)
GPIO.setup(12, GPIO.OUT)

last_status = "UNKNOWN"

def doUpdate(status):
    if status == "RED":
        GPIO.output(7, GPIO.HIGH)
        GPIO.output(11, GPIO.LOW)
        GPIO.output(12, GPIO.LOW)
    elif status == "GREEN":
        GPIO.output(7, GPIO.LOW)
        GPIO.output(11, GPIO.HIGH)
        GPIO.output(12, GPIO.LOW)
    elif status == "BLUE":
        GPIO.output(7, GPIO.LOW)
        GPIO.output(12, GPIO.HIGH)
        GPIO.output(11, GPIO.LOW)
    else:
        GPIO.output(7, GPIO.LOW)
        GPIO.output(11, GPIO.LOW)
        GPIO.output(12, GPIO.LOW)
    
    print("updating! (status: {})".format(status))
    
while True:
    status = api.GetDeviceStatus()
    if last_status != status:
        # Changed!
        doUpdate(status)
        last_status = status
    time.sleep(1)


@@ -156,33 +156,79 @@
 %0A%0A# 
-7  -%3E RED%0A# 11 -%3E GREEN%0A#
+Board Pin 7  -%3E RED led pin%0A# Board Pin 11 -%3E GREEN led pin%0A# Board Pin
  12 
@@ -234,16 +234,25 @@
  -%3E BLUE
+ led pin.
 %0A%0A# Crea
@@ -421,132 +421,374 @@
 %22)%0A%0A
-GPIO.setmode(GPIO.BOARD)%0AGPIO.setup(7, GPIO.OUT)%0AGPIO.setup(11, GPIO.OUT)%0AGPIO.setup(12, GPIO.OUT)%0A%0Alast_status = %22UNKNOWN%22%0A
+# Put the GPIO into board mode%0AGPIO.setmode(GPIO.BOARD)%0A# Set the Red, Green and Blue pins to output mode%0AGPIO.setup(7, GPIO.OUT)%0AGPIO.setup(11, GPIO.OUT)%0AGPIO.setup(12, GPIO.OUT)%0A%0A# Create the last status and set it to UNKNOWN (so that it should trigger the update loop)%0Alast_status = %22UNKNOWN%22%0A%0A# Update function (checks if it's RED, GREEN, BLUE or something else)
 %0Adef
@@ -1363,16 +1363,28 @@
 ))%0A    %0A
+# Main loop%0A
 while Tr
@@ -1395,141 +1395,314 @@
     
-status = api.GetDeviceStatus()%0A    if last_status != status:%0A        # Changed!%0A        doUpdate(status)%0A        last_status = status
+# Query the API for the status%0A    status = api.GetDeviceStatus()%0A    # Check if the status has changed%0A    if last_status != status:%0A        # Call the update function, passing in the new status%0A        doUpdate(status)%0A        last_status = status%0A    # Wait for 1 second in order to not overload the API
 %0A   

Update demo1.py