Configuring Smart Lighting Automation with PIR Sensors

I recently set up a PIR sensor using a Sonoff basic switch connected to my existing light relay, all managed through OpenHAB. While the setup works, I’ve encountered an issue where the PIR sensor doesn’t distinguish between day and night, causing the lights to activate continuously. This has been quite frustrating, especially during daylight hours when the lights shouldn’t be triggered at all.

My initial thought was to create a time-based rule in OpenHAB or Node-RED that disables the GPIO of the Sonoff switch during daylight hours. I considered integrating sunrise and sunset data from the Yahoo Weather API to automate this process. However, I’m not entirely sure if this approach will work seamlessly or if there are better alternatives.

I reached out to the community for suggestions, and several members recommended exploring OpenHAB’s built-in scheduling capabilities combined with the PIR sensor’s state. One user suggested using a rule that checks the current time and disables the sensor during daylight hours. Another idea was to use a separate light sensor to detect ambient light levels and adjust the PIR sensor’s sensitivity accordingly.

After some experimentation, I found that combining a simple time-based rule with the PIR sensor’s state provided the most reliable solution. Here’s a snippet of the rule I created:

plaintext
rule “Disable PIR during Daylight”
when
Time cron “0 7 * * *” // Enable PIR at 7 AM
then
sendCommand(Sonoff_GPIO, ON)
end

rule “Enable PIR at Night”
when
Time cron “0 19 * * *” // Disable PIR at 7 PM
then
sendCommand(Sonoff_GPIO, OFF)
end

This setup ensures that the PIR sensor only activates during nighttime, preventing unnecessary light activations during the day. I’m still exploring ways to refine this further, perhaps by integrating real-time weather data for more accurate sunrise and sunset times.

If anyone has additional tips or alternative approaches, I’d love to hear them! The community’s support has been invaluable in helping me optimize my smart lighting system.