hello everyone. I have a problem with rule machine. I'm doing it for the first time but it seems to me that it should work in this form as in screenshots
when gate contact sensor is open - google home speaks (gate open)
when gate contact sensor is closed - google home speaks (gate closed)
when gate contact or motion sensor is active / open - turn on lights
when gate contact and motion sensor is inactive/close - turn off lights
I don't know why it doesn't work. google home only informs about the opening of the gate and not about closing, and the lights do not turn on when the gate is opened
So here's part of the problem... your rule triggers when the contact switch opens. But if the contact switch closes the rule doesn't get triggered. Same with the motion sensor - triggers on activity but won't trigger on inactivity.
And then there's the endif issue.
It might be simpler to break this into 4 separate rules... or even use the room lighting app instead of RM.
So should i add
-sonoff (contact closed)
-hue sensor (motion inactive) to trigger Events?
I don't know how to write such formulas with endif
About room lightning app, you mean just "room lightning" on "motion and mode lightning" app ?
So think of it this way... rules are triggered by events - when something happens. When that thing happens, the rule processes all of its actions in rapid succession. If you have a trigger event that is the gate opens, and an if statement later that checks to see if the gate is closed, unless the gate opens and then closes within milliseconds, the gate will never be closed while the rule is running. (Unless you use a WAIT command but that's a bit different.) All of your IF statements are executed when the trigger event happens, too. So the gate can't be open one millisecond and closed the next.
So if you want Google to speak when the status of the gate changes you could have a rule that has contact sensor changes as its trigger, and then a statement that goes something like this:
If contact sensor is open
google says gate is open
else
google says gate is closed
endif
Or you could say
if contact sensor is open
google says gate is open
endif
if contact sensor is closed
google says gate is closed
endif
And yes I meant Room Lighting. It has all the capability of controlling lights based on motion and contact sensors. But you can certainly do it in RM if you'd prefer.
To make your rule cleaner, I'd change the triggers to
Hue Czujnik ruchu 3 motion *changed*
OR
Czujnik sonoff 1 contact *changed*
Your second posted rule will announce "the entrance gate was closed" when the motion goes active or inactive. From your first post, I don't think that is what you want. I'd remove the motion sensor as a trigger.
I've had some rules that would not reliably trigger using the *changed* criteria. For those rules I've had to define triggers for each separate state (ie. Separated triggers for Open and Closed).
You could also probably simplify each rule even more (few or no IF statements) by splitting the triggers and combining actions.
Rule 1A Trigger: contact open OR motion active
Rule 1A Actions: turn On mhcozy, speak "gate open."
Rule 1B Trigger: contact closed OR motion inactive
Rule 1B Actions: turn Off mhcozy, speak "gate closed."
In most cases, it is easier to write and maintain several simple rules rather than one "do everything" rule.