My Web Implementation of X10Commander w/ Scheduler

Forum to discuss X10 Commander iPhone/iPod/iPad/Android client for X10 Devices

My Web Implementation of X10Commander w/ Scheduler

Postby viddywell » Mon Nov 19, 2012 7:59 am

I should start by saying, I love the x10 commander app and it works great and their is absolutely no reason NOT to use it. Further it wasn't until I logged into the forum to share that I saw Rocket's much more robust web setup, so I duplicated (and did a lot of unnecessary work) in this process, and it looks like approached it from a different way. Finally, I'm not a web developer - so a lot of this is "messy" and cobbled together but it all works and having spent the time on it, I thought I'd share it with everyone here. :)

I like the versatility of a web page. I wanted something I could give to anyone if need be to access our x10.

In my case, I have a single light controlled with an x10 adapter (I know, more to come and more tweaking to this setup to come)

My main page is hosted on an outside web server - a subdomain off my personal domain secured with an htaccess file.

It looks like this:
Image

The schedule page linked form the main looks like this:
Image

The main page calls both an internal link as well as an external dyndns link for the top manual controls. For the schedule portion which I'll cover further down, I'm referencing a set of text files for the current schedule status - here's the source:

index.php

Code: Select all
<html>
<head>
<meta http-equiv="expires" content="0">
</head>
<title>Light Control</title>

<center>

<b>Controls</b>
<br>
<a href="on.html" target="output">
<img src="on.png"></a>
<a href="off.html" target="output">
<img src="off.png"></a>
<br><br>
<a href="http://lights.mydomain.com/scheduler">Go to scheduler</a>
<br>
<br>
<b>
Current Schedule</b>
<br>
Schedule Status:<b> <?php include("./scheduler/status.txt"); ?></b>
<br>
Currenty Scheduled "ON" time:<b> <?php include("./scheduler/on.txt"); ?></b>
<br>
Currenty Scheduled "OFF" time:<b> <?php include("./scheduler/off.txt"); ?></b>

<iframe src="about:blank" style="border:0px #FFFFFF none;" name="output" scrolling="no" frameborder="0" marginheight="0px" marginwidth="0px" height="1px" width="1px"></iframe>

</html>


From within this page, for the manual controls I load a document called off.html and on.html into a 1 pixel large iframe to hide the output. These send an "on" command to both my internal ip as well as my dyndns hostname so that the same page/control will work internally as well as externally. Here's the source for both the on and off html files:

on.html


Code: Select all
<html>
<title>On</title>
<iframe src="http://192.168.1.80:8086/?x10command=DEVICE~sendplc~%22A1%20ON%22" style="border:0px #FFFFFF none;" name="output" scrolling="no" frameborder="0" marginheight="0px" marginwidth="0px" height="1px" width="1px"></iframe>

<iframe src="http://mydyndns.mine.org:myportforward/?x10command=DEVICE~sendplc~%22A1%20ON%22" style="border:0px #FFFFFF none;" name="output" scrolling="no" frameborder="0" marginheight="0px" marginwidth="0px" height="1px" width="1px"></iframe></html>


off.html


Code: Select all
<html>
<title>Off</title>
<iframe src="http://192.168.1.80:8086/?x10command=DEVICE~sendplc~%22A1%20OFF%22" style="border:0px #FFFFFF none;" name="output" scrolling="no" frameborder="0" marginheight="0px" marginwidth="0px" height="1px" width="1px"></iframe>

<iframe src="http://mydyndns.mine.org:myportforward/?x10command=DEVICE~sendplc~%22A1%20OFF%22" style="border:0px #FFFFFF none;" name="output" scrolling="no" frameborder="0" marginheight="0px" marginwidth="0px" height="1px" width="1px"></iframe></html>



On to the schedule page, where things get a bit more complex. I really wanted a web interface method of setting a schedule (for example, away from home for several days - I'd like to schedule the lights to go on and off at certain times). To do this, while keeping the page hosted separately from my home computer running the x10 commander software I had to get a bit inventive. The way the whole thing works is by using a form to write to several text files. These text files are then downloaded via ftp to my home computer every 15 minutes. The text files are fed into variables and through a batch file calling the schtasks command, two scheduled tasks are modified to match the variables in the text file.

The components for this are:

[*]scheduler index.php on my webhost
form action "store_it.php" called by form
output text files - on.txt, off.txt, and status.txt created by form input on the webserver
batch file to download variable files and change scheduled task
batch file to turn on lights
batch file to turn off lights

index.php (located at ./scheduler)

Code: Select all
<html>

<body>
<a href="http://mydyndns.mine.org">Return to manual controls</a>
<br>
<br>
<b>Please assure ON time is before OFF time when setting schedule.</b>
<br>
Schedules take 15 minutes to take affect on home computer
<br><br>
<form action="store_it.php" method="post">
<table>
  <tr>
<b>Time On</b><br>
Hour:
<select name="houron">
  <option value="00">00</option>
  <option value="01">01</option>
  <option value="02">02</option>
  <option value="03">03</option>
  <option value="04">04</option>
  <option value="05">05</option>
  <option value="06">06</option>
  <option value="07">07</option>
  <option value="08">08</option>
  <option value="09">09</option>
  <option value="10">10</option>
  <option value="11">11</option>
  <option value="12">12</option>
  <option value="13">13</option>
  <option value="14">14</option>
  <option value="15">15</option>
  <option value="16">16</option>
  <option value="17">17</option>
  <option value="18">18</option>
  <option value="19">19</option>
  <option value="20">20</option>
  <option value="21">21</option>
  <option value="22">22</option>
  <option value="23">23</option>
</select>
Minute:
<select name="minuteon">
  <option value="00">00</option>
  <option value="15">15</option>
  <option value="30">30</option>
  <option value="45">45</option>
</select>
<br><br>

<b>Time Off</b><br>
Hour:
<select name="houroff">
  <option value="00">00</option>
  <option value="01">01</option>
  <option value="02">02</option>
  <option value="03">03</option>
  <option value="04">04</option>
  <option value="05">05</option>
  <option value="06">06</option>
  <option value="07">07</option>
  <option value="08">08</option>
  <option value="09">09</option>
  <option value="10">10</option>
  <option value="11">11</option>
  <option value="12">12</option>
  <option value="13">13</option>
  <option value="14">14</option>
  <option value="15">15</option>
  <option value="16">16</option>
  <option value="17">17</option>
  <option value="18">18</option>
  <option value="19">19</option>
  <option value="20">20</option>
  <option value="21">21</option>
  <option value="22">22</option>
  <option value="23">23</option>
</select>
Minute:
<select name="minuteoff">
  <option value="00">00</option>
  <option value="15">15</option>
  <option value="30">30</option>
  <option value="45">45</option>
 
</select>
<br><br>
<b>Schedule Status</b><br>
Status:
<select name="status">
  <option value="Enabled">Enabled</option>
  <option value="Disabled">Disabled</option>
</select>

<br>
 
   <td colspan="2" align="center"><input type="submit" value="Submit"></td>
</form>
<br><br>
Schedule Status:<b> <?php include("status.txt"); ?></b>
<br>
Currenty Scheduled "ON" time:<b> <?php include("on.txt"); ?></b>
<br>
Currenty Scheduled "OFF" time:<b> <?php include("off.txt"); ?></b>

</body>
</html>


store_it.php form action
Code: Select all
<?php
//Set Variables

$hron = $_POST['houron'];
$minon = $_POST['minuteon'];

$hroff = $_POST['houroff'];
$minoff = $_POST['minuteoff'];

$schedstatus = $_POST['status'];

$sep = ":";

$writeoff = fopen("off.txt","w");
$writeon = fopen("on.txt","w");
$writestatus = fopen("status.txt","w");


//Write On Text File





fwrite($writeon,$hron);
fwrite($writeon,$sep);
fwrite($writeon,$minon);

fclose($writeon);


//Write Off Text File

fwrite($writeoff,$hroff);
fwrite($writeoff,$sep);
fwrite($writeoff,$minoff);

fclose($writeoff);


//Write Status Text file

fwrite($writestatus,$schedstatus);
fclose($writestatus);


?>

Schedule Status:<b> <?php include("status.txt"); ?></b>
<br>
Currenty Scheduled "ON" time:<b> <?php include("on.txt"); ?></b>
<br>
Currenty Scheduled "OFF" time:<b> <?php include("off.txt"); ?></b>
<form action="index.php">
<input type="submit" value="Back to Schedule Input">
</form>


on.txt - variable by form input

Code: Select all
19:00


off.txt - variable by form input

Code: Select all
23:45


status.txt - variable by form input

Code: Select all
Enabled


batch file run every 15 minutes to check for new schedules and modify existing "LightsOn" (calls on.bat below) and "LightsOff" (calls off.bat below) scheduled tasks if changed

Code: Select all
@echo off
FTP -v -i -s:ftpscript.txt

set /p ontime=<on.txt
set /p offtime=<off.txt
set /p status=<status.txt

set statusset=/enable
if %status% neq Enabled set statusset=/disable


schtasks /change /RP home /TN LightsOn /ST %ontime% %statusset%
schtasks /change /RP home /TN LightsOff /ST %offtime% %statusset%
exit


on.bat - requires windows wget in same directory or system path

Code: Select all
wget http://goo.gl/my.shortened.url.pointing.to.internal.web.interface.call.for.on.had.to.do.this.because.batch.didn't.handle.tildes.and.quotes
del /q index.html@*


off.bat - requires windows wget in same directory or system path

Code: Select all
wget http://goo.gl/my.shortened.url.pointing.to.internal.web.interface.call.for.off.had.to.do.this.because.batch.didn't.handle.tildes.and.quotes
del /q index.html@*



I guess that sums it up. Like I said - not a web developer (system admin by trade), so I worked with what I knew to make this work. I like it and it works well so I thought I'd share with you fine folks - cause frankly who else is going to appreciate the ingenuity and work that went into it.

Thanks to the spectacular dev on making x10 commander so versatile and allowing for this types of extra functionality beyond the apps original purpose. If this is of interest to anyone and I can provide any further detail around how it works, please feel free to ask.
viddywell
 
Posts: 4
Joined: Mon Nov 19, 2012 7:11 am

Re: My Web Implementation of X10Commander w/ Scheduler

Postby Melloware » Mon Nov 19, 2012 11:16 am

Two thumbs up on this effort!!!
=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Melloware Inc.
http://www.melloware.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-
User avatar
Melloware
Site Admin
 
Posts: 11080
Joined: Thu Dec 01, 2005 10:24 pm
Location: Philadelphia, Pennsylvania USA

Re: My Web Implementation of X10Commander w/ Scheduler

Postby hinsler » Fri Jan 04, 2013 7:36 am

Hello. sorry for the confusion with my query but the Board Administrator kicked me off this site inappropriately twice! Looks like I am now here to stay.

So if you would be so kind as to explain to me how to get your code into my machine so that I can set up a scheduler for the X10 commander I would really appreciate it!

Thanks so much.

Harvey
hinsler
 
Posts: 1
Joined: Fri Jan 04, 2013 7:34 am


Return to X10 Commander

Who is online

Users browsing this forum: No registered users and 1 guest

cron