Hi,
In the last past weeks i’ve build a irrigation system and it soon became clear that i have to use my home automation system… so thanks for the OpenSprinkler binding… and here are my things, items and rules
The OSPI system runs great, but sometimes our family members and me want to start a short manual irrigation cycle. With the following telegram rules, i dont have to grant them access to the OSPI interface… they can easily start and stop the cycles via our telegram group chat…
opensprinkler.things
Bridge opensprinkler:http:http "OpenSprinkler HTTP Interface" @ "OSPI" [hostname="127.0.0.1", port=8080, password="PASSWORD", refresh=20] {
Thing station 01 "OpenSprinkler Station 01" @ "OSPI" [stationIndex=0]
Thing station 02 "OpenSprinkler Station 02" @ "OSPI" [stationIndex=1]
Thing device device "OpenSprinkler Rain Sensor" @ "OSPI"
}
opensprinkler.items
Group:Switch:AND(ON,OFF) gOSPI_Station
Group:Switch:AND(ON,OFF) gOSPI_Station_Queued
Switch OpenSprinklerDeviceRainsensor "Rain Sensor" {channel="opensprinkler:device:http:device:rainsensor"}
Switch OpenSprinklerStation01StationState "Station 1" (gOSPI_Station) {channel="opensprinkler:station:http:01:stationState"}
Switch OpenSprinklerStation01Queued "S1 in Warteschlange" (gOSPI_Station_Queued) {channel="opensprinkler:station:http:01:queued"}
Number:Time OpenSprinklerStation01RemainingWaterTime "restliche Laufzeit" {channel="opensprinkler:station:http:01:remainingWaterTime"}
Number:Time OpenSprinklerStation01NextDuration "S1 nächste Laufzeit" {channel="opensprinkler:station:http:01:nextDuration"}
Switch OpenSprinklerStation02StationState "Station 2" (gOSPI_Station) {channel="opensprinkler:station:http:02:stationState"}
Switch OpenSprinklerStation02Queued "S2 in Warteschlange" (gOSPI_Station_Queued) {channel="opensprinkler:station:http:02:queued"}
Number:Time OpenSprinklerStation02RemainingWaterTime "restliche Laufzeit" {channel="opensprinkler:station:http:02:remainingWaterTime"}
Number:Time OpenSprinklerStation02NextDuration "S2 nächste Laufzeit" {channel="opensprinkler:station:http:02:nextDuration"}
opensprinkler.rules
val OSPI_ReplyId = "OSPI_Reply"
var StationDuration = 600 // 10min
val Station01 = "Rasen oben"
val Station02 = "Rasen Hang"
val StationOFF = "Alle aus"
rule "Telegram Bot receive rasen"
when
Item TelegramBotLastMessageDate received update
then
val telegramAction = getActions("telegram","telegram:telegramBot:bot1")
if (TelegramBotLastMessageText.state.toString.toLowerCase == "/rasen") {
telegramAction.sendTelegramQuery(Long::parseLong(TelegramBotChatId.state.toString), "*Beregnungs-Optionen:*\nWelcher Bereich soll bewässert werden?", OSPI_ReplyId, Station01, Station02, StationOFF)
}
end
rule "Telegram Bot receive rasen answer"
when
Item TelegramBotReplyId received update OSPI_Reply
then
val telegramAction = getActions("telegram","telegram:telegramBot:bot1")
if (TelegramBotLastMessageText.state.toString == Station01) {
var reply = "Bewässerung für *" + Station01 + "* wurde gestartet.\nLaufzeit *" + StationDuration / 60 + "* Minuten."
OpenSprinklerStation01NextDuration.sendCommand(StationDuration)
OpenSprinklerStation01StationState.sendCommand(ON)
telegramAction.sendTelegramAnswer(Long::parseLong(TelegramBotChatId.state.toString), TelegramBotReplyId.state.toString, reply)
} else if (TelegramBotLastMessageText.state.toString == Station02) {
var reply = "Bewässerung für *" + Station02 + "* wurde gestartet.\nLaufzeit *" + StationDuration / 60 + "* Minuten."
OpenSprinklerStation02NextDuration.sendCommand(StationDuration)
OpenSprinklerStation02StationState.sendCommand(ON)
telegramAction.sendTelegramAnswer(Long::parseLong(TelegramBotChatId.state.toString), TelegramBotReplyId.state.toString, reply)
} else if (TelegramBotLastMessageText.state.toString == StationOFF) {
var reply = "Bewässerung für alle Stationen ausgeschaltet."
gOSPI_Station.members.filter[i|i.state == ON].forEach[i| { i.sendCommand(OFF)}]
// we also need to cancel the queued stations
gOSPI_Station_Queued.members.filter[i|i.state == ON].forEach[i| { i.sendCommand(OFF)}]
telegramAction.sendTelegramAnswer(Long::parseLong(TelegramBotChatId.state.toString), TelegramBotReplyId.state.toString, reply)
} else {
telegramAction.sendTelegramAnswer(Long::parseLong(TelegramBotChatId.state.toString), TelegramBotReplyId.state.toString, "ungültige Angabe!")
}
if (TelegramBotReplyId.state.toString == OSPI_ReplyId) {
// make sure the next request can see an update for "TelegramBotReplyId"
TelegramBotReplyId.postUpdate(NULL)
}
end
In the future will play a bit with the group items and labels… so maybe i can shorten the rules a bit and dont have to hardcode the station names… but for now its working as expected… and i’m quite happy with it…
If you have any questions or suggestions, please let me know
Have fun…
Cheers
/Holger