I’m trying to create a specific rule but the only option under the when section is “or” I don’t not want to “or” the rules together, I want to “and” them together. Well i would like to make a complex rule set for this.
The goal is to have the interior lights turn on when i come home from work during a narrow time frame using my phone as the trigger. once the rule has fired it should be locked out for some period of time to prevent random triggers.
what i have :
rule "Coming Home Lights"
//Channel "astro:sun:local:set#event" triggered START and
//Time cron "0 0 17 ? * MON,TUE,WED,THU,FRI *" //Monday - Friday after 7pm
//Time cron "0 0 18 ? * MON,TUE,WED,THU,FRI *" //Monday - Friday after 8pm
Item Presence_KeatonsPhone changed to ON // phone presence detection
logInfo("Light", "Kitchen light turned on by coming home rule")
if i was doing this in embedded C i would expect it to be something like
since "astro:sun:local:set#event triggered START " looks to be an even that is not persistence interrupt/flag i could use my other exterior light rule to set a flag bit and the off to clear the bit. I know there is an expire binding but i have not tried it yet.
The only way your C example would work is if it’s embedded in an endless loop just waiting for all conditions to be true, or have it in a function that gets called by something else.
The latter is (very simplified) how OH rules work, the rule body gets executed in response to an event, which can be a state change of an item, a channel trigger, a Cron trigger etc.
The thing about events is: they happen once, maybe trigger a rule, and then they’re gone. An if-statement (in any programming language) requires a state (of a variable, or an item in openhab) to compare to.
You can have an if-statement like that (except for the channel trigger since that’s an event), but that goes in the rule body, not in the trigger.
Sort of, you can’t use the events of the astro binding and the crown statements in this part.
However you can check whether the time now is after the sunset-time (I ca only guess that the astro binding does have a channel for that) and check if the time now is before or after the time of the cron statements.
looking at the example Rossko57 links to I have another question. maybe kinda dumb, has to do when using var vs val for assignment as i’m going to need it for time. I have a rule that does this and the VCS throws an error about the use of val
val DimmerValue = KitchenDimmer_SwitchDimmer. state as number
DimmerValue = DimmerValue +15
if (DimmerValue > 100)
DimmerValue = 100
if i think i understand what i’m doing/attempting, i basically creating a temp variable in the function, reading a state into the variable. doing changes to it. then limit checking the value before writing the value. I’m also doing the same in the other direction. so i cant have a number less than 0.