Hi all,
I’ve got an issue with a .js which should transform the value of an item which is returned in seconds from the binding to a more human readable format.
To achieve that, I created 2 items, one bound to the channel and one not bound:
Number robonect_duration "Dauer aktueller Modus [%s]" <grass> {channel="robonect:mower:13b76ca8:mowerStatus#duration" }
Number robonect_transform "Dauer aktueller Modus [%s]"
The rule to transform currently looks like that:
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
Looking at the logs, the rule seems to be kicking in correctly, but the actual script execution to transform is failing:
==> /var/log/openhab2/openhab.log <==
2017-07-21 08:59:03.379 [INFO ] [ipse.smarthome.model.script.test_log] - [Test Log]Log entry test...
2017-07-21 08:59:03.387 [ERROR] [ore.transform.actions.Transformation] - Error executing the transformation 'JS': An error occurred while executing script.
==> /var/log/openhab2/events.log <==
2017-07-21 08:59:03.393 [ItemStateChangedEvent ] - robonect_transform changed from 963 to 1001
==> /var/log/openhab2/openhab.log <==
2017-07-21 08:59:03.396 [INFO ] [.eclipse.smarthome.model.script.FILE] - 1001
So whatever error occurs when executing the script.
The actual script:
automower_duration.js
(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)
I am on openHAB 2.1, transformation-javascript - 2.1.0 is installed according to Paper UI.
Can someone please help me to correct the code?
Thanks,
Ben