Witam
nie wiedzieć czemu ostatnimi tygodniami miałem pare razy problem z mostem Nice.
Postanowiłem dorobić przycisk restart do mostu.
Restart mostu działa:
rule "Reset mostu nice"
when
Item Bridge_restart changed to ON
then
val headers = newHashMap("Authorization" -> "Bearer oh.NICE.TOKEN itd ;)")
sendHttpPutRequest("http://192.168.xx.xx:8080/rest/things/mynice:it4wifi:000b6c4a89a5/enable", "text/plain", "false", headers, 1000)
createTimer(now.plusSeconds(5), [ |
sendHttpPutRequest("http://192.168.xx.xx:8080/rest/things/mynice:it4wifi:000b6c4a89a5/enable", "text/plain", "true", headers, 1000)
Bridge_restart.postUpdate(OFF)
])
end
Do powyższego stwierdziłem że dodam sobie flagę informacyjną o stanie mostu i tu powstał problem na początek reguły które działają
rule "Most Nice nie działa"
when
Thing "mynice:it4wifi:000b6c4a89a5" changed to OFFLINE or
Thing "mynice:it4wifi:000b6c4a89a5" changed to UNINITIALIZED or
Thing "mynice:it4wifi:000b6c4a89a5" changed to UNKNOWN or
Thing "mynice:it4wifi:000b6c4a89a5" changed to INITIALIZING
then
val String nowyTekst = "Most Nice OFFLINE"
Status_Nice.setLabel(nowyTekst)
logInfo("Most Nice nie działa", "Most IoT jest OFFLINE")
end
rule "Most Nice działa"
when
Thing "mynice:it4wifi:000b6c4a89a5" changed to ONLINE
then
val String nowyTekst = "Most Nice ONLINE"
Status_Nice.setLabel(nowyTekst)
logInfo("Most Nice działa", "Most IoT jest ONLINE")
end
Nie chce mieć dwóch reguł i się rozpisywać i tu poległem poniżej ogólny NIEDZIAŁAJĄCY zarys kodu na którym się wyżywałem...
rule "Most Nice status"
when
Thing "mynice:it4wifi:000b6c4a89a5" changed
then
val String status = triggeringItem.state.toString
if (status == "ONLINE") {
val String nowyTekst = "Most Nice ONLINE"
Status_Nice.setLabel(nowyTekst)
logInfo("Most Nice działa", "Most IoT jest ONLINE")
} else {
val String nowyTekst = "Most Nice OFFLINE"
Status_Nice.setLabel(nowyTekst)
logInfo("Most Nice nie działa", "Most IoT jest OFFLINE")
}
end
Docelowo sam przycisk do restartu nie będzie widoczny jeśli most będzie online
sam komponent Status_Nice jeśli nie uda się okiełznać reguły po prostu zniknie 😉 choć wolałbym sobie taką flagę pozostawić
Czołem
Może nie działa, bo tutaj masz Thing
Thing "mynice:it4wifi:000b6c4a89a5" changed
a tutaj masz Item
val String status = triggeringItem.state.toString
Literatura powinna pomóc 🙂
Dzięki 😉
🤬 🤬 🤬 🤬 🤬 🤬
Skrypty to jednak nie moja bajka.
Poniżej działający kod dla potomnych ;P
rule "Most Nice status"
when
Thing "mynice:it4wifi:000b6c4a89a5" changed
then
val status = getThingStatusInfo("mynice:it4wifi:000b6c4a89a5")
logInfo("Most Nice działa", "Nowy status: " + status.toString())
if (status.toString() == "ONLINE") {
val nowyTekst = "Most Nice ONLINE"
Status_Nice.setLabel(nowyTekst)
logInfo("Most Nice działa", "Most IoT jest ONLINE")
} else {
val nowyTekst = "Most Nice OFFLINE"
Status_Nice.setLabel(nowyTekst)
logInfo("Most Nice nie działa", "Most IoT jest OFFLINE")
}
end

