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.
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…
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
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.
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
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