is it possible to create a rule with a delay and a second if check in it?
What i wanted to create is a rule that turn on a alarm switch when nobody is at home.
Rule should be clear:
rule "Alarmanlage automatisch"
when
Item person_1 changed or
Item person_2 changed
then
if ((person_1.state == OFF) && (person_2.state == OFF)) { // i know it could checked by an presence group
proxy_alarm.sendCommand(ON) }
else
proxy_alarm.sendCommand(OFF)
end
The problem i got is my presence detection. I am using network binding. But from time to time there is a really short offline to my iphones presence and a second later it switches back to online.
And yes, i am using arping and tested a lot with timeout and retries. Also chmod u+s is done to arping.
I am happy with network binding and it works really satisfactory to me, that really short offline switch is negligible for me (it’s really only 1 or 2 times a day) , but its enough to active the alarmsystem and everytime just in this short moment i am able to pass a motion detector
So, is there an option to create a rule with a short timer (30 seconds or so) with a check behind if both items really are offline?
Or do i have to create 2 rules???
rule "1"
when
Item person_1 changed or
Item person_2 changed
then
createTimer(now.plusSeconds(30)) [ check_state.sendCommand(ON) ]
end
rule "2"
when Item check_state received command ON
then if ((person_1.state == OFF) && (person_2.state == OFF)) {
proxy_alarm.sendCommand(ON) }
else
proxy_alarm.sendCommand(OFF)
end
Not sure what is wrong with this one but let me know if there is anything that I’d have to add or update to it to make it work,
Rule
when
Item gPhone changed from ON to OFF
then
createTimer(now.plusSeconds(30))
[
Mode.sendCommand(ECO) ]
end
In the above, the Mode is the Item name of my thermostat and I am sending it to go ECO which works fine in the UI but not sure If is working correctly.
Let me know if there is anything wrong with the code or what would be the update required on it.
The rule works fine in the PaperUI but obviously, I can’t add the Time Delay from there. Any help will be appreciated.
I have tried with off as well. Anyways none of my rules are working. I think something isn’t right but though one quick question, do we need to have items defined in items file if we want to use them in rules from command line. All of my items were created from the PaperUI, this might be a problem as well.
Okay. The best we can offer on that is - something is wrong.
Look in openhab.log and see what it tells you, maybe share that here if isn’t clear.
No, not at all. Whether your Items are created by PaperUI or xxx.items files makes no difference at all, they are all just Items when openHAB is running.
You do have to be careful about not having Items with same name from different sources though - only one would work.
Something wasn’t right and after the restart the remaining rules are working fine and I made some progress on the above as well but I think I may need some help in making it perfect.
The Use Case is that I’d like to check if my Phone is off then wait for 10 minutes and recheck if the Phone is still OFF then send a command to Turn the thermostat to ECO mode.
Right now, the wait is working fine but the inner condition isn’t working and this is probably something to do with syntax I think
The following works absolutely fine.
rule “Nest”
when
Item gPhone changed from ON to OFF
then
createTimer(now.plusSeconds(600), [
sendCommand(Thermostat_Mode,‘ECO’) ])
end
What I need is this and it is not working for some reason
rule “Nest”
when
Item gPhone changed from ON to OFF
then
createTimer(now.plusSeconds(600), [
if gPhone.state == OFF
sendCommand(Thermostat_Mode,‘ECO’) ])
end