now.getMonth cannot be cast

Einrichtung der openHAB Umgebung und allgemeine Konfigurationsthemen.

Moderatoren: seppy, udo1toni

Antworten
Benutzeravatar
HiG
Beiträge: 136
Registriert: 16. Jun 2021 13:39
Answers: 0

now.getMonth cannot be cast

Beitrag von HiG »

Ich hab hier folgende Rule gefunden

Code: Alles auswählen

rule "Xmas-Beleuchtung EIN"
when
    Time cron "0 00 16 ? 12,1 1-5" // 16:00:00 Uhr Montag-Freitag, Dezember und Januar
then
    if(now.getDayOfYear < 7 || now.getMonth = 12)
        Swi_FritzBox.sendCommand(ON)
end
und für mich abgeändert

Code: Alles auswählen

if(now.getMonth > 11  && now.getMonth < 4){
  logInfo("Bewegung","Heizperiode")
  }else{
  logInfo("Bewegung","keine Heizperiode")
  }
Beim Ausführen bekomme ich allerdings dann folgende Fehlermeldung

Code: Alles auswählen

failed: class java.lang.Integer cannot be cast to class java.lang.Enum (java.lang.Integer and java.lang.Enum are in module java.base of loader 'bootstrap')

int5749
Beiträge: 1173
Registriert: 4. Nov 2019 22:08
Answers: 9

Re: now.getMonth cannot be cast

Beitrag von int5749 »

Ich hab dies mal schnell nach Google geschmissen und dies kommt, weil Du falsche Werte vergleichst.

getMonth liefert: Januar, Februar, etc
getMonthValue würde die von Dir benötigten Wert: 1,2,etc liefern


added more information

Code: Alles auswählen

Copied from release notes

Rules now use Java Time API instead of Jodatime so some expressions need to be adapted:

    getHourOfDay → getHour, getMinuteOfHour → getMinute, getMonthOfYear → getMonthValue
    Some simple >and < comparisons may no longer work and you may need to use isAfter()/isBefore() instead.
openHAB 4.1.0 Release mit openHABian in einem Debian Bookworm (LXC) unter Proxmox 8.1.3

Benutzeravatar
HiG
Beiträge: 136
Registriert: 16. Jun 2021 13:39
Answers: 0

Re: now.getMonth cannot be cast

Beitrag von HiG »

int5749 hat geschrieben: 31. Jan 2022 14:03 und dies kommt, weil Du falsche Werte vergleichst.

:oops: :oops: :oops: :oops:

Danke für die Nachsicht. Nachdem ich nun auch noch die Werte 11 und 4 getauscht habe....liefert die Rule was sie soll.

Antworten