The intention is to lock the door automatically at night (2 hours after the sunset and until sunrise). I want that to happen only when the person returns in the house (I was thinking to use the PIR sensor for that even though someone else's movement might be picked up) and more only if the battery level is over 30%.
I have created a rule 4.0 like this.
Trigger: When contact sensor is closed
Action: Lock the door.
Conditions: Time between Sunset + 120 minutes and Sunrise
Battery level of Door Lock is > 30
Entrance motion sensor active
Are all these conditions to be fulfilled to trigger the action (are they ANDed?)
Reading some of the other similar posts I realized that with a delay I might get a decently workable solution but still it bothers me I can't model what I want so any help would be appreciated.
None of them do anything unless you use them in the actions (via "Conditional Actions")--and there you can combine them however you want, with AND, OR, NOT, and any nesting you want (though too much gets hard to edit).
You're on the right track, but there are two things I'd consider:
How do you want to lock the door "automatically"? You could check at a specific time or after a specific event (e.g., after unlocking the door or after the contact sensor reports closing, both with or without a delay). This would most likely affect what triggers your rule.
How do you want to rest for returning to the house? I see you have one idea for that: entryway motion. If you don't want to wait very long before automatically locking the lock--specifically, during the time when the sensor may still be reporting "active" for motion--then that's probably a good proxy. If you have any presence devices, you could also use something based on whether those recently arrived. If your sensor might not still be reporting "active," you could also use a similar bit of extra work to tell if it's been active recently. (For either of these ideas, I'd suggest a global variable and another rule that sets that variable to a specific value when those things happen, then returns it to another value some time after; then use this variable as a condition in the other rule. Much easier than trying to do everything in the same rule.)
If you want to lock the door immediately after the contact sensor is closed but only if your conditions are met, your rule as-written would work in that way if you use the conditions in your actions...something like:
Trigger:Contact sensor closed
Actions:
IF (Time is between Sunset + 120 and Sunruse AND Battery of Door lock > 30 AND Entrace motion sensor is active) THEN
Lock door
END-IF
I realized after posting that there's a "conditional action". Initially I went directly adding a "lock" action on a "contact closed" trigger under certain conditions which of course doesn't work otherwise why would a separate "conditional action" be justified. Anyway, not saying it's easy to create a rule editor but it was a bit confusing, The flow and the drop downs are logical but still convoluted at the same time, it's a strange thing. I succeeded eventually to have my action triggered only at night and after a certain delay. I gave up on the presence sensor, not because it wouldn't work but because it wouldn't work properly for what I intended. The sensor will pick up anybody inside the house and allow the door to be locked "thinking" the person that got out briefly returned. The delay is working decently.