System Generated Commands vs User Generated Commands (Keeping Track of When User Overrides System)

Does Openhab offer a way to distinguish between a flick of a switch (by a user) versus a system generated command (from Rules / Code)?

Specifically, I am trying to automate lights to be switched “on” at dusk “&&” when user “presence” is detected. The Code for this is elsewhere on the forum.
However if user has decided they don’t want this feature to activate (i.e. going to bed early, yet still “present” for our purposes), is there a way to code this override?

Can consider a timer, but this gets unwieldy. For example, user switches lights off, yet a few minutes later the lights switch back on again as the system has identified that both Presence and Time Conditions are met. To solve this, if we have the user’s decision to switch the lights off being subject to a time limit - until the next day , that is fine, but what if they change their mind and switch the lights on again…?

Another alternative may be to create a variable “SystemTurnedOn=True/False”, however this seems tricky to implement in practice.

Please assume, for the sake of this question, that the solution does not lie in having a more sophisticated “Presence” condition (such as PIR in the room or similar) - though clearly this is a possibility I will need to think about.

Rules code so far as follows:

rule "lamp trigger to switch on when dark and someone home"
when
	Item Presence changed
then

	var Number hour = now.getHourOfDay 
	if ((hour >= 18) && (hour <= 23 ) && (Presence.state==ON))     
	{
		lamp1_Color.sendCommand(myColor)
		lamp2_Color.sendCommand(myColor)
		lamp_Timer.sendCommand(ON)
		logInfo("lamp_trigger.rules", "Presence and Time criteria are met: switching lamp on, with lamp timer")

	}	
end

Many thanks !

You can create a proxy switch and add it to your sitemap so you can control if the rule runs. Then place the proxy switch in your if statement.

Example:

rule "lamp trigger to switch on when dark and someone home"
when
	Item Presence changed
then

	var Number hour = now.getHourOfDay 
	if ((hour >= 18) && (hour <= 23 ) && (Presence.state==ON) && Proxy_switch.state==OFF)     
	{
		lamp1_Color.sendCommand(myColor)
		lamp2_Color.sendCommand(myColor)
		lamp_Timer.sendCommand(ON)
		logInfo("lamp_trigger.rules", "Presence and Time criteria are met: switching lamp on, with lamp timer")

	}	
end

See Design Pattern: Manual Trigger Detection for a couple additional ways to do this.