[SOLVED]Tricky Rule - Question to Contact State and TTS Alexa...can`t find whats wrong

So i´m trying to get a Alarm Setting working on Openhab.
I have two Groups which are definied as CONTACT Groups

Group:Contact:OR(OPEN, CLOSED) Fensterdummy "Dummy Fenster Kontakt [(%d)]"
Group:Contact:OR(OPEN, CLOSED) Griffdummy   "Dummy Fenster Griff   [(%d)]"

I have a rule which checks if there is a State OPEN and send those Items via TTS to Alexa, so she tells me which Window(s) i have to close before leaving the House.

rule "alarm + fenster abfrage" 
  when 
    Item Testswitch3 received command ON
  then
    val OffeneFenster     =  Fensterdummy.members.filter[ i | i.state == OPEN ].map[ label ].reduce[ s, label | s + ", " + label ]
    val AngekippteFenster =  Griffdummy.members.filter[ i | i.state == OPEN ].map[ label ].reduce[ s, label | s + ", " + label ]

      if( Fensterdummy.state == "OPEN" || Griffdummy.state == OPEN)   {
        Testswitch3.postUpdate(OFF)
        EchoWohnzimmerTextToSpeech.sendCommand("Achtung, der Alarm wurde nicht aktiviert, da folgende Fenster noch geöffnet sind. " + AngekippteFenster + ", " + OffeneFenster)
      }
end

so now when both Groups are OPEN and i trigger the Rule

estswitch3 changed from OFF to ON

2019-10-18 13:17:42.500 [vent.ItemStateChangedEvent] - Testswitch3 changed from ON to OFF

2019-10-18 13:17:42.504 [ome.event.ItemCommandEvent] - Item 'EchoWohnzimmerTextToSpeech' received command Achtung, der Alarm wurde nicht aktiviert, da folgende Fenster noch geöffnet sind. Griff Wohnzimmer, Küchenfenster

everything is fine ( bothe Windows which are opened are correctly recognized via TTS)

When i close the Windows so my Group

Group:Contact:OR(OPEN, CLOSED) Fensterdummy "Dummy Fenster Kontakt [(%d)]"

switches to CLOSED (LOG)

Fensterdummy changed from OPEN to CLOSED through Fenster_Kuechedummy

and i trigger the rule again, i got some error in the TTS

Item 'Testswitch3' received command ON

2019-10-18 13:21:34.250 [ome.event.ItemCommandEvent] - Item 'EchoWohnzimmerTextToSpeech' received command Achtung, der Alarm wurde nicht aktiviert, da folgende Fenster noch geöffnet sind. Griff Wohnzimmer, null

i cant figure out why the hell she is always telling null...seems like my group is undef but its not
The group which is closed always end up in a NULL TTS…

Can somone help here pls ?

You can always add logInfo() to find out what value things have in your rule.

There’s something wrong there, if both Groups are Contact types. You don’t want to be comparing state with a string.

The null in your message seems to be the OffeneFenster variable that you created a few lines earlier.

val OffeneFenster = Fensterdummy.members.filter[ i | i.state == OPEN ]...

If none of the members are OPEN that part is going to return an empty list.
You’ll probably want to enhance your rule to supply a meaningful string like “none” or “okay” for that case.
Or amend your speech string building so that it doesn’t try to include an empty list.

1 Like

thank you for the Tips…i changed this but with no effect :frowning:

rule "alarm + fenster abfrage" 
  when 
    Item Testswitch3 received command ON
  then
    val OffeneFenster     =  Fensterdummy.members.filter[ i | i.state == OPEN ].map[ label ].reduce[ s, label | s + ", " + label ]
    val AngekippteFenster =  Griffdummy.members.filter[ i | i.state == OPEN ].map[ label ].reduce[ s, label | s + ", " + label ]

      if( Fensterdummy.state == OPEN || Griffdummy.state == OPEN)   {
        Testswitch3.postUpdate(OFF)
        EchoWohnzimmerTextToSpeech.sendCommand("Achtung, der Alarm wurde nicht aktiviert, da folgende Fenster noch geöffnet sind. " + AngekippteFenster + ", " + OffeneFenster)
      }
end

ending up with NULL…this is a test group with only one or two items. The Items are 100% CLOSED when the NULL Message comes out…maybe there is somethin wrong in my rule part

EchoWohnzimmerTextToSpeech.sendCommand("Achtung, der Alarm wurde nicht aktiviert, da folgende Fenster noch geöffnet sind. " + AngekippteFenster + ", " + OffeneFenster)

i have no clue what else i could try…

Don’t confuse NULL, the initial state that Items carry when they are first loaded, and null which means no result.

When all the Items are closed in, for example Fensterdummy, OffenFenster is going to be null. Since you include OffeneFenster in your TTS whether or not it’s null or not, you will get null in the TTS.

You need to check whether OffeneFenster is null or not and not include it in your TTS if it is null. You need to do the same for AngekippteFenster.

1 Like

In the example error message you showed us, there is an open window in one group and none in the other. You do want a message in that case, right? Just not the null part.

If you are now thinking you get the message with both groups all closed, please show that message.

1 Like

When both Groups are closed -nothing happens (i had an else part where he immediatley jumped to)
i solved this with dummy items and combined both groups into one contact group

rule "alarm + fenster abfrage" 
  when 
    Item Testswitch3 received command ON
  then
    val OffeneFenster     =  Fensterdummy.members.filter[ i | i.state == OPEN ].map[ label ].reduce[ s, label | s + ", " + label ]
      if( Fensterdummy.state == OPEN)   {
        Testswitch3.postUpdate(OFF)
        EchoWohnzimmerTextToSpeech.sendCommand("Achtung, der Alarm wurde nicht aktiviert, da folgende Fenster noch geöffnet sind. "  + OffeneFenster)
      }
end

This is the rule

rule "Fenstergriff Wohnzimmer"
when
    Item GriffWZ changed
then
    switch GriffWZ.state {
        case "OPEN": {
          GriffWZ_Dummy.sendCommand(OPEN)
        }
        case "TILTED": {
         GriffWZ_Dummy.sendCommand(OPEN)
        }
        case "CLOSED": {
         GriffWZ_Dummy.sendCommand(CLOSED)
        }
   }
end

rule "Fensterkontakt Wohnzimmer"
     when
       Item FenWohn changed
     then
       switch FenWohn.state {
         case "OPEN": {
            FenWohndummy.postUpdate("OPEN")         
    }
        case"CLOSED": {
            FenWohndummy.postUpdate("CLOSED")
            }
    }
end

Dummy-Item Rules

Contact      GriffWZ_Dummy  "Griff Wohnzimmer [MAP(kontakte.map):%s]"   <window> (Fensterdummy) 
Group:Contact:OR(OPEN, CLOSED) Fensterdummy "Dummy Fenster Kontakt [(%d)]"

This seems to work for me now…i got my response and don`t have any NULL message :slight_smile: