# Homeyscript über Öffnungszustand von Fenster und Türen

**URL:** <https://community.homey.app/t/homeyscript-uber-offnungszustand-von-fenster-und-turen/108449>\
**Category:** Flows (DE)\
**Created:** [April 19, 2024, 9:13am UTC](https://community.homey.app/t/homeyscript-uber-offnungszustand-von-fenster-und-turen/108449 "2024-04-19T09:13:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bernd\_77](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/bernd_77/32/82709_2.png) [@Bernd\_77](https://community.homey.app/u/Bernd_77)\
**Post date:** [April 19, 2024, 9:13am UTC](https://community.homey.app/t/homeyscript-uber-offnungszustand-von-fenster-und-turen/108449/1 "2024-04-19T09:13:47Z")

</div>

Hallo miteinander,

ich habe folgendes Script in diesen Foren gefunden, welches ich einem Flow verwende:

```auto
// Check if certain doors or windows is open?

let devices = await Homey.devices.getDevices();
let windowText = "";
let currentText = "";
let logText = "";
let windowOpen = false;

_.some(devices, device => 
{
if ( device.class == 'sensor' ) 
// device.class is found at https://tools.developer.homey.app/tools/devices
  {
  if( device.capabilitiesObj &&
  device.capabilitiesObj.alarm_contact &&
  device.capabilitiesObj.alarm_contact.value )
    {
    currentText = "";
    // to compare and see if there is no typing error
    //console.log(`- Open door/window script check: \nName: ${device.name} \nZone: ${device.zone} \n(ZoneName: ${device.zoneName}) \n[device.class: ${device.class} \ndevice.capabilities: ${device.capabilities}]`); 

      if(device.name != ""){
      windowOpen = true;
      if(windowText=="")
      windowText = device.name + "\t(Zone: " + device.zoneName + ")";
      
      else
      windowText = windowText + "\n" + device.name + "\t(Zone: " + device.zoneName + ")";
      }
    }
  }
});

if(windowOpen == true)
windowText = "\nDiese Türen oder Fenster sind offen:\n" + windowText + "\n";
else
// comment this out if you don't want a msg when all's fine:
windowText = "Alle Türen und Fenster sind geschlossen.";

Homey.flow.runFlowCardAction({
        uri: 'homey:manager:notifications',
        id: 'create_notification',
        args: {
          text: windowText + '\n[Bernd Unterwegs - Tür/Fenster Offen Meldung]'
        },
      });

//just to check
console.log("\nOutput:", windowText);

// Create / update HomeyScript variabele
await tag("door_windowText", windowText);

return (true);

```

Als Ausgabe gibt er bei einem Test folgendes aus:

Output:  
Diese Türen oder Fenster sind offen:  
Tür Garage (Zone: undefined)

———————————————————  
✅ Script Success  
↩ Returned: true

Die Meldung ist korrekt, die “Tür Garage” ist offen, so wurde die Tür von mir benannt.

Was muss ich im Script aber verändern, dass die Meldung _“(Zone: undefined)”_ nicht erscheint, sonder die Zone mit angegeben wird?

Gibt es eigentlich irgendwo Hilfe zu Verwendung und Programmierung in Homeyscript?

Vielen Dank

---

<div class="post-metadata">

**Author:** ![Rmb](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/rmb/32/79135_2.png) [@Rmb](https://community.homey.app/u/Rmb)\
**Post date:** [April 19, 2024, 12:09pm UTC](https://community.homey.app/t/homeyscript-uber-offnungszustand-von-fenster-und-turen/108449/2 "2024-04-19T12:09:31Z")

</div>

Erstellen Sie eine Garage-Zone und stecken Sie das Garagentor hinein.  
Oder löschen Sie im Code alles, was mit „Zone“ zu tun hat.

> **[My Homey](https://my.homey.app/homeys/645f7f4e5d66a50b8eb3e160/scripts)**
>
> Homey Web App

---

<div class="post-metadata">

**Author:** ![RonnyW](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ronnyw/32/10879_2.png) [@RonnyW](https://community.homey.app/u/RonnyW)\
**Post date:** [April 19, 2024, 12:37pm UTC](https://community.homey.app/t/homeyscript-uber-offnungszustand-von-fenster-und-turen/108449/3 "2024-04-19T12:37:56Z")

</div>

Wenn ich mich richtig erinnere, hat Athom die API geändert. Man kann nun nicht mehr direkt den Zonenname aus dem Gerät lesen.

Wenn der Text stört, dann erstmal diese Zeile

```auto
      windowText = windowText + "\n" + device.name + "\t(Zone: " + device.zoneName + ")";

```

ersetzen durch diese:

```auto
      windowText = windowText + "\n" + device.name;

```

Wenn du die Zone benötigst, dann muss die nochmal mit einem separaten API-Aufruf über die ID gelesen werden. Müsste ich mir später man anschauen…

---

<div class="post-metadata">

**Author:** ![RonnyW](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ronnyw/32/10879_2.png) [@RonnyW](https://community.homey.app/u/RonnyW)\
**Post date:** [April 19, 2024, 12:44pm UTC](https://community.homey.app/t/homeyscript-uber-offnungszustand-von-fenster-und-turen/108449/4 "2024-04-19T12:44:21Z")

</div>

Bitteschön 🕶

```auto
// Check if certain doors or windows is open?

let devices = await Homey.devices.getDevices();
let zones = await Homey.zones.getZones();

let windowText = "";
let currentText = "";
let logText = "";
let windowOpen = false;

_.some(devices, device => 
{
if ( device.class == 'sensor' ) 
// device.class is found at https://tools.developer.homey.app/tools/devices
  {
  if( device.capabilitiesObj &&
  device.capabilitiesObj.alarm_contact &&
  device.capabilitiesObj.alarm_contact.value )
    {
    currentText = "";
    // to compare and see if there is no typing error
    //console.log(`- Open door/window script check: \nName: ${device.name} \nZone: ${device.zone} \n(ZoneName: ${device.zoneName}) \n[device.class: ${device.class} \ndevice.capabilities: ${device.capabilities}]`); 

      if(device.name != ""){
        let zone = zones[device.zone];
        windowOpen = true;
        if(windowText=="")
          windowText = device.name + "\t(Zone: " + zone.name + ")";        
        else
          windowText = windowText + "\n" + device.name + "\t(Zone: " + zone.name + ")";
      }
    }
  }
});

if(windowOpen == true)
windowText = "\nDiese Türen oder Fenster sind offen:\n" + windowText + "\n";
else
// comment this out if you don't want a msg when all's fine:
windowText = "Alle Türen und Fenster sind geschlossen.";

Homey.flow.runFlowCardAction({
        uri: 'homey:manager:notifications',
        id: 'create_notification',
        args: {
          text: windowText + '\n[Bernd Unterwegs - Tür/Fenster Offen Meldung]'
        },
      });

//just to check
console.log("\nOutput:", windowText);

// Create / update HomeyScript variabele
await tag("door_windowText", windowText);

return (true);

```

---

<div class="post-metadata">

**Author:** ![Bernd\_77](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/bernd_77/32/82709_2.png) [@Bernd\_77](https://community.homey.app/u/Bernd_77)\
**Post date:** [April 19, 2024, 4:48pm UTC](https://community.homey.app/t/homeyscript-uber-offnungszustand-von-fenster-und-turen/108449/5 "2024-04-19T16:48:45Z")

</div>

Vielen Dank Ronny!  
Das ist die Lösung. Jetzt zeigt er die offene Garagentür in der Zone Garage richtig an.

Diesen Teil habe noch gelöscht (der wurde von mir nicht gebraucht):

```auto
Homey.flow.runFlowCardAction({
        uri: 'homey:manager:notifications',
        id: 'create_notification',
        args: {
          text: windowText + '\n[Bernd Unterwegs - Tür/Fenster Offen Meldung]'
        },
      });

```

Falls es jemanden interessiert, ist hier ein möglicher Flow dazu (das Script wurde als kontakte-pruefung gespeichert):

![Bildschirmfoto 2024](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/d/0/d0e4488ad740aa88f14cdf6ce6682f47f1a762dc.png)
