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("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_PINK_LIGHTS", "Calendar Red Pink.fseq");
define("YELLOW_LIGHTS", "Calendar Yellow.fseq");
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 = date(DATE_FORMAT, strtotime($startDate));
if (empty($endDate) || is_null($endDate)) {
throw new Exception("Invalid end date");
}
$this->endDate = date(DATE_FORMAT, strtotime($endDate));
if (empty($sequence) || is_null($sequence)) {
throw new Exception("Invalid start date");
}
$this->sequence = $sequence;
}
}
$currentYear = date("Y");
$holidayMappings = array(
// dynamic holidays
new HolidayMapping("second friday $currentYear-01", "third monday $currentYear-01", RED_GREEN_BLACK_LIGHTS), // mlk day
new HolidayMapping("second friday $currentYear-02", "third monday $currentYear-02", RED_BLUE_LIGHTS), // presidents day
new HolidayMapping("first friday $currentYear-05", "second sunday $currentYear-05", RED_PINK_LIGHTS), // mothers day
new HolidayMapping("4th friday $currentYear-05", "last monday $currentYear-05", RED_BLUE_LIGHTS), // memorial day
new HolidayMapping("second friday $currentYear-06", "third sunday $currentYear-06", BLUE_LIGHTS), // fathers day
new HolidayMapping("third monday $currentYear-06", "third monday $currentYear-06", RED_GREEN_BLACK_LIGHTS), // juneteenth
new HolidayMapping("$currentYear-09-01", "first monday $currentYear-09", RED_BLUE_LIGHTS), // labor day
// 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_BLACK_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("october 31", "october 31", YELLOW_LIGHTS), // halloween
new HolidayMapping("november 11", "november 11", RED_BLUE_LIGHTS), // veterans day
// special months
new HolidayMapping("february 1", "february 29", RED_GREEN_BLACK_LIGHTS), // black history
new HolidayMapping("april 1", "april 30", BLUE_LIGHTS), // autism awareness
new HolidayMapping("may 1", "may 31", GREEN_LIGHTS), // mental health awareness
new HolidayMapping("october 1", "october 31", PINK_LIGHTS), // breast cancer awareness
);
$currentDate = date(DATE_FORMAT);
$sequenceName = BLUE_LIGHTS;
foreach ($holidayMappings as $holidayMapping) {
if ($holidayMapping->startDate >= $currentDate && $holidayMapping->endDate <= $currentDate) {
$sequenceName = $holidayMapping->sequence;
break;
}
}
$url = "'http://localhost/api/command/Start Playlist/$sequenceName/true/false'";
$output = shell_exec("wget $url");
echo "$output" > "/home/fpp/media/log/holiday.log";
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.