This rule gives the java error when the rule beeing executed: (no error when beeing saved).
rule "Voice Testing Rule"
when
Item Voice_Robot changed from OFF to ON
then
say("Seneste opdatering var kl. " + String::format("%1$tH:%1$tM %1$td.%1$tm.%1$tY", NetamoIndendoersMeasuretime.state.toString))
end
Thx Rich…
I searched for examples and found quite a few… I dont really see why it shouldnt work… The only thing I can think of is that the format is wrong in some way. But since I have no idea what the error message is all about, this is just a wild guess. So I have given up for now.
finally had time to test this… Didn´t work…
This is the rule:
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
And when it fire:
2019-03-03 15:54:04.076 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Voice Testing Rule': An error occurred during the script execution: null
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