Sterowanie Things p...
 
Powiadomienia
Wyczyść wszystko

Informacja [Rozwiązany] Sterowanie Things przez rules za pomocą item 😉

3 Wpisów
2 Użytkownicy
2 Likes
211 Wyświetleń
(@szpila86)
Wpisów: 330
Weteran Patron Strony Donator 2K22, Donator 2K23, Donator 2K24
Autor tematu
 

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ć

 
Dodane : 08/11/2023 2:53 pm
(@kamikac)
Wpisów: 226
Pomocny
 

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 🙂

https://community.openhab.org/t/oh3-getting-triggeringitemname-and-previousstate-of-thing-changed/128794/5

 
Dodane : 13/11/2023 11:35 pm
(@szpila86)
Wpisów: 330
Weteran Patron Strony Donator 2K22, Donator 2K23, Donator 2K24
Autor tematu
 

@kamikac 

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
 
Dodane : 14/11/2023 8:13 pm
kamiKAC and adrian reacted
Udostępnij: