Holiday Landscape Light Script for Falcon Pi Player
I use Falcon PI Player for my holiday lighting. After adding flood lights to the light show this past year, I wanted to use the landscape or flood lights year round for special days, months, and holidays. While FPP does have the functionality to schedule actions based on holidays, it does not have all of the holidays that I wanted to be able to accomidate. In addition, there are special months, that I wanted to do certain colors for. THe FPP Schedule does not have the capabilities (at least at the time of writing this article) to be able to do that.
That said, I created the PHP script below. THe way that this works is the FPP Scheduler will call the script as the scheduled time, the script determines what day it is. Then based on the day, month, or other conditions specified, the selected sequence is started by sending a command to FPP and set to repeat.
Turn On Lights
Need to know which sequence to turn when turning on the lights. The script below will check the current date, get the sequence name that should be played based upon the rules, and then run the FPP command to start the sequence on a loop.
<?php
define("DEBUG", false);
define("DATE_FORMAT", "Y-M-d");
define("BLUE_LIGHTS", "Calendar Blue.fseq");
define("BLUE_GREEN_LIGHTS", "Calendar Blue Green.fseq");
define("GREEN_LIGHTS", "Calendar Green.fseq");
define("PINK_CYAN_YELLOW_LIGHTS", "Calendar Pink Cyan Yellow.fseq");
define("PINK_LIGHTS", "Calendar Pink.fseq");
define("RED_BLUE_LIGHTS", "Calendar Red Blue.fseq");
define("RED_GREEN_BLACK_LIGHTS", "Calendar Red Green Black.fseq");
define("RED_GREEN_LIGHTS", "Calendar Red Green.fseq");
define("RED_PINK_LIGHTS", "Calendar Red Pink.fseq");
define("YELLOW_LIGHTS", "Calendar Yellow.fseq");
define("CHRISTMAS_PLAYLIST", "Christmas.json");
final class HolidayMapping
{
public $startDate;
public $endDate;
public $sequence;
public function __construct($startDate, $endDate, $sequence)
{
if (empty($startDate) || is_null($startDate)) {
throw new Exception("Invalid start date");
}
$this->startDate = strtotime($startDate);
if (empty($endDate) || is_null($endDate)) {
throw new Exception("Invalid end date");
}
$this->endDate = strtotime($endDate);
if (empty($sequence) || is_null($sequence)) {
throw new Exception("Invalid sequence");
}
$this->sequence = $sequence;
if (DEBUG) {
echo "Start " . date(DATE_FORMAT, $this->startDate) . ", End " . date(DATE_FORMAT, $this->endDate) . ", $this->sequence\n";
}
}
}
$currentYear = date("Y");
$holidayMappings = array(
// dynamic holidays
new HolidayMapping("third monday $currentYear-01 -3 days", "third monday $currentYear-01", RED_GREEN_BLACK_LIGHTS), // mlk day
new HolidayMapping("third monday $currentYear-02 -3 days", "third monday $currentYear-02", RED_BLUE_LIGHTS), // presidents day
new HolidayMapping("second sunday $currentYear-05 -2 days", "second sunday $currentYear-05", RED_PINK_LIGHTS), // mothers day
new HolidayMapping("last monday of $currentYear-05 -3 days", "last Monday of $currentYear-05", RED_BLUE_LIGHTS), // memorial day
new HolidayMapping("third sunday $currentYear-06 -2 days", "third sunday $currentYear-06", BLUE_LIGHTS), // fathers day
new HolidayMapping("third monday $currentYear-06 -3 days", "third monday $currentYear-06", RED_GREEN_BLACK_LIGHTS), // juneteenth
new HolidayMapping("first monday $currentYear-09 -3 days", "first monday $currentYear-09", RED_BLUE_LIGHTS), // labor day
new HolidayMapping("fourth thursday $currentYear-11", "fourth thursday $currentYear-11", YELLOW_LIGHTS), // thanksgiving
new HolidayMapping("fourth friday $currentYear-11", "december 31 $currentYear", CHRISTMAS_PLAYLIST), // holiday lights show playlist
// static holidays
new HolidayMapping("january 1", "january 1", RED_BLUE_LIGHTS), // new years
new HolidayMapping("february 14", "february 14", RED_PINK_LIGHTS), // valentines day
new HolidayMapping("march 17", "march 17", GREEN_LIGHTS), // st patricks day
new HolidayMapping("april 22", "april 22", BLUE_GREEN_LIGHTS), // earth day
new HolidayMapping("may 5", "may 5", RED_GREEN_LIGHTS), // cinco de mayo
new HolidayMapping("june 14", "june 14", RED_BLUE_LIGHTS), // flag day
new HolidayMapping("july 1", "july 4", RED_BLUE_LIGHTS), // independence day
new HolidayMapping("november 11", "november 11", RED_BLUE_LIGHTS), // veterans day
// special months
new HolidayMapping("february 1 $currentYear", "february 29 $currentYear", RED_GREEN_BLACK_LIGHTS), // black history
new HolidayMapping("april 1 $currentYear", "april 30 $currentYear", BLUE_LIGHTS), // autism awareness
new HolidayMapping("may 1 $currentYear", "may 31 $currentYear", GREEN_LIGHTS), // mental health awareness
new HolidayMapping("october 1 $currentYear", "october 31 $currentYear", PINK_LIGHTS), // breast cancer awareness
);
$currentDate = strtotime(date(DATE_FORMAT));
if (DEBUG) {
echo "Debug enabled" . "\n";
echo "Current date " . date(DATE_FORMAT, $currentDate) . "\n";
}
$sequenceName = BLUE_LIGHTS;
foreach ($holidayMappings as $holidayMapping) {
if ($currentDate >= $holidayMapping->startDate && $currentDate <= $holidayMapping->endDate) {
$sequenceName = $holidayMapping->sequence;
break;
}
}
$url = "'http://localhost/api/command/Start Playlist/$sequenceName/true/false'";
if (DEBUG) {
echo $url . "\n";
}
else {
shell_exec("wget $url");
}
Turn Off Lights
To stop the running playlist, I have set a schedule within FPP to run the Stop Gracefully command at the specified time. Falcon Pi Player has this functionality built into it, so I do not have to create custom code for this purpose.
For other tasks, such as cleaning up logs and such, I run additional scripts that use the FPP scheduler at the specified time when the show is offline. That way, everything can be done from the user interface of FPP, and will not get wiped out when upgrading FPP versions.