# Script dat melding stuurt als garagedeur openstaat totdat garagedeur wordt gesloten

**URL:** https://community.homey.app/t/script-dat-melding-stuurt-als-garagedeur-openstaat-totdat-garagedeur-wordt-gesloten/63356
**Category:** Flows
**Tags:** homeyscript, domoticz, javascript
**Created:** [May 6, 2022, 8:56pm UTC](https://community.homey.app/t/script-dat-melding-stuurt-als-garagedeur-openstaat-totdat-garagedeur-wordt-gesloten/63356 "2022-05-06T20:56:39Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Richard\_van\_Deursen](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/richard_van_deursen/32/47723_2.png) [@Richard\_van\_Deursen](https://community.homey.app/u/Richard_van_Deursen)
#### Post date: [May 6, 2022, 8:56pm UTC](https://community.homey.app/t/script-dat-melding-stuurt-als-garagedeur-openstaat-totdat-garagedeur-wordt-gesloten/63356/1 "2022-05-06T20:56:39Z")

</div>

Hallo,

Al jarenlang maak ik gebruik van Domoticz en momenteel ben ik aan het overswitchen naar Homey. In Domoticz had ik een script dat mij om de 4 minuten een melding stuurt als de garagedeur openstaat. Nu wil ik dezelfde functionaliteit in Homey. Kan iemand mij misschien verder helpen?

Alvast dank

Het script dat ik in Domoticz gebruikte:

commandArray = {}  
if (otherdevices[‘Garagedeur Script’]==‘On’) then

sensors = {‘Garagedeur’}  
– All times in minutes  
firstWarningTimeMinutes = 2  
– Then repeat every … minutes  
repeatTimeMinutes = 2

– First %s is the sensor name, the second one the time in minutes  
firstWarningMessage = ‘Info#Let op, “%s” staat al meer dan %s minuten open!’  
repeatWarningMessage = ‘Waarschuwing#LET OP, “%s” nog steeds open! Tijd open: %s minuten!!’

– Don’t edit below this line

firstWarningTime = firstWarningTimeMinutes \* 60  
repeatTime = repeatTimeMinutes \* 60

timeNow = os.time()

– commandArray = {}

for index,sensor in pairs(sensors) do  
s = otherdevices\_lastupdate[sensor]  
– 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)
 
timeLastOpened = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference = (os.difftime (timeNow, timeLastOpened))
if (otherdevices[sensor] ~= 'Open' or difference < firstWarningTime) then
    -- Door closed or within margin
    return commandArray
end

if (difference <= (firstWarningTime + 60)) then
    -- First warning
    commandArray['SendNotification'] = string.format(firstWarningMessage, sensor, tostring(firstWarningTimeMinutes))
else
    offset = (difference - firstWarningTime) % repeatTime
    if offset > 0 and offset <= 60 then
        commandArray['SendNotification'] = string.format(repeatWarningMessage, sensor, tostring(math.floor(difference / 60)))
    end
end

```

end  
return commandArray

end

---

<div class="post-metadata">

### Author: ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)
#### Post date: [May 7, 2022, 12:00am UTC](https://community.homey.app/t/script-dat-melding-stuurt-als-garagedeur-openstaat-totdat-garagedeur-wordt-gesloten/63356/2 "2022-05-07T00:00:36Z")

</div>

Ik weet wel hoe het met een flow kan…  
Als…  
iedere 4 minuten  
En…  
Sensoralarm garagedeur is On  
Dan…  
Stuur push bericht naar gebruiker A “Garagedeur staat nog open”

---

<div class="post-metadata">

### Author: ![Dijker](https://avatars.discourse-cdn.com/v4/letter/d/b9bd4f/32.png) [@Dijker](https://community.homey.app/u/Dijker)
#### Post date: [May 7, 2022, 9:56am UTC](https://community.homey.app/t/script-dat-melding-stuurt-als-garagedeur-openstaat-totdat-garagedeur-wordt-gesloten/63356/3 "2022-05-07T09:56:10Z")

</div>

> [@Peter\_Kawa](#):
>
> Als…  
> iedere 4 minuten

Jammer doe ik net de deur open seconde later… Ping: Garagedeur staat **nog** open

ik zou gaan voor drie flows en een Timer: (Naar wens aanpassen WELKE meldingen je wel wilt.)

Wel jammer dat in de gedeelde Flow het Custom Icon niet zichtbaar is:  
op mijn Dashboard / als Favorit Device in Homey App.

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/a/4/a473aa5f568b8af305bd34364c77124ac31bb222.png)

---

<div class="post-metadata">

### Author: ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)
#### Post date: [May 7, 2022, 1:02pm UTC](https://community.homey.app/t/script-dat-melding-stuurt-als-garagedeur-openstaat-totdat-garagedeur-wordt-gesloten/63356/4 "2022-05-07T13:02:39Z")

</div>

> [@Dijker](#):
>
> Jammer doe ik net de deur open seconde later… Ping: Garagedeur staat **nog** open

Ha, je hebt helemaal gelijk

---

<div class="post-metadata">

### Author: ![Richard\_van\_Deursen](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/richard_van_deursen/32/47723_2.png) [@Richard\_van\_Deursen](https://community.homey.app/u/Richard_van_Deursen)
#### Post date: [May 7, 2022, 2:24pm UTC](https://community.homey.app/t/script-dat-melding-stuurt-als-garagedeur-openstaat-totdat-garagedeur-wordt-gesloten/63356/5 "2022-05-07T14:24:23Z")

</div>

Het is me uiteindelijk gelukt met een aantal flows!  
Ik start met een variable timer=4 minuten

Deur open  
Als: deur open  
Dan: Start flow loop1 na 4 minuten

Loop1  
Als: Deze flow is gestart  
En : deur open  
Dan: Stuur notificatie 'Garagadeur staat ‘timer’ minuten open.  
Start flow loop2 na 2 minuten  
Bereken ‘timer’ als ‘timer + 2’

Loop2  
Als: Deze flow is gestart  
En : deur open  
Dan: Stuur notificatie 'Garagadeur staat ‘timer’ minuten open.  
Start flow loop1 na 2 minuten  
Bereken ‘timer’ als ‘timer + 2’

Garagedeur sluiten  
Als: deur dicht  
Dan: zet ‘timer’ naar 4

Wellicht bruikbaar voor anderen.  
Op deze manier is het mogelijk een loop te bouwen met flows.

---

<div class="post-metadata">

### Author: ![ChrisBoer](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/chrisboer/32/1252_2.png) [@ChrisBoer](https://community.homey.app/u/ChrisBoer)
#### Post date: [May 8, 2022, 2:46pm UTC](https://community.homey.app/t/script-dat-melding-stuurt-als-garagedeur-openstaat-totdat-garagedeur-wordt-gesloten/63356/6 "2022-05-08T14:46:21Z")

</div>

Ik gebruik een variabele en doe hem automatisch sluiten na 30 min en zet dan de variabele weer op “false”

Maar ik zet mijn auto niet in de garage, dan maakt het niet uit of hij plots dicht gaat er zit ook een beveilinging op maar toch niet fijn als hij dicht zou gaan als je net je auto erin rijdt dus hou hier rekening mee.
