Design Pattern: Working with Groups in Rules

groups
designpattern
Tags: #<Tag:0x00007f01484b2d50> #<Tag:0x00007f01484b2a08>

(Andrew Pawelski) #81

What about a function?


(Kris K) #82

Hi @rlkoshak

I’ve been using your DP for the Doors but my TTS is obviously just reading aloud what i’ve written rather than the state, like your broadcast alerts do.

What would be the best method for TTS to tell if its open or closed verbally?

My current rule snippet:


  // Alert if necessary
  if(alert){
    sendBroadcastNotification(msg.toString)
     Echo_Living_Room_TTS.sendCommand('The Garage Door is Open')
  }

Would this work? I want Alexa to basically verbally if the door is open or closed using TTS


  // Alert if necessary
  if(alert){
    sendBroadcastNotification(msg.toString)
     Echo_Living_Room_TTS.sendCommand(msg.ToString)
  }

Or, this?

  // Alert if necessary & Door is Open
  if(alert && state == OPEN) {
    sendBroadcastNotification(msg.toString)
     Echo_Living_Room_TTS.sendCommand('The Garage Door is Open')
  }
  // Alert if necessary & Door is Closed
  if(alert && state == CLOSED) {
    sendBroadcastNotification(msg.toString)
     Echo_Living_Room_TTS.sendCommand('The Garage Door is Closed')
  }

Thanks!


(Rich Koshak) #83

I don’t actually use TTS. I just send a myopenhab.org message.

I find TTS announcements to be too intrusive. It’s easy to ignore or delay looking at an OH alert when it beeps on my phone or watch but all conversation will stop when speaker starts talking at you.

From what I know I don’t see anything wrong with any of those. I’d work to make it more generic.

    // If alerted == OFF and triggeringItem == OFF then sensor went offline and we have not yet alerted
    // If alerted == ON and triggeringItem == ON then the sensor came back online after we alerted that it was offline
    if(alerted.state == triggeringItem.state) {
        val currState = triggeringItem.state
        // wait one minute before alerting to make sure it isn't flapping
        timers.put(triggeringItem.name, createTimer(now.plusMinutes(1), [ |
            // If the current state of the Item matches the saved state after 5 minutes send the alert
            if(triggeringItem.state == currState) {
                aInfo.sendCommand(name + " is now " + transform("MAP", "admin.map", triggeringItem.state.toString) + "!")
                alerted.postUpdate(if(currState == ON) OFF else ON)
            }
            timers.put(triggeringItem.name, null)
        ]))
    }

(Kris K) #84

Thanks ill look into your suggestion. How have people previously delt with notifications that have different expire timers? One of my doors I want an alert after 1 minute, but the other is an hour.

The notification is generic in that it will say the gate (with 1m expire) has been open for one hour, despite the timer being 1 minute

It would be great if we could somehow have notifications/alerts that are specific to the group members


(Scott Rushworth) #85

You’d need to use JSR223, but you can add this info (timer timeouts, notification text, etc.) into Item metadata and use it in your rule. I’ll get an example post out one of these days…


Released: Openhab2 Amazon Echo Control Binding (controlling alexa from openhab2)
(Rich Koshak) #86

I use separate Items with similar names (see Design Pattern: Associated Items) and the Expire binding. Each door would have it’s own Timer Item with a custom Expire for that door. The message gets a little tricky but I would probably skip the “for X minutes” in the alert message and just say “too long” or something generic as not worth the effort to implement.

In Rules DSL you can dynamically add tags. It would be awkward but you can associated the message with the Item as a tag since metadata isn’t available in Rules DSL apparently.


(Kris K) #87

I think you’re right, ill just remove the ‘open for X minnutes’ - its kind of irrelevant really.


(E. Gerland) #88

Hi Rich,

Your DPs are awesome and I use them quite a lot.
I also use your “Working with Groups” for Windows, Vehicle doors etc.

For my main Things to monitor (12) I would do it the same way to reduce code.
My single Thing switches look like this:

Switch ZwaveThing "Zwave" (G_Things)

whereas the Group is:

Group:Switch:AND(ON,OFF) G_Things “Things”

My rules for each single Thing look like this:

rule "OFFLINE check ZWave"
when 
Member of G_Things changed 
then
	var status = ThingAction.getThingStatusInfo("zwave:serial_zstick:49ddd2f3").getStatus()
	if(status.toString() == 'ONLINE') {
		if(ZwaveThing.state != ON) {
			ZwaveThing.postUpdate(ON)
		}
	}		
	else { 
		if(ZwaveThing.state != OFF) {
			ZwaveThing.postUpdate(OFF)
		}
	}
end

So I end up with 12 rules of this type and I am sure that there is a smarter way.

My problem is how to handle the different things (like zwave:serial_zstick:49ddd2f3) within this group.
With Switches it’s easy, but I possibly need to handle these things as a group of Strings?!

Any hint into the right direction would help.