Number robonect_duration "Dauer aktueller Modus [%s]" <grass> {channel="<[robonect:mower:13b76ca8:mowerStatus#duration:JS(automower_duration.js)]>" }
results in
[ERROR] [el.item.internal.GenericItemProvider] - Binding configuration of type 'channel' of item 'robonect_duration' could not be parsed correctly.
org.eclipse.smarthome.model.item.BindingConfigParseException: UID segment '<[robonect' contains invalid characters. Each segment of the UID must match the pattern [A-Za-z0-9_-]*.
at org.eclipse.smarthome.model.thing.internal.GenericItemChannelLinkProvider.createItemChannelLink(GenericItemChannelLinkProvider.java:77)[136:org.eclipse.smarthome.model.thing:0.9.0.b5]
at org.eclipse.smarthome.model.thing.internal.GenericItemChannelLinkProvider.processBindingConfiguration(GenericItemChannelLinkProvider.java:67)[136:org.eclipse.smarthome.model.thing:0.9.0.b5]
at org.eclipse.smarthome.model.item.internal.GenericItemProvider.internalDispatchBindings(GenericItemProvider.java:325)[126:org.eclipse.smarthome.model.item:0.9.0.b5]
at org.eclipse.smarthome.model.item.internal.GenericItemProvider.internalDispatchBindings(GenericItemProvider.java:297)[126:org.eclipse.smarthome.model.item:0.9.0.b5]
at org.eclipse.smarthome.model.item.internal.GenericItemProvider.processBindingConfigsFromModel(GenericItemProvider.java:182)[126:org.eclipse.smarthome.model.item:0.9.0.b5]
at org.eclipse.smarthome.model.item.internal.GenericItemProvider.modelChanged(GenericItemProvider.java:367)[126:org.eclipse.smarthome.model.item:0.9.0.b5]
at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.notifyListeners(ModelRepositoryImpl.java:286)[125:org.eclipse.smarthome.model.core:0.9.0.b5]
at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.addOrRefreshModel(ModelRepositoryImpl.java:136)[125:org.eclipse.smarthome.model.core:0.9.0.b5]
at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.checkFile(FolderObserver.java:234)[125:org.eclipse.smarthome.model.core:0.9.0.b5]
at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.processWatchEvent(FolderObserver.java:297)[125:org.eclipse.smarthome.model.core:0.9.0.b5]
at org.eclipse.smarthome.core.service.WatchQueueReader.run(WatchQueueReader.java:206)[101:org.eclipse.smarthome.core:0.9.0.b5]
at java.lang.Thread.run(Thread.java:748)[:1.8.0_131]
Unfortunately, you cannot apply a transform to a channel link. If the binding supports transforms, you would add the transform to the Thing definition and it will be documented in the binding’s readme.
If the binding does not support transforms, you will have to do the transform in a Rule.
(function(i) {
var ret = "";
var seconds = JSON.parse(input).status.duration;
var days = Math.floor(seconds/(24*60*60));
var restwodays = seconds % (24*60*60);
var hours = Math.floor(restwodays/(60*60));
var restwohours = restwodays % (60*60);
var minutes = Math.floor(restwohours/ 60);
var seconds = restwohours % 60;
var minutess = "" + minutes;
if(minutes<=9) minutess = "0"+minutes;
var secondss = "" + seconds;
if(seconds<=9) secondss = "0"+seconds;
if ( days > 0 ) ret = "" + days + "T ";
if ( hours > 0 ) ret = ret + hours + ":";
if ( minutes > 0 ) ret = ret + minutess + ":";
ret = ret + secondss + "";
return ret;
})(input)
Defined a new string item without a linking to the channel:
String robonect_transform "Dauer aktueller Modus [%s]"
Created a new rule:
automowr_duration.rules
rule TransformRobonectDuration
when
Item robonect_duration received update
then
robonect_transform = transform("JS", "automower_duration.js", robonect_duration.state.toString)
end
Unfortunately resulting in
[ERROR] [ore.transform.actions.Transformation] - Error executing the transformation 'JS': An error occurred while executing script.
[ERROR] [.script.engine.ScriptExecutionThread] - Rule 'TransformRobonectDuration': An error occurred during the script execution: Cannot assign a value in null context.
[ERROR] [.script.engine.ScriptExecutionThread] - Rule 'TransformRobonectDuration': An error occurred during the script execution: Couldn't invoke 'assignValueTo' for feature JvmVoid: (eProxyURI: automower_duration.rules#|::0.2.0.2.0.1::0::/1)
Current rule:
import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import org.joda.time.*
import org.openhab.core.transform.actions.Transformation
rule "TransformRobonectDuration"
when
Item robonect_duration changed
then
var String robonectduration value = transform("JSONPATH", "automower_duration.js", robonect_duration.state.toString)
postUpdate("robonect_transform", robonectduration)
end
import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import org.joda.time.*
import org.openhab.core.transform.actions.Transformation
rule "TransformRobonectDuration"
when
Item robonect_duration changed
then
var robonectduration=transform("JSONPATH", "automower_duration.js", robonect_duration.state.toString)
robonect_transform.postUpdate(robonectduration)
logInfo("test_log","[Test Log]Log entry test...")
end
Item definition
Number robonect_duration "Dauer aktueller Modus [%s]" <grass> {channel="robonect:mower:13b76ca8:mowerStatus#duration" }
String robonect_transform "Dauer aktueller Modus [%s]"
Current status:
Log entry is being created, tested it to determine whether rule kicks in at all, so obviously yes. However, robonect_transform is not updated at all.
I could imagine this is down to JS being wrong, so also this one again for the records:
(function(i) {
var ret = "";
var seconds = JSON.parse(input).status.duration;
var days = Math.floor(seconds/(24*60*60));
var restwodays = seconds % (24*60*60);
var hours = Math.floor(restwodays/(60*60));
var restwohours = restwodays % (60*60);
var minutes = Math.floor(restwohours/ 60);
var seconds = restwohours % 60;
var minutess = "" + minutes;
if(minutes<=9) minutess = "0"+minutes;
var secondss = "" + seconds;
if(seconds<=9) secondss = "0"+seconds;
if ( days > 0 ) ret = "" + days + "T ";
if ( hours > 0 ) ret = ret + hours + ":";
if ( minutes > 0 ) ret = ret + minutess + ":";
ret = ret + secondss + "";
return ret;
})(input)
Yepp, am on OH2. Imports eliminated. I tried JS but that returned an error.
transformation-javascript - 2.1.0 is installed according to PaperUI.
Rule currently looking as followed:
rule "TransformRobonectDuration"
when
Item robonect_duration changed
then
logInfo("test_log","[Test Log]Log entry test...")
var robonectduration=transform("JS", "automower_duration.js", robonect_duration.state.toString)
robonect_transform.postUpdate(robonectduration)
logInfo("FILE",robonectduration)
end
Resulting in following logfile output when robonect_duration gets updated:
==> /var/log/openhab2/events.log <==
2017-07-20 22:40:05.432 [ItemStateChangedEvent ] - robonect_duration changed from 44729 to 44752
==> /var/log/openhab2/openhab.log <==
2017-07-20 22:40:05.433 [INFO ] [ipse.smarthome.model.script.test_log] - [Test Log]Log entry test...
2017-07-20 22:40:05.444 [ERROR] [ore.transform.actions.Transformation] - Error executing the transformation 'JS': An error occurred while executing script.
==> /var/log/openhab2/events.log <==
2017-07-20 22:40:05.447 [ItemStateChangedEvent ] - robonect_transform changed from 44729 to 44752
==> /var/log/openhab2/openhab.log <==
2017-07-20 22:40:05.448 [INFO ] [.eclipse.smarthome.model.script.FILE] - 44752
So I still believe something is wrong with the .js… but it works just fine with the HTTP variant item…
The JavaScript is failing for some reason. I’m no JavaScript expert so all I can suggest is to comment out the bulk of the JS and slowly add back in the lines until you can figure out on what line it is failing.
Okay, so you agree the rule itself should be fine now, but the JS part is having errors and I can continue to try to solve that and leave the rule assuming it’s fine for the time being?