OK, I read all the linked posts, w/o finding a solution.
I also tried the REGEX w/o luck… but think this is the way to add the +0000 to the MQTT message, which looks like this 2021-10-26T23:46:12.040463Z
This is not shown in local time, which is what I’d like to achieve.
Maybe the ‘Z’ at the end is unexpected and should be +0000 instead?
I have tried:
{mqtt="<[mymosquitto:teslamate/cars/1/since:state:REGEX(s/Z/+0000/g)]"}
But then get Regex errors, due to Regex not installed:
021-11-02 12:34:43.924 [ERROR] [core.karaf.internal.FeatureInstaller] - Failed installing 'openhab-transformation-regex': Error:
Error downloading mvn:org.openhab.ui.bundles/org.openhab.ui.paper/[2.5.0,2.6)
So I gave up on this approach, using a rule instead.
with the help of this post:
I arrived at this rule:
rule "Convert UTC timestamp to local date-time"
when
Item TeslaM3_since changed
then
var Number EpochFromDateTime = (TeslaM3_since.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli
EpochFromDateTime = EpochFromDateTime + (10 * 60 * 60 * 1000)
val DateTimeType MyDateTimeFromEpoch = new DateTimeType(new DateTime(EpochFromDateTime).toString)
TeslaM3_since.postUpdate(MyDateTimeFromEpoch)
logInfo(logPrefix + "1.01", "Updated time stamp")
end
However, it raised this error:
2021-11-02 14:25:00.109 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'Convert UTC timestamp to local date-time': No instant converter found for type: java.math.BigDecimal
I am really peeved… what an effort to add four zeros and a plus sign to a MQTT string to get the proper timestamp. ![]()
[edit1]
added log entries to rule:
rule "Convert UTC timestamp to local date-time"
when
Item TeslaM3_since changed or
// s m h D M DoW Y
Time cron "0 0/5 * * * ?"
// here: 10 seconds past midnight; use http://www.cronmaker.com/
then
var Number EpochFromDateTime = (TeslaM3_since.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli
logInfo(logPrefix + "1.01", "Updated time stamp")
EpochFromDateTime = EpochFromDateTime + (10 * 60 * 60 * 1000)
logInfo(logPrefix + "1.02", "Updated time stamp")
val DateTimeType MyDateTimeFromEpoch = new DateTimeType(new DateTime(EpochFromDateTime).toString)
logInfo(logPrefix + "1.03", "Updated time stamp")
TeslaM3_since.postUpdate(MyDateTimeFromEpoch)
logInfo(logPrefix + "1.04", "Updated time stamp")
end
result…
2021-11-02 14:39:43.761 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'tesla.rules'
2021-11-02 14:39:49.982 [INFO ] [.smarthome.model.script.TeslaM3.0.01] - System Start: Tesla rules
2021-11-02 14:40:00.013 [INFO ] [.smarthome.model.script.TeslaM3.1.01] - Updated time stamp
2021-11-02 14:40:00.022 [INFO ] [.smarthome.model.script.TeslaM3.1.02] - Updated time stamp
2021-11-02 14:40:00.025 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'Convert UTC timestamp to local date-time': No instant converter found for type: java.math.BigDecimal