Say time and date

Usually that is the result of a type error. Are you certain NetamoIndendoerMeasuretime isn’t NULL or UNDEF?

Also, check your parens. I don’t think they are right. They’re should be three on the end

  1. close the new Date
  2. close the String::format
  3. close the say
1 Like

110% possitive…

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

7 minutes ago. Netamo updated every 10. minute.

There are three “(” and three “)”.

Yes but can’t just put them any old place. They define the scopes of the function calls. The scopes are

say -> String::format -> new Date

Therefore there should be three parens at the end.

I think you are missing an open paren before

NetamoIndendoerMeasuretime.state as DateTimeType)

and then the one at the end.

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

Break the line up a bit and add some logging to see which of those calls is experiencing the type problem.

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?

It’s an Object, not an Item. It doesn’t have a .state. Just call .toString.

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)

Are these linies suppose to go inbetween the line, you suggest I should break up?

These lines are the line I asked you to break up broken up. With logging in place so show the result at each stage of the operation.

Like this?

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.

Not, just like I wrote 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

Check that the item make exactly matches how it is defined in your items file or PaperUI

This is the item:

DateTime    NetamoIndendoersMeasuretime	    "Netamo Indendørs Sidste opdatering [%1$tH:%1$tM %1$td.%1$tm.%1$tY]"    <time>    { channel="netatmo:NAMain:16451b76:70ee502727e6:TimeStamp" }

And this is the output.

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

I’m back on my system and could test:

Using this rule:

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.

How would this rule work in OH3? Seems as if “string” gets a cannot infer type error.