Control a Smart Bulb
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 notewhen you use a virtual switch, you can only create metadata and test the turning on and off functionality however, a physical smart rgb light bulb is necessary for testing other functions of this code lab activity, such as changing the light bulb color to red smartthings labs feature is available only on android app in us, canada, uk, india, and south korea start your project go to bhs bixbydevelopers com and sign in using your samsung account create a new project select your smartthings location and smart rgb light bulb or virtual switch for the device click create metadata from scratch then, click next choose powerswitch under bixby voice category select the powerswitch-turnoff and powerswitch-turnon voice intents click next 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 go to voice intents > powerswitch-turnon > graph click the sample graphs icon on the left sidebar menu to show all the available sample graphs scroll down to see the turn on device sample graph or find it using the search bar drag and drop the sample graph into your powerswitch-turnon graph editor click try it to turn on your light bulb noteif you're using a virtual switch, it will turn on, but you won't be able to see the switch itself however, you can see the state of the virtual switch change from off to on in the smartthings app 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 copy the nodes from the powerswitch-turnon graph to the powerswitch-turnoff graph editor click the command node to open the node configuration pane and change the command from on to off right-click on the command node and change its comment to turn off device click try it to turn off the device 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 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}}] 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 noteadd a constant node with time zone, for example america/new_york, as string value if you want to test this section based on your local time click align 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 notewatch this short clip to quickly know how to navigate your way in this code lab and to see how easy it is to use bixby home studio to learn more about bixby, visit developer samsung com/bixby