Hi community,
I was switching over from OH 2.5.10 to 3.0.0 with success in general. The paper UI and text based Things/items/etc. were automatically adapted and the basic function is running. On few points I need to adapt, before I will spend time in getting familiar with new OH3 features.
I have a problem in one rule and fear I’m not able to solve it by myself, because I’m no professional programmer. In OH2 the rule was working smooth, without any problems, even if someone of this community named it “ugly code”, but for me it was working.
The target application: If AmazonEcho is getting a timer, it sends a DateTime information to an item. This information is the target date and time on which the timer is counted to 0. I puzzled for OH2 a functional code after researching step by step and using some code examples and now I need to translate that from joda.time base to java.time base.
I was thinking, if it is possible to import a joda.time base for that rule?
If this is not possible, may somebody can translate that with ease?
Here is the item, which is triggered with the target date time information, if a timer is started via Amazon Alexa:
DateTime EchoWohnzimmer_NaechsterTimer "EchoWohnzimmer_NaechsterTimer" {channel="amazonechocontrol:echo:Sabrina_Amazon:G090RF0474830SUC:nextTimer"}
This item is the trigger for the following rule, which will calculate the difference between the target time of the item and the current time, to show a countdown in a string item “EchoTimer”:
var Timer echotimer //Variable für den Echo-Timer im Wohnzimmer
rule "Echo-Timer"
when
Item EchoWohnzimmer_NaechsterTimer changed
then
if (EchoWohnzimmer_NaechsterTimer.state == UNDEF) {
EchoTimer.sendCommand("Kein aktiver Timer")
}
else {
// Timer Date and time 2019-10-20T21:58:35.870-0600
val timerString = EchoWohnzimmer_NaechsterTimer.state.format("%1$tY-%1$tm-%1$tdT%1$tH:%1$tM:%1$tS")
echotimer = createTimer(now, [ |
// parse String to Date Time
var DateTime timestring = parse(timerString)
// find out time left in minutes
val timeleft = (((timestring.millis + 60000) - now.millis) / 60000)
// finish sequence if the time left is 0
if(timeleft == 0) {
EchoTimer.sendCommand("Timer abgelaufen")
Thread::sleep(2000)
EchoTimer.sendCommand("Kein aktiver Timer")
}
else {
// update the timer Item with time remaining
EchoTimer.sendCommand("noch " + timeleft + " Min.")
// reschedule the timer for 1 minute
echotimer.reschedule(now.plusMillis(60000))
}
] )
}
end
Thank’s for any help to get this functional in OH 3!