Sonoff RF 433, PIR and FloodLight, only enable light when PIR goes ON and time is night

Hi, I am new on Openhab2 and I still trying to create a rules which is doing this:

Hardware: Sonoff RF 433 (Tasmota), PIR CT60M, Novotella Floodlight (Tasmota)

When the PIR is detecting motion (Switch goes to ON)
And it is in the night and dark

->
power on the Floodlight for one minute

when the night is over do not power on the floodlight.

My rule without reagarding the night hours are working, but I don’t get it this working with the night hours…

var Timer tLicht = null

rule “Bewegungsmelder”
when
Item TasBridge01_Bewegung01 received update ON

then
tLicht?.cancel
if(TasFlood01_PowerSwitch.state != ON) TasFlood01_PowerSwitch.sendCommand(O$
tLicht = createTimer(now.plusMinutes(1), [
if(TasFlood01_PowerSwitch.state != OFF) TasFlood01_PowerSwitch.sendComm$

])

end

I did something similar, but not mqtt.
I have a Switch Item named IsItDark that is controlled by rules using the astro binding. I use the expire1 binding for a timer Item (5 minutes, in my case).
My PIR rule checks the switch status. I am not where I have access to my rules right now.
Motion within my timer period resets the timer Item and starts the timer again.

I am using Z-Wave devices but these ideas should work for you.

I’ve done this in a rule:

rule “Bewegungsmelder”
when
    Item TasBridge01_Bewegung01 received update ON
then
    var vCurrentHour = now.getHourOfDay()

    if(vCurrentHour < 5 || vCurrentHour > 19){
        //Do stuff at night time
    }
end

My night time is defined as 1900hrs until 0500hrs in the morning…

With the Astro binding instalkled you can have an item

String Day_Phase_String {channel="astro:sun:home:phase#name"}

Then you can check for

If (Day_Phase_String == "night") {
…

or

If (Day_Phase_String != "daylight") {
…

depending on how you want to proceed with the twilights.

2 Likes

There are many definitions for dawn & dusk though and my method lets you choose :wink:

Sorry @Bruce_Osborne, was meant as a reply for @Nutzer_Abgemeldet.

I agree though, and I use an outdoor Lux sensor, as depending on the weather condition, time of year and location of the whole setup you can’t really rely 100% on and astro calculations to determine the actual outdoor brightness.

To keep it simple in the beginning, the Astro binding direct method might be a good point to get @Nutzer_Abgemeldet started :slight_smile:

In general though, the civil twilights are when you can see quite nicely, so a separate rule to turn on and off an IsItDark item, which can then be used for other rules like this case is an option.

1 Like

Another advantage of the virtual switch is you can test whenever you want by triggering manually. :smiley:

Things

Thing   astro:sun:home              [ geolocation="xx.xx,yy.yy,zz", interval=60 ] {
    Channels:
        Type rangeEvent : civilDusk#event
        Type rangeEvent : civilDawn#event
}

then with rules setting the IsItDark item to ON and OFF

rule "Civil Dusk"
when
	Channel 'astro:sun:home:civilDusk#event' triggered END 
then
       IsItDark.sendCommand(ON)
       // IsItDark.postUpdate(ON)
end

rule "Civil Dawn"
when
	Channel 'astro:sun:home:civilDawn#event' triggered START 
then
       IsItDark.sendCommand(OFF)
       // IsItDark.postUpdate(OFF)
end

wow, so much replies. great. it is really difficult to find the right way if are new with this topic :wink:
thnks…

1 Like

Setting location in the paper ui means you can skip the geolocation part.

Welcome.
I figured it out by searching here.

1 Like

Items:

Switch IsItDark <moon>
Switch zooz_papillon_motion "Zooz Papillon Motion [%s]" <motion> (papillon_yard) { channel="zwave:device:16ddbcdbd38:node20:alarm_motion" }}
Switch papillon_light "Papillon Light [%s]" <light> (papillon_yard) { channel="zwave:device:16ddbcdbd38:node15:switch_dimmer" }
Switch PapTimer { expire="5m,command=OFF" }

rules

rule "Sunset"
when
    Channel 'astro:sun:local:civilDusk#event' triggered START
then
    IsItDark.postUpdate(ON)
end

rule "Sunrise"
when
    Channel 'astro:sun:local:civilDawn#event' triggered START
then
    IsItDark.postUpdate(OFF)
end

rule "Papillon Motion On"
when
    Item zooz_papillon_motion changed from OFF to ON
then
    if (IsItDark.state == ON) {
        papillon_light.sendCommand(ON)
        // start Timer
        PapTimer.sendCommand(ON)
    }
end

rule "Papillon Motion Off"
when
    Item PapTimer changed from ON to OFF
then
    papillon_light.sendCommand(OFF)
end