In that case neither your approach nor my approach does what you need.
You need:
- A Switch Item with Expire to represent when the Timer is running during which time the announcement can be repeated
- A separate Item on your HABpanel to press to have the announcement repeated
- A Rule that triggers from the second Item that checks to see if the Switch Item is ON and if so go ahead and repeat the announcement. If not then ignore the button press.
Since you are likely to have more than one announcement this would apply to I recommend applying Design Pattern: Separation of Behaviors and Design Pattern: Gate Keeper to centralize all your announcement logic.
Then you can use something like the following which will repeat the last received announcement for up to 15 minutes:
Items:
String Announcement
Switch AnnouncementTimer { expire="15m,command=OFF" }
Switch RepeateAnnouncement "Repeate the last announcement"
Rules:
rule "New Announcement"
when
Item Announcement received command
then
logInfo("Announcement", receivedCommand.toString)
if(vTimeOfDay.state != "NIGHT" && vTimeOfDay.state != "BED"){
say(receivedCommand.toString)
AnnouncementTimer.sendCommand(ON)
}
end
rule "Repeat Last Announcement"
when
Item RepeatAnnouncement received command
then
if(AnnouncementTimer.state == ON) say(Announcement.state.toString)
else logInfo("Announcement", "Too much time has passes since last announcement"
end
// to use the above in your rules
rule "Waschmaschine"
when
Item Waschmaschine received command OFF
then
Announcement.sendCommand("Die Waschmaschine ist fertig!")
end
Theory of operation: You have a trio of Items.
- String Item you send command to with the text to announce
- A Switch Item that gets set to ON for 15 minutes, this is the Timer
- A Switch Item you put on your HABPanel to press to have the announcement repeated
To generate an announcement simply sendCommand("text to announce")
. This triggers the “Announcement” rule which will log the announcement. If it isn’t night time it says the announcement and sets the Timer by sending it the ON command.
To repeat the last announcement the user sends a command to RepeatAnnouncement which checks to see if the Timer is running and if it is says the last announcement (i.e. the current state of Announcement).
Note: If it were me, I would just put Announcement on my HABPanel. Since the users have to interact with the panel in the first place to have the announcement repeated why not just put the text of the announcement there and save everyone that extra step and extra time?