2019-03-03 22:27:41.305 [vent.ItemStateChangedEvent] - NetamoIndendoersMeasuretime changed from 2019-03-03T22:17:02.000+0100 to 2019-03-03T22:27:07.000+0100
rule "Voice Testing Rule"
when
Item Voice_Robot changed from OFF to ON
then
say("Seneste opdatering var kl." + String::format( "%1tH:%1tM %1td.%1tm.%1tY", (new Date (NetamoIndendoerMeasuretime.state as DateTimeType).zonedDateTime.timeInMillis )))
end
Return with this error, when rule fires:
2019-03-04 23:05:36.537 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Voice Testing Rule': An error occurred during the script execution: null
Which I knew how/where to breake it…
I actually thought off getting rid of the say, and just try to log insted. But I only see the NetamoIndendoerMeasuretime state, which makes no sense in logging, cause I already now what it is from the item…
Is it possible to log the new Date? I dont see its state anywhere?
rule "Voice Testing Rule"
when
Item Voice_Robot changed from OFF to ON
then
val st = NetamoIndendoerMeasuretime.state as DateTimeType
logInfo("Test", "State = " + st)
say("Seneste opdatering var kl." + String::format( "%1tH:%1tM %1td.%1tm.%1tY", (new Date (NetamoIndendoerMeasuretime.state as DateTimeType).zonedDateTime.timeInMillis )))
end
I tried, and it returned with a strange error, when fired…
2019-03-07 00:17:14.564 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Voice Testing Rule': The name 'NetamoIndendoerMeasuretime' cannot be resolved to an item or type; line 5, column 11, length 26
NetamoIndendoerMeasuretime is indeed an item, so I dont get it.
rule "Voice Testing Rule"
when
Item Voice_Robot changed from OFF to ON
then
val st = NetamoIndendoerMeasuretime.state as DateTimeType
logInfo("Test", "State = " + st)
val epoch = st.zonedDateTime.timeInMillis
logInfo("Test", "epoch = " + epoch)
val dt = new Date(epoch)
logInfo("Test", "Date = " + dt.toString)
val fmt = String::format( "%1tH:%1tM %1td.%1tm.%1tY", dt)
logInfo("Test", "Formatted = " + fmt)
val msg = "Seneste opdatering var kl. " + fmt
logInfo("Test", "Message = " + msg)
say(msg)
end
I get the same error, and nothing else in the log.
2019-03-08 01:37:38.126 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Voice Testing Rule': The name 'NetamoIndendoerMeasuretime' cannot be resolved to an item or type; line 5, column 15, length 26
2019-03-09 14:20:06.590 [vent.ItemStateChangedEvent] - NetamoIndendoersMeasuretime changed from 2019-03-09T14:08:55.000+0100 to 2019-03-09T14:19:01.000+0100
rule "Test Rule"
when
Item Test changed to ON
then
logInfo ("Test Rule", "Started")
var string tmp = "Letzter Eintrag war um " + IP_last_seen.state.format("%1$tH") +"Uhr"+ IP_last_seen.state.format("%1$tM")+ " am "+ IP_last_seen.state.format("%1$td.%1$tB.%1$tY")
logInfo ("Test Rule", tmp)
say (tmp,"voicerss:deDE","sonos:PLAY1:PlayBuero")
end
IP_lastseen is an item linked to the “lastseen” channel of a network device thing.
logoutput was:
Letzter Eintrag war um 16Uhr45 am 09.März.2019
Note: I’m using German language, in your language you might want to order the numbers differently.