I am on OH 4.0.0 and struggeling to get a rule to work;
I have a DateTime item which are being fed from an external datasource (through HTTP binding).
In addition - the same datasource feeds an item with a electricity price.
I now want to format a string to be published to a string item - where I have the price and the date formatted together.
I can get this to work with the current time - like this:
var String tmp
var String Timestamp
val date_formatter = java.time.format.DateTimeFormatter.ofPattern("dd.MM.YYYY HH:mm")
Timestamp = now.format(date_formatter)
tmp = ((Math::round(Elpris.floatValue*100.00)/100.00) + " kr pr. Kwh (" + Timestamp + ")")
postUpdate(ElpriserTestStringItem, tmp)
But I cannot get it to work with the contents of my DateTime item instead of the current time… This is my (non-workable) rule code:
var String tmp
var String Timestamp
val date_formatter = java.time.format.DateTimeFormatter.ofPattern("dd.MM.YYYY HH:mm")
Timestamp = (SpotPriceDKK_currentTime.state as DateTimeType).getZonedDateTime().format(date_formatter)
tmp = ((Math::round(Elpris.floatValue*100.00)/100.00) + " kr pr. Kwh (" + Timestamp + ")")
postUpdate(ElpriserTestStringItem, tmp)
I am missing something related to stringing DateTime items - but what ?