if (Dim($_POST['dimmer'], 0, $_POST['Naam']) == 'ERROR') {
                 echo '<div id="message" class="balloon">Dimmer ' . $_POST['Naam'] . ' level ' . $_POST['dimlevel'] . '<br/>ERROR</div>';
             }
             cset('timedimmer' . $_POST['Naam'], $time);
             cset('dimmer' . $_POST['Naam'], 0);
         } else {
             if (isset($_POST['dimsleep_x'])) {
                 cset('dimmer' . $_POST['Naam'], 1);
             } else {
                 if (isset($_POST['dimwake_x'])) {
                     if (Dim($_POST['dimmer'], $_POST['dimwakelevel'] + 1, $_POST['Naam']) == 'ERROR') {
                         echo '<div id="message" class="balloon">Dimmer ' . $_POST['Naam'] . ' level ' . $_POST['dimlevel'] . '<br/>ERROR</div>';
                     }
                     cset('dimmer' . $_POST['Naam'], 2);
                 } else {
                     if (Dim($_POST['dimmer'], $_POST['dimlevel'], $_POST['Naam']) == 'ERROR') {
                         echo '<div id="message" class="balloon">Dimmer ' . $_POST['Naam'] . ' level ' . $_POST['dimlevel'] . '<br/>ERROR</div>';
                     }
                     cset('timedimmer' . $_POST['Naam'], $time);
                     cset('dimmer' . $_POST['Naam'], 0);
                 }
             }
         }
     }
 } else {
     if (isset($_POST['Naam'])) {
         switch ($_POST['Naam']) {
             case 'radioluisteren':
                 $idx = 72;
                 break;
             case 'tvkijken':
 foreach ($items as $item) {
     if (${'D' . $item} != 'Off') {
         $action = $mc->get('dimmer' . $item);
         if ($action == 1) {
             $level = floor(${'Dlevel' . $item} * 0.95);
             Dim(${'DI' . $item}, $level, $item);
             if ($level == 0) {
                 $mc->set('dimmer' . $item, 0);
             }
         } else {
             if ($action == 2 && date('i') % 2 == 1) {
                 $level = ${'Dlevel' . $item} + 1;
                 if ($level > 30) {
                     $level = 30;
                 }
                 Dim(${'DI' . $item}, $level, $item);
                 if ($level == 30) {
                     $mc->set('dimmer' . $item, 0);
                 }
             }
         }
     }
 }
 //heating on/off
 if ($Sweg == 'On') {
     if ($Sheating != 'Off' && $STheating < $eenuur) {
         Schakel($SIheating, 'Off', 'heating');
         $Sheating = 'Off';
     }
 } else {
     if ($Sheating != 'On') {
                 }
             }
         }
     } else {
         if (isset($_POST['Udevice'])) {
             if (Udevice($_POST['Udevice']) == 'ERROR') {
                 echo '<div id="message" class="balloon">' . $_POST['Naam'] . ' ' . $_POST['Actie'] . '<br/>ERROR</div>';
             }
         } else {
             if (isset($_POST['dimlevelEettafel'])) {
                 if (Dim(163, $_POST['dimlevelEettafel']) == 'ERROR') {
                     echo '<div id="message" class="balloon">Dimmer eettafel level ' . $_POST['dimlevelEettafel'] . '<br/>ERROR</div>';
                 }
             } else {
                 if (isset($_POST['dimlevelZithoek'])) {
                     if (Dim(159, $_POST['dimlevelZithoek']) == 'ERROR') {
                         echo '<div id="message" class="balloon">Dimmer eettafel level ' . $_POST['dimlevelEettafel'] . '<br/>ERROR</div>';
                     }
                 } else {
                     if (isset($_POST['Scene'])) {
                         if (Scene($_POST['Scene']) == 'ERROR') {
                             echo '<div id="message" class="balloon">Scene ' . $_POST['Naam'] . ' activeren' . '<br/>ERROR</div>';
                         }
                     }
                 }
             }
         }
     }
 }
 if (isset($_POST['denon'])) {
     $denon_address = 'http://192.168.0.2';
 }
 if ($action == "wake") {
     if (${'Dlevel' . $place} < 30 && $mc->get('dimmer' . $place) != 2) {
         $mc->set('dimmer' . $place, 2);
         Dim(${'DI' . $place}, ${'Dlevel' . $place} + 1, $place);
     }
 } else {
     if ($action == "sleep") {
         if (${'Dlevel' . $place} > 1 && $mc->get('dimmer' . $place) != 1) {
             $mc->set('dimmer' . $place, 1);
             Dim(${'DI' . $place}, ${'Dlevel' . $place} - 1, $place);
         }
     } else {
         if ($action == "dimmer") {
             if (${'Dlevel' . $place} != $detail) {
                 Dim(${'DI' . $place}, $detail, 'GCal ' . $place . ' ');
             }
         } else {
             if ($action == "schakel") {
                 if (${'S' . $place} != $detail) {
                     Schakel(${'SI' . $place}, $detail, 'GCal ' . $place . ' ');
                 }
             } else {
                 if ($action == "setpoint") {
                     $mc->set('setpoint' . ${'RI' . $place}, 2);
                     if (${'R' . $place} != $detail) {
                         Udevice(${'RI' . $place}, 0, $detail, 'GCal ' . $place . ' ');
                     }
                 }
             }
         }