Control a Smart Bulb


Objective

Control a smart light bulb and change its color using Bixby Home Studio.

Overview

Bixby Home Studio (BHS) provides a simple and optimized way for accessing and controlling devices connected to your SmartThings account. You can quickly create complex diagrams and condition-based flows with BHS's user-friendly graphical user interface (GUI). Any device compatible with SmartThings can be adjusted, controlled, and updated through Bixby Home Studio.

For more information, visit Getting Started with Bixby Home Studio.

Set up your environment

You will need the following:

  • Samsung and SmartThings account (same email address)

  • smart RGB light bulb added to SmartThings account

  • virtual switch from SmartThings Labs (if a smart RGB light bulb is not available)

    a. Go to SmartThings app.

    b. In the Menu, select Labs.

    c. Choose Virtual Switch and click + to add a virtual switch.

    d. Enter the name of virtual switch, location, and room.

Start your project

  1. Go to bhs.bixbydevelopers.com and sign in using your Samsung account.
  2. Create a New Project.

  1. Select your SmartThings Location and smart RGB light bulb or virtual switch for the device.
  2. Click Create metadata from scratch. Then, click Next.

  1. Choose powerSwitch under Bixby Voice Category.
  2. Select the powerSwitch-turnOff and powerSwitch-turnOn voice intents.
  3. Click Next.

  1. Input a Project Name and click Done.

Use a sample graph to switch on the bulb

Sample Graphs are various example action flows that you can explore to learn more about the different voice intents, nodes, and SmartThings capabilities. You can use these sample graphs as starter points for your own devices.

Each sample graph generically handles specific capabilities covered under various user utterances through the different voice intents. For example, the Turn On Device sample graph works for any device. It covers a variety of user utterances such as "Turn on air conditioner.", "Turn on fan.", "Turn on speaker.”, and so on.

Follow the steps below to use the Turn On Device sample graph to switch on the device:

  1. Go to Voice Intents > powerSwitch-turnOn > Graph.

  1. Click the Sample Graphs icon on the left sidebar menu to show all the available sample graphs.

  1. Scroll down to see the Turn On Device sample graph or find it using the search bar.
  2. Drag and drop the sample graph into your powerSwitch-turnOn graph editor.

  1. Click Try It to turn on your light bulb.

Turn off the light bulb and add an alternative response

The Turn On Device sample graph functions to switch on the device when the Start node triggers the Command node. This graph can be modified to reverse its function, to do that:

  1. Copy the nodes from the powerSwitch-turnOn graph to the powerSwitch-turnOff graph editor.

  1. Click the Command node to open the Node Configuration pane and change the command from on to off.

  1. Right-click on the Command node and change its comment to Turn off device.

  1. Click Try It to turn off the device.

  1. After the command is performed, the response is either Success or Execution Failed. To make the light bulb more responsive, design the graph to provide different responses depending on whether the light bulb is already off or currently on.

    a. Click the Raw button and delete the existing code in the Raw Graph.

    b. Copy and paste the following JSON into it and click Add.

    [{"nodeId":"5b648da1-a2c3-4912-baff-a559b968070e","nodeVer":"1.0","nodeType":"capabilityAttribute","isStateful":true,"group":null,"inputPorts":{"device":{"nodes":[],"portInfo":null}},"triggerPorts":{"success":{"nodes":["ccf1cbb8-c99b-439f-8246-bc9e7b7abfbf"],"portInfo":null},"failure":{"nodes":[],"portInfo":null}},"valuePorts":{},"triggerInPorts":{},"configurations":{"attribute":{"dataType":"datatype.schema.AFCapabilityAttribute","dataValue":{"component":"main","capability":"switch","attribute":"switch","property":{"name":"value","dataType":"datatype.primitive.AFString"}}},"required":{"dataType":"datatype.primitive.AFBoolean","dataValue":true}},"styles":{"x":415,"y":360}},{"nodeId":"ccf1cbb8-c99b-439f-8246-bc9e7b7abfbf","nodeVer":"1.0","nodeType":"equalComparison","isStateful":true,"group":null,"inputPorts":{"leftValue":{"nodes":["5b648da1-a2c3-4912-baff-a559b968070e"],"portInfo":null},"rightValue":{"nodes":["8d9bf8ec-7cb1-4ffe-b4c0-b0424d394027"],"portInfo":null}},"triggerPorts":{"true":{"nodes":["593250c4-9c19-4155-8f90-1318f9484aab"],"portInfo":null},"false":{"nodes":["a9c4d152-eb0d-45d2-a2bd-20217de6fee6"],"portInfo":null}},"valuePorts":{},"triggerInPorts":{},"configurations":{"operator":{"dataType":"datatype.operator.EqualComparisonOperator","dataValue":"equalTo"}},"styles":{"x":585,"y":332}},{"nodeId":"8d9bf8ec-7cb1-4ffe-b4c0-b0424d394027","nodeVer":"1.0","nodeType":"constant","isStateful":true,"group":null,"inputPorts":{},"triggerPorts":{},"valuePorts":{},"triggerInPorts":{},"configurations":{"value":{"dataType":"datatype.primitive.AFString","dataValue":"on"}},"styles":{"x":415,"y":500}},{"nodeId":"a9c4d152-eb0d-45d2-a2bd-20217de6fee6","nodeVer":"1.0","nodeType":"responseFeatureAlreadySet","isStateful":true,"group":null,"inputPorts":{},"triggerPorts":{},"valuePorts":{},"triggerInPorts":{},"configurations":{},"styles":{"x":635,"y":480}}]
    

    c. Four nodes were added to the graph.

    • An Attribute node that receives and passes an on or off value;
    • A Constant node with on as its value;
    • An Equal Comparison node that compares if the Attribute value is equal to the Constant value; and
    • A Response: Already set node

    d. Rewire the graph to make it work properly by clicking the line coming from the Start node and pressing the Delete key.

    e. Create a new line from the Start node and connect it to the Attribute node's trigger port.

    f. Connect the Equal Comparison node's true port to the Command node's trigger port.

    g. Click the Align button a couple of times to automatically organize the graph.

    h. Then, click Try It while the device is already off or already on, to observe the different responses.

Change the light bulb's color based on time

The Command node has two capabilities that can adjust the color of light bulb, such as ColorControl and ColorTemperature.

In this step, use these Command node capabilities together with the Get Current DateTime node and Get DateTime Attributes node to set the light bulb's color to red or warm, if the current date time is 8:00 PM or later. Otherwise, the light bulb's color remains blue.

  1. Add the following JSON into the powerSwitch-turnOn graph.
[{"nodeId":"a31659e2-68fc-42b6-8076-01c2cb9fec23","nodeVer":"1.0","nodeType":"getCurrentDateTime","isStateful":true,"group":null,"inputPorts":{"__zoneid":{"nodes":[],"portInfo":null}},"triggerPorts":{"main":{"nodes":["ea58c225-7d40-45b9-85d6-d8d941de9b2e"],"portInfo":null}},"valuePorts":{},"triggerInPorts":{},"configurations":{},"styles":{"x":715,"y":280}},{"nodeId":"ea58c225-7d40-45b9-85d6-d8d941de9b2e","nodeVer":"1.0","nodeType":"getDateTimeAttributes","isStateful":true,"group":null,"inputPorts":{"input":{"nodes":["a31659e2-68fc-42b6-8076-01c2cb9fec23"],"portInfo":null}},"triggerPorts":{"main":{"nodes":["880416f6-d288-4b97-b763-2abd46bf2737"],"portInfo":null}},"valuePorts":{"seconds":{"name":"seconds"},"month":{"name":"month"},"hour":{"name":"hour"},"year":{"name":"year"},"minutes":{"name":"minutes"},"timestampInSeconds":{"name":"timestampInSeconds"},"day":{"name":"day"}},"triggerInPorts":{},"configurations":{},"styles":{"x":815,"y":280}},{"nodeId":"880416f6-d288-4b97-b763-2abd46bf2737","nodeVer":"1.0","nodeType":"comparableComparison","isStateful":true,"group":null,"inputPorts":{"leftValue":{"nodes":["gr://node/ea58c225-7d40-45b9-85d6-d8d941de9b2e/value/hour"],"portInfo":null},"rightValue":{"nodes":["606796bc-d8ea-4421-942d-91544271615d"],"portInfo":null}},"triggerPorts":{"true":{"nodes":["b2ba65ab-5e3e-4615-8d3a-79015a03d7bc"],"portInfo":null},"false":{"nodes":[],"portInfo":null}},"valuePorts":{},"triggerInPorts":{},"configurations":{"operator":{"dataType":"datatype.operator.ComparableComparisonOperator","dataValue":"greaterThanOrEqualTo"}},"styles":{"x":975,"y":320}},{"nodeId":"606796bc-d8ea-4421-942d-91544271615d","nodeVer":"1.0","nodeType":"constant","isStateful":true,"group":null,"inputPorts":{},"triggerPorts":{},"valuePorts":{},"triggerInPorts":{},"configurations":{"value":{"dataType":"datatype.primitive.AFInteger","dataValue":20}},"styles":{"x":815,"y":420}},{"nodeId":"2b22b1a1-b9cb-4881-a861-3bf74ccd7847","nodeVer":"1.0","nodeType":"capabilityCommand","isStateful":true,"group":null,"inputPorts":{"device":{"nodes":[],"portInfo":null},"1:color":{"nodes":["2389baa9-db45-4eb3-a40c-1166bf1e620f"],"portInfo":{"dataTypes":["undefined"],"minItems":1,"maxItems":1,"isCustomPort":true}}},"triggerPorts":{"success":{"nodes":["a31659e2-68fc-42b6-8076-01c2cb9fec23"],"portInfo":null},"failure":{"nodes":[],"portInfo":null}},"valuePorts":{},"triggerInPorts":{},"configurations":{"commands":{"dataType":"datatype.util.AFList","dataValue":[{"dataType":"datatype.schema.AFCapabilityCommand","dataValue":{"component":"main","capability":"colorControl","command":"setColor","arguments":[{"dataType":"datatype.schema.AFCommandArgument","dataValue":{"name":"color","optional":false,"dataType":"datatype.primitive.AFJsonObject"}}]}}]}},"styles":{"x":590,"y":274}},{"nodeId":"2389baa9-db45-4eb3-a40c-1166bf1e620f","nodeVer":"1.0","nodeType":"constant","isStateful":true,"group":null,"inputPorts":{},"triggerPorts":{},"valuePorts":{},"triggerInPorts":{},"configurations":{"value":{"dataType":"datatype.primitive.AFJsonObject","dataValue":{"hue":55,"saturation":55}}},"styles":{"x":675,"y":440}},{"nodeId":"b2ba65ab-5e3e-4615-8d3a-79015a03d7bc","nodeVer":"1.0","nodeType":"capabilityCommand","isStateful":true,"group":null,"inputPorts":{"device":{"nodes":[],"portInfo":null},"1:temperature":{"nodes":["4d02fcda-df99-4c75-8b0a-73bb67933acd"],"portInfo":{"dataTypes":["undefined"],"minItems":1,"maxItems":1,"isCustomPort":true}}},"triggerPorts":{"success":{"nodes":[],"portInfo":null},"failure":{"nodes":[],"portInfo":null}},"valuePorts":{},"triggerInPorts":{},"configurations":{"commands":{"dataType":"datatype.util.AFList","dataValue":[{"dataType":"datatype.schema.AFCapabilityCommand","dataValue":{"component":"main","capability":"colorTemperature","command":"setColorTemperature","arguments":[{"dataType":"datatype.schema.AFCommandArgument","dataValue":{"name":"temperature","optional":false,"dataType":"datatype.primitive.AFInteger"}}]}}]}},"styles":{"x":1115,"y":380}},{"nodeId":"4d02fcda-df99-4c75-8b0a-73bb67933acd","nodeVer":"1.0","nodeType":"constant","isStateful":true,"group":null,"inputPorts":{},"triggerPorts":{},"valuePorts":{},"triggerInPorts":{},"configurations":{"value":{"dataType":"datatype.primitive.AFInteger","dataValue":500}},"styles":{"x":975,"y":478}}]

  1. Rewire the graph as follows:

    a. Delete the wire that connects Command (switch) node's success port and Response: Success node's trigger port.

    b. Connect the Command (switch) node's success port to the Command (colorControl) node's trigger port.

    c. Connect the Command (colorTemperature) node's success port to the Response: Success node's trigger port.

    d. Connect the Numerical Comparison node's false port to the Response: Success node's trigger port.

  1. Click Align.

  1. Then, click Try It to see how the light bulb color change based on time.

You're done!

Congratulations! You have successfully achieved the goal of this Code Lab. Now, you can control a smart light bulb using Bixby Home Studio. If you face any trouble, you may download this file:

Control Bulb Complete Code
(25.72 KB)

To learn more about Bixby, visit:
developer.samsung.com/bixby