[SOLVED] Getting notifications every 30 sec till the door will be closed

Hi

the goal is simple, i have a door sensor. i want to be alerted by telegram and chromecast if the door is opened more than one minute and a get a reminder every 30 sec till the door will be closed

    rule "door opened"
    when
    	Item mqtt_sensor_door changed
    then


    	if (Motion_Enable_Switch.state == OFF) return;
  		if(previousState == NULL) return;
		if(mqtt_sensor_door.state == "CLOSED") return;

		logInfo("GroupTest", "Door is opened")			                      
		
		Thread::sleep(20)	

		if(mqtt_sensor_door.state == "OPEN"){
// i never got the log above. that's the issue
			logInfo("GroupTest", "Door is STILL opened")			                      

			if(Bot6_Enabled.state == ON){sendTelegram("bot6","Close the door" )}
			if (VoiceOutput_Switch.state == OFF ){ say("Close the door")}
			logInfo("GroupTest", "Done")			                      

		}
end

the validation of the current state seems to not working. moreover, i have some issues to structure this loop.

your help will be more than appreciated!

G

I assume that your door_sensor is a contact sensor in that case the states are OPEN or CLOSED, no quotes
Add some logInfo statements to find out where the rule exits…
Use a time for the first minute
We’ll deal with the repeat every 30 seconds later
I also tidied up because your indents were a mess

rule "door opened"
when
    Item mqtt_sensor_door changed
then
    logInfo("GroupTest", "TEST 1")
    if (Motion_Enable_Switch.state == OFF) return;
    logInfo("GroupTest", "TEST 2")
    if (previousState == NULL) return;
    logInfo("GroupTest", "TEST 3")
    if (mqtt_sensor_door.state == CLOSED) return;
    logInfo("GroupTest", "Door is opened")

    createTimer(now.plusMinutes(1), [ |
        if(mqtt_sensor_door.state == OPEN) {
            // i never got the log above. that's the issue
            logInfo("GroupTest", "Door is STILL opened")			                      
            if(Bot6_Enabled.state == ON) { 
                sendTelegram("bot6","Close the door" )
            }
            if (VoiceOutput_Switch.state == OFF ) {
                say("Close the door")
            }
            logInfo("GroupTest", "Done")			                      
        }
    ])
end
1 Like

[quote=“vzorglub, post:2, topic:52422”]

Thank you , it worked
could you help me on the loop ?

2018-09-27 15:13:47.054 [INFO ] [pse.smarthome.model.script.GroupTest] - TEST 1
2018-09-27 15:13:47.067 [INFO ] [rthome.model.script.Rule File:MOTION] - group motion
2018-09-27 15:13:47.073 [INFO ] [pse.smarthome.model.script.GroupTest] - TEST 2
2018-09-27 15:13:47.082 [INFO ] [pse.smarthome.model.script.GroupTest] - TEST 3
2018-09-27 15:13:47.088 [INFO ] [pse.smarthome.model.script.GroupTest] - Member mqtt_sensor_door to OPEN
2018-09-27 15:13:47.096 [INFO ] [pse.smarthome.model.script.GroupTest] - Door is opened
2018-09-27 15:14:10.431 [INFO ] [pse.smarthome.model.script.GroupTest] - Door is STILL opened

Ok,

You need to add the following line at the TOP of your rules file:

var Timer timer = null

Then your rule becomes:

rule "door opened"
when
    Item mqtt_sensor_door changed
then
    if (Motion_Enable_Switch.state == OFF) return;
    if (previousState == NULL) return;
    if (mqtt_sensor_door.state == CLOSED) return;
    logInfo("GroupTest", "Door is opened")

    if (timer === null) {
        timer = createTimer(now.plusMinutes(1), [ |
            if(mqtt_sensor_door.state == OPEN) {
                logInfo("GroupTest", "Door is STILL opened")			                      
                if(Bot6_Enabled.state == ON) { 
                    sendTelegram("bot6","Close the door" )
                }
                if (VoiceOutput_Switch.state == OFF ) {
                    say("Close the door")
                }
                timer.reschedule(now.plusSeconds(30)) // Do it again in 30 seconds
            } else {
                timer = null    // cancels the timer
            }
        ])
    }
end

Thanks a lot !