Hello,
at first: Excuse my english
The idea for this was in the german “openhabforum”. I have build it myself (with “some” code from the “original” - Thank you OP ) and want to show you how I did it. Im open for ideas or if something “wrong”. Im new to OpenHab but think it could help other.
What does my solution do:
Everyday at 18:00 o’clock a rule is checking, if one of my “Waste item” (filled with the icalendar binding) is having a date of tomorrow. If so, a “question” is sent every hour by telegram whether the garbage cans have been taken out. If this question is not “answerd” the “question” is send every hour again.
How:
At first you need an item for every “waste” you have and link it to the icalender-Filter (In this examples the items with the waste event are beggining with “Abfall…”. For my solution you have to put all the items in one group (“Abfall”).
Now you have to check, if the Waste items are filled with a “date” and set the “state description” to “%1$td.%1$tm.%1$tY”
Okay. Now we are need some “help/variant” items.
(I dont have the textual item definiton - I build it with paper UI)
vAbfall_Aktuell = string. The string will be, if waste for tomorrow is found, the label of the waste-item
vAbfall_Benachrichtigung = A Switch for the notification
vAbfall_BenachrichtigungE = A Switch if the notification have to be send again
Its important to have a diffrent name for the “help/variant” items, because we are looping through the group
Now to the rules.
The first rule is running every day at 18:00 o’clock. The script checks, if the waste is tomorrow.
val tomorrow = now.plusDays(1)
//loop through the group Abfall, but only for the items "Abfall*"
Abfall.members.filter[ i | i.name.substring(0,6) == "Abfall" && i.state != NULL].forEach[ i |
//Save the date
val Wert = (i.state as DateTimeType).zonedDateTime
//check if the waste date tomorrow
if (Wert.year == tomorrow.year && Wert.month == tomorrow.month && Wert.dayOfMonth == tomorrow.dayOfMonth)
{
//Save the label of the waste item to "vAbfall_Aktuell" and trigger "ON" to the notification
logInfo("Abfall-1", "Morgigen Abfall gefunden. Setze Benachrichtigungen aktiv")
vAbfall_Aktuell.sendCommand(i.label)
vAbfall_BenachrichtigungE.sendCommand(ON)
vAbfall_Benachrichtigung.sendCommand(ON)
return
}
]
The second rule is triggered, when the “vAbfall_Benachrichtigung” item was updatet to “on”:
The script is doing the following:
We will check if the “vAbfall_BenachrichtigungE” is “ON”.
In the “first” run, it will be “ON” because we have done this in the first rule. Then we will send an Telegram query and create an timer for one hour. After one hour we update vAbfall_Benachrichtigung to “ON” again (even though it was still ON). So the same rule is running again.
This means: This rule is running every hour and send a TeleframQuery until the “vAbfall_BenachrichtigungE” is "OFF"
//definition for the telegrambot
val telegramAction = getActions("telegram","telegram:telegramBot:yyyyyyyyy")
//check if vAbfall_BenachrichtigungE.state is on.
if(vAbfall_BenachrichtigungE.state == ON){
//If ON, we send the telegram query and create a timer for one hour
logInfo("Abfall-2", "Benachrichtigung noch aktiv - Deshalb schicken wir Nachricht. Erneute prüfung in einer Stunde")
telegramAction.sendTelegramQuery("Morgen wird " + vAbfall_Aktuell.state +" geleert.\nWurde die Tonne heraus gestellt?", "Abfall", "Ja!")
createTimer(now.plusMinutes(60), [ |
// The timer is sending "ON" to vAbfall_Benachrichtigung. This rule here is running again one hour later.
vAbfall_Benachrichtigung.sendCommand(ON)
])
} else {
//everthing off
logInfo("Abfall-3", "Antwort erhalten. Benachrichtigung Abschalten - Kein neuer Timer")
vAbfall_Benachrichtigung.sendCommand(OFF)
}
In the third rule, we will check if an answer was send from Telegram. If yes, we switch “vAbfall_BenachrichtigungE” to off.
I have changed the “when” to “lastMessageDate”. Because if the last answer is the same, the channel “Reply” was not “updatet”.
The script:
//Check if the Reply = "Abfall" (to be defined in the sendTelegramQuery string).
if(TelegramBot_ReplyId.state == "Abfall"){
logInfo("Abfall-3", "Antwort erhalten. BenachrichtigungE Abschalten")
//Send command off
vAbfall_BenachrichtigungE.sendCommand(OFF)
}
That’s all! I hope this can help you
PS: I dont know, if the solution is “good” to trigger the same timer-rule with a timer. But it work
PS2: This solution is only working for ONE waste-date (“return” after found one date in script one)
Greetings from Germany
Mike