In the meantime I have configured this binding almost perfectly, so that outgoing and incoming calls are displayed in OH3 with names, phone numbers, date and time.
For me, however, this constellation would only be complete if the call duration could also be read out or calculated in some other way.
The time should be calculated in seconds using the following rule and the status Active and Idle.
var Long lPhoneStart = 0
rule "Gesprächsdauer messen"
when
Item fritzCallRinging changed
then
var Integer iSeconds = 0
if(newState.toString == "ACTIVE") {
iPhoneStart = ZonedDateTime.now.getEpochSecond
} else if(previousState.toString == "ACTIVE" && newState.toString == "IDLE") {
iSeconds = (ZonedDateTime.now.getEpochSecond - iPhoneStart).intValue
}
var String callDauer = "-"
callDauer.postUpdate(iSeconds)
end
Unfortunately, the following error messages appear:
2022-10-15 18:15:57.921 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'fritzbox_94-1' failed: An error occurred during the script execution: Could not invoke method: org.openhab.core.model.script.actions.BusEvent.postUpdate(java.lang.String,java.lang.String) on instance: null in fritzbox_94
2022-10-15 18:15:58.586 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'fritzbox_94-1' failed: 'getEpochSecond' is not a member of 'java.time.ZonedDateTime'; line 9, column 23, length 32 in fritzbox_94
2022-10-15 18:16:03.592 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'fritzbox_94-1' failed: 'getEpochSecond' is not a member of 'java.time.ZonedDateTime'; line 11, column 22, length 32 in fritzbox_94
Many thanks for the support. But when I use this code:
var Long lPhoneStart = 0
rule "Gesprächsdauer messen"
when
Item fritzCallRinging changed
then
var Integer iSeconds = 0
if(newState.toString == "ACTIVE") {
iPhoneStart = ZonedDateTime.now.toEpochSecond
} else if(previousState.toString == "ACTIVE" && newState.toString == "IDLE") {
iSeconds = (ZonedDateTime.now.toEpochSecond - iPhoneStart).intValue
}
var String callDauer = "-"
callDauer.postUpdate(iSeconds)
end
I get the following error messages:
2022-10-16 17:08:14.589 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'fritzbox_94-1' failed: An error occurred during the script execution: Could not invoke method: org.openhab.core.model.script.actions.BusEvent.postUpdate(java.lang.String,java.lang.String) on instance: null in fritzbox_94
2022-10-16 17:08:14.613 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'fritzbox_94-3' failed: The name 'callDauer' cannot be resolved to an item or type; line 107, column 31, length 9 in fritzbox_94
2022-10-16 17:08:17.638 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'fritzbox_94-1' failed: An error occurred during the script execution: Couldn't invoke 'assignValueTo' for feature JvmVoid: (eProxyURI: fritzbox_94.rules#|::0.2.0.2.0.1.1.0.0::0::/1) in fritzbox_94
2022-10-16 17:08:28.636 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'fritzbox_94-1' failed: The name 'iPhoneStart' cannot be resolved to an item or type; line 11, column 55, length 11 in fritzbox_94
The value that the variable callDauer is to take is passed to an item in a further rule. It is possible that I made a mistake here. Must call duration then be configured as a global variable and if so, how do I do that?
I didn’t notice the error in the definition of lPhoneStart, sorry.
This code shows me a value for the first time, namely “0”. However, because the call has not yet ended at this time, I assume that an item update will be added after the end of the call.
I read something about it somewhere. However, at the moment I don’t know how to do this. Maybe you have another tip.
var Long iPhoneStart = 0
rule "Gesprächsdauer messen"
when
Item fritzCallRinging changed from IDLE to DIALING
then
var Integer iSeconds = 0
if(newState.toString == "ACTIVE") {
iPhoneStart = ZonedDateTime.now.toEpochSecond
} else if(previousState.toString == "ACTIVE" && newState.toString == "IDLE") {
iSeconds = (ZonedDateTime.now.toEpochSecond - iPhoneStart).intValue
}
Flag_ADauer_00.postUpdate(iSeconds)
end
First the following information: I can display various data using a self-built widget. Here also u. a. that of the item “Flag_ADauer_00”.
After the end of a call, the value 1666009749 is displayed there (it also no longer changes). If I then look into the openhab structure under Items/Flag_ADauer_00, the value 24 is displayed. This corresponds exactly to the duration of my last test call. So the display for the widget needs to be updated after the call.
How can I achieve this?
Addendum…
One approach might be:
rule "anything"
when
Item fritzCallRinging changed from ACTIVE to IDLE
then
Here the update of the widget (or Items)... BUT HOW?
end