Page 1 of 1

Door open blockly troubles

Posted: Wednesday 18 October 2017 14:59
by Mace
Trying to get the following working: If the front door is open for longer then 1 minute, play a sound thru the Xiaomi gateway en send an alert.
These are my blockly's:
Set door open.PNG
Set door open.PNG (11.21 KiB) Viewed 3542 times
As I don't want an alert everytime the door is opened for a short time, I first set a trigger when the door is open for a longer period (for test sake 10 seconds).
If I just use this script, the 'Door open switch' is triggered after 10 seconds.

Then the actual action :
Door open.PNG
Door open.PNG (52.94 KiB) Viewed 3542 times
I get a notification that the door is open, but the 'Door open switch' doesn't get triggered anymore, I see that the Xiaomi Gateway Doorbell is triggered, but get no sound. I do get the notification that the door is open, but not that it is closed again when I close the testdoor again.

Doing something wrong, but what?

Re: Door open blockly troubles

Posted: Saturday 21 October 2017 20:03
by Mace
No one a clue?

Re: Door open blockly troubles

Posted: Saturday 21 October 2017 21:21
by Amsterdam020
In the test you set the door open switch.
If door open set door open switch.

In your second script you have...
If door sensor open AND switch open.
THEN

This situation does not exist because you do not set the switch to open like in the first working script.

I am not an expert. Hope it helps

Re: Door open blockly troubles

Posted: Sunday 22 October 2017 13:29
by Mace
Thanks! Totally looked over that. Removed the "Door sensor Test'= open from the second script, now it works!

Re: Door open blockly troubles

Posted: Tuesday 24 October 2017 11:18
by Slinkos
Still this will not work, because the door open switch will be set to 'On' after 10 seconds anyway, even if you close the door before the 10 seconds have passed. Instead you should use a time script.

Re: Door open blockly troubles

Posted: Tuesday 24 October 2017 14:08
by freijn
I have done this in Lua. See the Lua GarageDoor example.. in the wiki

Re: Door open blockly troubles

Posted: Tuesday 24 October 2017 21:07
by Mace
@slinkos: Found that out...;) Can you tell me more about a good time script for this?

@freijn: Thanks, I'll look into that!

Re: Door open blockly troubles

Posted: Tuesday 24 October 2017 23:15
by Slinkos
Yes, with the GarageDoor example as freijn says. So in your case it would look like this:

Code: Select all

-- script_time_dooropen.lua
t1 = os.time()
s = otherdevices_lastupdate['Door open switch']
-- returns a date time like 2013-07-11 17:23:12
 
year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)
 
commandArray = {}
 
t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference = (os.difftime (t1, t2))
if (otherdevices['Door open switch'] == 'On' and difference > 10 and difference < 20) then
   commandArray['SendNotification']='Door is open#Door is open for more than 10 seconds!'
   print("Door is open")
end 
 
return commandArray
What this does, is that it compares the last update time of your switch, with the current time. If that is more than 10 seconds, it will send you a notification. The <20 is so that you only get notificated once, because 20/30/40/whatever seconds is also more than 10.

Now there is a problem with this script, because it runs every minute, there's a good chance that by the time it runs, the last update is more than 20 seconds in the past. So you should consider in changing your "less than value" to < 65 seconds, that's the minimum for this to work.

Here's your code that should work:

Code: Select all

-- script_time_dooropen.lua
t1 = os.time()
s = otherdevices_lastupdate['Door open switch']
-- returns a date time like 2013-07-11 17:23:12
 
year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)
 
commandArray = {}
 
t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference = (os.difftime (t1, t2))
if (otherdevices['Door open switch'] == 'On' and difference > 10 and difference < 65) then
   commandArray['SendNotification']='Door is open#Door is open for more than 10 seconds!'
   print("Door is open")
end 
 
return commandArray

Re: Door open blockly troubles

Posted: Tuesday 24 October 2017 23:17
by Slinkos
Actually, I used your "Door open switch" in my example. But you no longer need to use that switch off course. You should just change that to the name of your door sensor. And maybe replace 'On' with 'Open'.

Re: Door open blockly troubles

Posted: Saturday 28 October 2017 15:02
by Mace
Thanks for the help! I tested it, but I don't get a message after 60 seconds. Where should this be send to? In the log?

And preferably, I would like it that a switch is actually triggered, so I can work with this switch in Blockly

Re: Door open blockly troubles

Posted: Tuesday 31 October 2017 9:31
by Slinkos

Code: Select all

commandArray['SendNotification']='Door is open#Door is open for more than 10 seconds!'
should be doing the same as the send notification in yout blocky.

Code: Select all

print("Door is open")
should appear in your domoticz log, do you see that one?