Added support for SARTANO. Cleaned the code.
This commit is contained in:
parent
c5f092fc72
commit
75cd57445a
3 changed files with 26 additions and 8 deletions
|
@ -35,6 +35,7 @@ Feel free to improve the program.
|
|||
|
||||
Revision history
|
||||
=================
|
||||
2008-02-11 0.2.0 Added support for SARTANO devices. General code cleanups.
|
||||
2008-02-11 0.1.4 Completely new switch logic, hopefully more robust with fewer bugs.
|
||||
2008-02-10 0.1.3 Modified switch logic. When dawn is before on-time, lights are not switched on. If dusk time is after off time, lights are not switched on.
|
||||
2008-01-30 0.1.2 Corrected a bug regarding datetimelocal.
|
||||
|
|
|
@ -13,10 +13,10 @@ $TELLSTICK_DEVICE = "/dev/tellstick";
|
|||
$CONFIG_FILE = "/etc/tellstickd.conf";
|
||||
$LOG_FILE = "/var/log/tellstickd";
|
||||
|
||||
# After this point you really shouldn't need to go
|
||||
# You should not need to go beyond this point (unless you have found a bug or need to improve the functionality).
|
||||
$AUTHOR = "Magnus Juntti, juntti\@mail.com";
|
||||
$PROGRAM_NAME = "tellstickd";
|
||||
$VERSION = "0.1.4";
|
||||
$VERSION = "0.2.0";
|
||||
|
||||
|
||||
# Structure of the configurations to be read;
|
||||
|
@ -96,7 +96,7 @@ sub is_inbetween_times
|
|||
$time2 += 2400;
|
||||
}
|
||||
|
||||
if ($curr_time >= $time1 && $curr_time <= $time2) {
|
||||
if ($curr_time >= $time1 && $curr_time < $time2) {
|
||||
return $YES;
|
||||
}
|
||||
|
||||
|
@ -109,13 +109,23 @@ sub rfcmd_exec {
|
|||
my $device_id = $_[0];
|
||||
my $action = $_[1];
|
||||
|
||||
if ($device_cfg[$device_id][0] eq "SARTANO") {
|
||||
$RFCMD_OPTIONS = "$TELLSTICK_DEVICE $device_cfg[$device_id][0] $device_cfg[$device_id][1]";
|
||||
}
|
||||
elsif ($device_cfg[$device_id][0] eq "NEXA") {
|
||||
$RFCMD_OPTIONS = "$TELLSTICK_DEVICE $device_cfg[$device_id][0] $device_cfg[$device_id][1] $device_cfg[$device_id][2]";
|
||||
}
|
||||
else {
|
||||
die("$PROGRAM_NAME: Device $device_id has an unknown protocol. Only NEXA and SARTANO allowed.\n");
|
||||
}
|
||||
|
||||
# Action = 1 means turn lamp on
|
||||
|
||||
# Action = 1 means turn device on, 0 turn device off
|
||||
if ($action == 1) {
|
||||
# Only turn the device on if it is not already turned on to avoid flashing dimmers.
|
||||
if ($device_cfg[$device_id][22] == 0) {
|
||||
printf("$PROGRAM_NAME: Time is $current_time. Switching on $device_cfg[$device_id][0] device $device_cfg[$device_id][1]$device_cfg[$device_id][2].\n");
|
||||
`$RFCMD $TELLSTICK_DEVICE $device_cfg[$device_id][0] $device_cfg[$device_id][1] $device_cfg[$device_id][2] 1`;
|
||||
`$RFCMD $RFCMD_OPTIONS 1`;
|
||||
$device_cfg[$device_id][22] = 1;
|
||||
|
||||
return;
|
||||
|
@ -127,7 +137,7 @@ sub rfcmd_exec {
|
|||
elsif ($action == 0) {
|
||||
if ($device_cfg[$device_id][22] == 1) {
|
||||
printf("$PROGRAM_NAME: Time is $current_time. Switching off $device_cfg[$device_id][0] device $device_cfg[$device_id][1]$device_cfg[$device_id][2].\n");
|
||||
`$RFCMD $TELLSTICK_DEVICE $device_cfg[$device_id][0] $device_cfg[$device_id][1] $device_cfg[$device_id][2] 0`;
|
||||
`$RFCMD $RFCMD_OPTIONS 0`;
|
||||
$device_cfg[$device_id][22] = 0;
|
||||
|
||||
return;
|
||||
|
@ -243,6 +253,10 @@ sub read_config
|
|||
$device_cfg[$i][22] = 1; # Initial state set to so that they will be switched of at startup
|
||||
|
||||
|
||||
if ($device_cfg[$device_id][0] eq "SARTANO") {
|
||||
$device_cfg[$i][2] = "";
|
||||
}
|
||||
|
||||
# Some sanity checks
|
||||
# If the turn on time is not to be used, this is marked with -1
|
||||
if ($device_cfg[$i][3] != -1) {
|
||||
|
@ -419,11 +433,11 @@ while (1) {
|
|||
# Sunrise time + requested offset
|
||||
if ($device_cfg[$i][5] == $YES) {
|
||||
$device_cfg[$i][20] = add_time($sunrise_time, $device_cfg[$i][6]);
|
||||
printf("$PROGRAM_NAME: Device $device_cfg[$i][1]$device_cfg[$i][2] sunrise off time set to $device_cfg[$i][20].\n");
|
||||
printf("$PROGRAM_NAME: Device $device_cfg[$i][0] $device_cfg[$i][1]$device_cfg[$i][2] sunrise off time set to $device_cfg[$i][20].\n");
|
||||
|
||||
# Sunset time - requested offset
|
||||
$device_cfg[$i][21] = subtract_time($sunset_time, $device_cfg[$i][7]);
|
||||
printf("$PROGRAM_NAME: Device $device_cfg[$i][1]$device_cfg[$i][2] sunset on time set to $device_cfg[$i][21].\n");
|
||||
printf("$PROGRAM_NAME: Device $device_cfg[$i][0] $device_cfg[$i][1]$device_cfg[$i][2] sunset on time set to $device_cfg[$i][21].\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,9 @@
|
|||
# Time format xx:yy where xx is hour and yy is minute
|
||||
# If no turn on time or turn off time should be used. Note this with -1. See the example line below. Only to be used on turn on or turn off times.
|
||||
# NEXA A 1 -1 22:45 1 00:30 00:30
|
||||
#
|
||||
# Sample row for a SARTANO device. Note that the 0 in column three does not have a meaning.
|
||||
SARTANO 0000000000 0 05:30 22:45 1 00:30 00:15
|
||||
|
||||
# Sample to control NEXA device A 1. Turn on device 05:30 turn off 22:45. Turn off the device 30 minutes after sunrise, turn on again 15 minutes before sunset.
|
||||
NEXA A 1 05:30 22:45 1 00:30 00:15
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue