Turn on devices

This example will show you how to turn on devices in your browser.

Setting up

First we'll need to prepare the simulation to contain some devices. So open up your favourite editor and point it to data/sim.xml. Paste the following into it:

<?xml version="1.0"?>
<simulation version="1">
  <modulator busid="71" dsid="10">
    <zone id="1">
      <device dsid="11" busid="11" type="standard.simple"/>
      <device dsid="12" busid="12" type="standard.simple"/>
      <device dsid="13" busid="13" type="standard.simple"/>
      <group id="1">
        <device busid="11" />
        <device busid="12" />
        <device busid="13" />
      </group>
    </zone>
  </modulator>
</simulation>

If you want your devices to be named correctly replace your data/apartment.xml with the following block:

<?xml version='1.0' encoding='utf-8'?>
<config version="1">
        <devices>
                <device dsid="3504175fe0000000ffc00011">
                        <name>dev1</name>
                </device>
                <device dsid="3504175fe0000000ffc00012">
                        <name>dev2</name>
                </device>
                <device dsid="3504175fe0000000ffc00013">
                        <name>dev3</name>
                </device>
        </devices>
</config>

Skeleton

The following is the skeleton we're using to build our example on:

<html>
  <head>
    <title>digitalStrom - Example - turnOn/Off</title>
  </head>
  <body>
  </body>    
</html>

We need to load some libraries for our scripts. The first is prototype.js, which adds some helpers. The second one is model.js which will be provided by the dSS. To load those, inser the following lines after /title>

    <script src="js/lib/prototype/prototype.js" language="JavaScript" type="text/javascript"></script>
    <script src="js/model.js" language="JavaScript" type="text/javascript"></script>

Next we're going to insert the js-code to turn on/off a device. After the code added above insert the following:

<script type="text/javascript" language="JavaScript">

function turnOn() {
  (new Device("3504175fe0000000ffc00011")).turnOn();
}

function turnOff() {
  (new Device("3504175fe0000000ffc00011")).turnOff();
}

</script>

In turnXXX() we're creating a device object by passing it the dSID to affect. Now we need something calling those devices. The following snippet creates two anchor elements to turnOn/Off the specified device:

      <a href="javascript:turnOn()">Turn on</a>
      <a href="javascript:turnOff()">Turn off</a>

Put the lines above between the body tags. Now load up the page and press the two links and see your virtual light-bulbs go on and off.