Post by Jason on Nov 28, 2021 19:08:51 GMT -8
Good evening all,
I've been slowly replacing light switches and fan controls in our home with Lutron Caséta products. I selected Lutron products because they integrate with IFTT (If This Then That). My family (myself included) are pretty poor about managing lights inside and outside our home. As a result, I decided to integrate SkyWeather2 sunlight measurements with IFTTT triggers to manage the outdoor lights on our home.
The integration is pretty simple and requires a fairly minimal amount of setup but does rely upon my favorite tool Node-RED. First and foremost, Lutron and IFTTT require accounts be setup prior to using either tools. Once the accounts are setup, a request within IFTTT to connect with Lutron Caséta must be performed.
Within the Lutron app, I created two scenes, Sunrise and Sunset. Sunrise turns the lights off and sunset turns them on. Since I connected IFTTT to Lutron, the two scenes were visible within IFTTT. Next I created two IFTTT applets using webhooks titled Sunrise and Sunset. I connected each web hook (or trigger) to actions that trigger the appropriate scene. Each webhook has a unique URL for triggering the desired applet.
Finally, I augmented the Node-RED flow that processes the telemetry from the WeatherRack2. I added a function that determines the action to take using the following code:
the function is connected to a switch that has three outputs: Do Nothing, Sunrise, and Sunset. Attached to the Sunrise and Sunset outputs on the switch are HTTP request nodes that call the appropriate URL created for the applets within IFTTT.
Thanks,
Jason
I've been slowly replacing light switches and fan controls in our home with Lutron Caséta products. I selected Lutron products because they integrate with IFTT (If This Then That). My family (myself included) are pretty poor about managing lights inside and outside our home. As a result, I decided to integrate SkyWeather2 sunlight measurements with IFTTT triggers to manage the outdoor lights on our home.
The integration is pretty simple and requires a fairly minimal amount of setup but does rely upon my favorite tool Node-RED. First and foremost, Lutron and IFTTT require accounts be setup prior to using either tools. Once the accounts are setup, a request within IFTTT to connect with Lutron Caséta must be performed.
Within the Lutron app, I created two scenes, Sunrise and Sunset. Sunrise turns the lights off and sunset turns them on. Since I connected IFTTT to Lutron, the two scenes were visible within IFTTT. Next I created two IFTTT applets using webhooks titled Sunrise and Sunset. I connected each web hook (or trigger) to actions that trigger the appropriate scene. Each webhook has a unique URL for triggering the desired applet.
Finally, I augmented the Node-RED flow that processes the telemetry from the WeatherRack2. I added a function that determines the action to take using the following code:
dayTime = flow.get("$parent.daytime");
sunlight = msg.payload.light;
action = "Do Nothing";
if (dayTime == undefined) {
// first time flow has been called
// dayTime not set in context
// set dayTime and trigger appropriate action
if (sunlight > 1000) {
flow.set("$parent.daytime", true)
// dayTime = true;
action = "Sunrise"
} else {
flow.set("$parent.daytime", false)
// dayTime = false;
action = "Sunset"
}
} else {
if (dayTime && sunlight <= 1000) {
// set dayTime to false
flow.set("$parent.daytime", false)
// trigger Sunset action
action = "Sunset"
/* } else if (dayTime && sunlight > 1000) {
action = "Do Nothing";
} else if (!dayTime && sunlight <= 1000) {
action = "Do Nothing"; */
} else if (!dayTime && sunlight > 1000) {
// set dayTime to true
flow.set("$parent.daytime", true)
// trigger Sunrise action
action = "Sunrise";
}
}
msg.payload = action;
return msg;
the function is connected to a switch that has three outputs: Do Nothing, Sunrise, and Sunset. Attached to the Sunrise and Sunset outputs on the switch are HTTP request nodes that call the appropriate URL created for the applets within IFTTT.
Thanks,
Jason