Just coming back to this as I’ve implemented some of my light control and have refactored it a bit since my suggestion above that I think achieves the same result but has less rules and coupling hence I think is simpler.
Some possible reasons for controlling the light, fed from different sensor data:
Front Door opened
Hall PIR opened
Security system - normally presence off and just simulating activity
Manual override
Alarm triggered
At the top level I have a Group Switch with AND(ON,OFF) so All ON is ON else OFF:
Group:Switch:AND(ON,OFF) grp_Landing_Lights_Proxy "Landing Lights Proxy [%s]" <light> (grp_House)
The proxy group is bound to my physical light switch so ultimately its state defines whether the light is ON or OFF. I’ve only put two sub items in to this main proxy group, an Auto switch:
Switch swt_Landing_Lights_Auto "Landing Lights Auto [%s]" <light> (grp_Switches, grp_Landing_Lights_Proxy)
For me the Auto item will be set ON 99% of the time. If your light is in a bedroom and you wanted to turn off the light this is the item you use to turn the light OFF. I expect I’ll use it for ‘alarm triggered’ conditions so I can flash the lights.
The second sub item of the proxy group is actually another Group Switch, this time OR based and ON if any ON else OFF:
Group:Switch:OR(ON,OFF) grp_Landing_Lights_OR "Landing Lights OR [%s]" <light> (grp_Landing_Lights_Proxy)
Previously I was chasing the state of the light to put it back on in cases where one of the activities had possibly also changed state. Now each activity based rule only deals with controlling its own switch state so I’ve got these switch items in the sub group:
Switch swt_Landing_Lights_PIR "Landing Lights PIR [%s]" <light> (grp_Switches, grp_Landing_Lights_OR)
Switch swt_Landing_Lights_Manual "Landing Lights Manual [%s]" <light> (grp_Switches, grp_Landing_Lights_OR)
Switch swt_Landing_Lights_Sec "Landing Lights Security [%s]" <light> (grp_Switches, grp_Landing_Lights_OR)
The PIR and security rules only deal with their appropriate switch item, they don’t care about anything else that is going on. I’ve put the Manual switch on my UI devices so people can turn ON the lights if they need to i.e. sitting reading when the PIR times out.
So although not technically a single Tri-State item it can meet the requirements:
ON - set Auto and Manual items ON
AUTO - set Auto ON and Manual OFF
OFF - set Auto OFF
you could also front your UI with a Tri-State widget that mapped it down to those settings.
Note: My lights are one way so binding to the Group is fine but if you have lights that feedback and bind to a Switch Item I guess you will need to make some changes. Maybe have another item outside of these groups which is bound to the light and some rules to sync them appropriately with the Manual item.