Door open blockly troubles

Post Reply
Mace
Posts: 67
Joined: Monday 21 August 2017 19:52
Target OS: Windows
Domoticz version: 3.8153
Location: Rhoon
Contact:

Door open blockly troubles

Post by Mace » Wednesday 18 October 2017 14:59

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 668 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 668 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?

Mace
Posts: 67
Joined: Monday 21 August 2017 19:52
Target OS: Windows
Domoticz version: 3.8153
Location: Rhoon
Contact:

Re: Door open blockly troubles

Post by Mace » Saturday 21 October 2017 20:03

No one a clue?

Amsterdam020
Posts: 49
Joined: Saturday 05 March 2016 22:42
Target OS: Raspberry Pi
Domoticz version: 3.5629
Contact:

Re: Door open blockly troubles

Post by Amsterdam020 » Saturday 21 October 2017 21:21

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
Rp3, youlesss, rfxcom, philips hue, dsb1820

Mace
Posts: 67
Joined: Monday 21 August 2017 19:52
Target OS: Windows
Domoticz version: 3.8153
Location: Rhoon
Contact:

Re: Door open blockly troubles

Post by Mace » Sunday 22 October 2017 13:29

Thanks! Totally looked over that. Removed the "Door sensor Test'= open from the second script, now it works!

Slinkos
Posts: 106
Joined: Thursday 10 December 2015 1:21
Target OS: Raspberry Pi
Domoticz version: 3.4834
Location: Netherlands
Contact:

Re: Door open blockly troubles

Post by Slinkos » Tuesday 24 October 2017 11:18

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.

freijn
Posts: 178
Joined: Friday 23 December 2016 17:40
Target OS: Raspberry Pi
Domoticz version:
Location: Netherlands Purmerend
Contact:

Re: Door open blockly troubles

Post by freijn » Tuesday 24 October 2017 14:08

I have done this in Lua. See the Lua GarageDoor example.. in the wiki

Mace
Posts: 67
Joined: Monday 21 August 2017 19:52
Target OS: Windows
Domoticz version: 3.8153
Location: Rhoon
Contact:

Re: Door open blockly troubles

Post by Mace » Tuesday 24 October 2017 21:07

@slinkos: Found that out...;) Can you tell me more about a good time script for this?

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

Slinkos
Posts: 106
Joined: Thursday 10 December 2015 1:21
Target OS: Raspberry Pi
Domoticz version: 3.4834
Location: Netherlands
Contact:

Re: Door open blockly troubles

Post by Slinkos » Tuesday 24 October 2017 23:15

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
Last edited by Slinkos on Tuesday 24 October 2017 23:21, edited 1 time in total.

Slinkos
Posts: 106
Joined: Thursday 10 December 2015 1:21
Target OS: Raspberry Pi
Domoticz version: 3.4834
Location: Netherlands
Contact:

Re: Door open blockly troubles

Post by Slinkos » Tuesday 24 October 2017 23:17

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'.

Mace
Posts: 67
Joined: Monday 21 August 2017 19:52
Target OS: Windows
Domoticz version: 3.8153
Location: Rhoon
Contact:

Re: Door open blockly troubles

Post by Mace » Saturday 28 October 2017 15:02

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

Slinkos
Posts: 106
Joined: Thursday 10 December 2015 1:21
Target OS: Raspberry Pi
Domoticz version: 3.4834
Location: Netherlands
Contact:

Re: Door open blockly troubles

Post by Slinkos » Tuesday 31 October 2017 10:31

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?

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests