Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 8 Next »

Hardware Setup

Philip Hue is a system of 4 components:

  1. Apps – These are ways to control the lights to make them do smart things. 
  2. Bridge – This is used to enable your smart bulbs to communicate with each other and the Portal via the internet. The main set of APIs are those offered by the bridge. These allow you to control all settings of the lights in your system. These APIs require direct access to your bridge so you’ll only be able to access them when your app and bridge are on the same local network.
  3. Portal – This is a web based control panel which connects your home to the internet. It delivers control commands from outside and keeps your software in the bridge up-to-date. The portal presents a utility API to help you discover the address of your bridge.
  4. Lights – This is the output of the system. These smart bulbs contain 3 types of LED specifically chosen to produce a range of colors and intensities. Lights create a mesh network with each other which enables each light to pass on messages to the next extending the range and making everything more robust. They are connected to the bridge via an open standards protocol called ZigBee Light Link.

We will be controlling the lights using Philip Bridge HTTP APIs.

Philip Bridge HTTP Requests

http://10.0.2.16/api/newdeveloper/lights

Request Name: Get the list of lights

Get Lights JSON
{
    "1": {
        "state": {
            "on": true,
            "bri": 144,
            "hue": 13088,
            "sat": 212,
            "effect": "none",
            "xy": [
                0.5128,
                0.4147
            ],
            "ct": 467,
            "alert": "none",
            "colormode": "hs",
            "reachable": true
        },
        "type": "Extended color light",
        "name": "Hue Lamp 1",
        "modelid": "LCT001",
        "uniqueid": "00:17:88:01:00:b6:c6:f0-0b",
        "swversion": "66009663",
        "pointsymbol": {
            "1": "none",
            "2": "none",
            "3": "none",
            "4": "none",
            "5": "none",
            "6": "none",
            "7": "none",
            "8": "none"
        }
    },
    "2": {
        "state": {
            "on": true,
            "bri": 144,
            "hue": 13088,
            "sat": 212,
            "effect": "none",
            "xy": [
                0.5128,
                0.4147
            ],
            "ct": 467,
            "alert": "none",
            "colormode": "ct",
            "reachable": true
        },
        "type": "Extended color light",
        "name": "Hue Lamp 2",
        "modelid": "LCT001",
        "uniqueid": "00:17:88:01:00:b9:38:7c-0b",
        "swversion": "66009663",
        "pointsymbol": {
            "1": "none",
            "2": "none",
            "3": "none",
            "4": "none",
            "5": "none",
            "6": "none",
            "7": "none",
            "8": "none"
        }
    },
    "3": {
        "state": {
            "on": true,
            "bri": 144,
            "hue": 13088,
            "sat": 212,
            "effect": "none",
            "xy": [
                0.5128,
                0.4147
            ],
            "ct": 467,
            "alert": "none",
            "colormode": "hs",
            "reachable": true
        },
        "type": "Extended color light",
        "name": "Hue Lamp 3",
        "modelid": "LCT001",
        "uniqueid": "00:17:88:01:00:b9:38:5c-0b",
        "swversion": "66009663",
        "pointsymbol": {
            "1": "none",
            "2": "none",
            "3": "none",
            "4": "none",
            "5": "none",
            "6": "none",
            "7": "none",
            "8": "none"
        }
    }
}

Request Name:  Change the state of Light

http://10.0.2.16/api/newdeveloper/lights/1/state

Get Lights JSON
{"on":true}

Queries

Find Lights
 <Query>
  <Find format="all">
    <PhilipLightModel>
      <LightNumber eq="1"/>
    </PhilipLightModel>
  </Find>
</Query>
GetLightManager
<Query>
  <Find format="All">
    <PhilipLightManagerModel>
      <ManagerId ne=""/>
    </PhilipLightManagerModel>
  </Find>
</Query>
InitManager
<Query>
  <DeleteAll>
    <PhilipLightManagerModel>
      <ManagerId ne=""/>
    </PhilipLightManagerModel>
  </DeleteAll>
  <Create>
    <PhilipLightManagerModel>
      <LoadLights>
        True
      </LoadLights>
    </PhilipLightManagerModel>
  </Create>
</Query>
ToggleLight
<Query>
  <Find format="All">
    <PhilipLightModel>
      <LightNumber eq="1"/>
    </PhilipLightModel>
  </Find>
  <SetResponseData>
    <Key>
      Message.Value.Find.Result.PhilipLightModel.state.On
    </Key>
    <Value>
      false
    </Value>
  </SetResponseData>
  <Update>
    <From>
      Result
    </From>
    <Include>
      $Response.Message.Value.Find
    </Include>
  </Update>
</Query>

PhidgetMotor Complete Model
<Namespace Name="Atomiton">

  <Domain Name="Lights">

    <PhilipLightBaseURI>http://10.0.2.16/api/newdeveloper</PhilipLightBaseURI>

    <Macro Name="ExecuteQuery">

      <Argument>

        <QueryString>

          <Query/>

        </QueryString>

      </Argument>

      <Result>

        <OnRequest>

          <Target>[:RuntimeParams.FacetIDName:]</Target>

          <Process>

            <Message>

              <Value>[:$Macro.Argument.QueryString:]</Value>

            </Message>

          </Process>

        </OnRequest>

      </Result>

    </Macro>




    <Macro Name="AddLight">

      <Argument>

        <LightNumber/>

        <On/>

        <bri/>

        <hue/>

        <sat/>

      </Argument>

      <Result>

        <ExecuteQuery>

          <QueryString>

            <DeleteAll>

              <PhilipLightModel>

                <LightNumber eq="[:$Macro.Argument.LightNumber:]"/>

              </PhilipLightModel>

            </DeleteAll>

            <Create>

              <PhilipLightModel>

                <LightNumber>[:$Macro.Argument.LightNumber:]</LightNumber>

                <state>

                  <On>[:$Macro.Argument.On:]</On>

                  <bri>[:$Macro.Argument.bri:]</bri>

                  <hue>[:$Macro.Argument.hue:]</hue>

                  <sat>[:$Macro.Argument.sat:]</sat>

                </state>

              </PhilipLightModel>

            </Create>

          </QueryString>

        </ExecuteQuery>

      </Result>

    </Macro>




    <Def Name="PhilipLightState">

      <Boolean Name="On"/>

      <Integer Name="bri"/>

      <Integer Name="hue"/>

      <Integer Name="sat"/>

      <String Name="effect"/>

      <Double Name="xy" cardinality="2"/>

      <Integer Name="ct"/>

      <String Name="alert"/>

      <String Name="colormode"/>

      <Boolean Name="reachable"/>

    </Def>

    <Def Name="PointSymbol">

      <String name="1" default="none"/>

      <String name="2" default="none"/>

      <String name="3" default="none"/>

      <String name="4" default="none"/>

      <String name="5" default="none"/>

      <String name="6" default="none"/>

      <String name="7" default="none"/>

      <String name="8" default="none"/>

    </Def>




    <ThingFacet Name="PhilipLightFacet">

      <String Name="LightNumber"/>

      <PhilipLightState Name="state" KnownBy="PhilipLightActionUsingCurl"/>

      <String Name="Type"/>

      <String Name="Name"/>

      <String Name="modelid"/>

      <String Name="uniqueid"/>

      <String Name="swversion"/>

      <PointSymbol Name="Pointsymbol"/>




      <AA>[:#o#Event.Argument:]</AA>

      <Ontrue>{"on":true}</Ontrue>

      <Onfalse>"on":false</Onfalse>




      <Action Name="PhilipLightActionUsingCurl">

        <Workflow Limit="1" Live="1" Timeout="-1">

          <Task name="Main" While="True">

            <Event name="Argument" as="ActionArgument"/>

            <Invoke name="SetState" waitFor="ActionArgument"

              execute="curl -X PUT -d '{&quot;on&quot;:[%:[:AA:].state.On.Value:%]}' [:PhilipLightBaseURI:]/lights/[%:[:AA:].LightNumber.Value:%]/state"/>

            <Log Message="[:Invoke.SetState:]"/>

            <Output name="Result" as="ActionResult">

              <Value>

                <state>

                  [%:[:AA:].state.On.Value:%]

                </state>

              </Value>

            </Output>

          </Task>

        </Workflow>

      </Action>

    </ThingFacet>




    <ThingFacet Name="PhilipLightManagerFacet">

      <String Name="LoadLights" KnownBy="LoadLightsAction"/>

      <Action Name="LoadLightsAction">

        <Workflow Limit="1" Live="1" Timeout="-1">

          <Task Name="Main" While="True">

            <Event Name="Argument" as="ActionArgument"/>

            <Invoke Name="GetLights" waitFor="ActionArgument" Get="[:PhilipLightBaseURI:]/lights"/>

            <Log Message="Lights Loaded...[:Invoke.GetLights.Message.Value:]"/>

            <Invoke Name="ParseGetLightsResult">

              <FacetScript>

                <AddLight>

                  <LightNumber>1</LightNumber>

                  <On>[:Invoke.GetLights.Message.Value.1.State.On:]</On>

                  <bri>[:Invoke.GetLights.Message.Value.1.State.bri:]</bri>

                  <hue>[:Invoke.GetLights.Message.Value.1.State.hue:]</hue>

                  <sat>[:Invoke.GetLights.Message.Value.1.State.sat:]</sat>

                </AddLight>

                <AddLight>

                  <LightNumber>2</LightNumber>

                  <On>[:Invoke.GetLights.Message.Value.2.State.On:]</On>

                  <bri>[:Invoke.GetLights.Message.Value.2.State.bri:]</bri>

                  <hue>[:Invoke.GetLights.Message.Value.2.State.hue:]</hue>

                  <sat>[:Invoke.GetLights.Message.Value.2.State.sat:]</sat>

                </AddLight>

                <AddLight>

                  <LightNumber>3</LightNumber>

                  <On>[:Invoke.GetLights.Message.Value.3.State.On:]</On>

                  <bri>[:Invoke.GetLights.Message.Value.3.State.bri:]</bri>

                  <hue>[:Invoke.GetLights.Message.Value.3.State.hue:]</hue>

                  <sat>[:Invoke.GetLights.Message.Value.3.State.sat:]</sat>

                </AddLight>

              </FacetScript>

            </Invoke>

            <Output Name="Result" as="ActionResult">

              <Value>

                <LoadLights>True</LoadLights>

              </Value>

            </Output>

          </Task>

        </Workflow>

      </Action>

    </ThingFacet>




    <ThingModel Name="PhilipLightModel" Combines="PhilipLightFacet">

      <Sid Name="LightId"/>

    </ThingModel>




    <ThingModel Name="PhilipLightManagerModel" Combines="PhilipLightManagerFacet">

      <sid Name="ManagerId"/>

    </ThingModel>

  </Domain>

</Namespace>







  • No labels