I want to store in a String Item the last alarm which was received by OH Item updates
Item:
String LastAlarmEvent “Dummy text”
What I can do by a rule:
LastAlarmEvent.label = “Last alarm event tiggered: [10.05.2017 16:30 Uhr " + wugTemp_Min.state.format(”%.1f °C")]"
This will change the label of the string item perfectly.
var SimpleDateFormat df = new SimpleDateFormat( “dd.MM., HH:mm” )
does not work at all, because SimpleDateFormat not known (maybe I have to import anything in the rule file?)
Every time my date/time syntax seems to be wrong. Any idea?
It can be solved by using this one:
LastAlarmEvent.label = “Last alarm event tiggered: [” + String::format( “%1$td.%1$tm.%1$tY %1$tH:%1$tM “, new Date() ) + wugTemp_Min.state.format(”%.1f °C”) + “]”
But I have to add
import java.util.Date
to the rule file
What specifically doesn’t work. Does the date time not appear at all, doesn’t appear correctly, generates an error?
The more typical way to do what you are after is not to modify the label directly but to modify the state of the String Item.
Also, now is a Joda datetime, not a java.util.DateTime so you can’t use them inter-changeably. Below is one of many ways to do that and it avoids String::format as I don’t think that works with Joda DateTime.
var alarmTime = now
var alarm = alarmTime.year + "-" + alarmTime.monthOfYear + "-" + alarmTime.dayOfMonth + " " +
alarmTime.hourOfDay + "/" + alarmTime.minuteOfHour + "/" + alarmTime.secondOfMinute + ", " +
AlarmItem.state.toString // what ever you do to generate the last part of the text
LastAlarmEvent.postUpdate(alarm)