Turn Lights On Only if After Sunset and If Presence is Detected

Hi guys, as per title, I want my lights to turn on any time during the night after sunset but before sunrise, and if it detects my phone is present through Network Binding. How would I go about doing this? I’ve got Astro Binding, but am not sure what channel event to use. I’ve got this so far:

rule "gOfficeLights ON"
when
	Channel 'astro:sun:local:civilDusk#event' triggered END
then
	if Item Presence_Sony_Xperia_X changed from OFF to ON
	{
	sendCommand(gOfficeLights, ON)
	}
end

Thanks in advance!

This post from 3h ago should also solve your question:

https://community.openhab.org/t/automation-orchestration-design-patterns/1967

Checkout this thread and see if helps you.

Thanks guys, yes I’ve read those posts but none say if I were to sense the presence of a phone as well as any time after sunset but before sunrise.

You needed to go one more level down to understand how to set a virtual switch to track time of day status Design Pattern: Time Of Day

And there are a number of threads on iPhone e presence detection like this (search is your friend) for determining changes in presence BEGINNER Guide to iPhone Presence?

Then it’s a straight forward rule to trigger on a change in time of day status or presence change and then verify in your rule that all conditions are true to turn on the lights.

Thanks. The presence detection is no worries, I’ve got that sorted. It was the Night Mode state which I just found how to do here: Time of Day Events

So long story short, I think it’s working now! When Night Mode is activated, phone is detected to be ON, the Office Lights switch on. Will check tomorrow if Night Mode has turned itself off.

Cheers!