Click here for system info
runtimeInfo:
version: 3.2.0
buildString: Release Build
locale: en-GB
systemInfo:
configFolder: /etc/openhab
userdataFolder: /var/lib/openhab
logFolder: /var/log/openhab
javaVersion: 11.0.13
javaVendor: Azul Systems, Inc.
javaVendorVersion: Zulu11.52+13-CA
osName: Linux
osVersion: 5.11.22-5-pve
osArchitecture: amd64
availableProcessors: 2
freeMemory: 61696984
totalMemory: 299892736
bindings:
- astro
- gpstracker
- http
- mqtt
- network
I have the following Item defined via the UI:
{
"link": "http://openhab.lan/rest/items/strSolarData",
"state": "{2021-12-29=569, 2021-12-30=469}",
"stateDescription": {
"readOnly": true,
"options": []
},
"editable": true,
"type": "String",
"name": "strSolarData",
"label": "Solar data",
"category": "",
"tags": [],
"groupNames": []
}
It is linked to an HTTP Binding Channel, and receives a JSON string. Currently, the Item has the following value:
{2021-12-29=569, 2021-12-30=469}
I have been trying to use Blockly to split this string at the comma. Below is my first attempt:
Code
var i;
var logger = Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.rule.' + ctx.ruleUID);
var i_list = itemRegistry.getItem('strSolarData').getState().split(',');
for (var i_index in i_list) {
i = i_list[i_index];
logger.warn(i);
}
Unfortunately, I get the following error in the log when clicking Run Now:
[ERROR] [.internal.handler.ScriptActionHandler] - Script execution of rule with UID '6caf048c18' failed: TypeError: (itemRegistry.getItem("strSolarData").getState()).split is not a function in <eval> at line number 6
OK, so thereâs a TypeError. Strange, because itâs a String Item, and Iâm trying to perform a function (split) which is usually performed on Strings. Maybe the get state of item block isnât returning a String? To test this, I modified the code to force the variable to store itself as a String by deliberately appending ââ:
Code
var item_state, i;
var logger = Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.rule.' + ctx.ruleUID);
item_state = itemRegistry.getItem('strSolarData').getState();
item_state += '';
var i_list = item_state.split(',');
for (var i_index in i_list) {
i = i_list[i_index];
logger.warn(i);
}
Success! I get the following in the log:
15:47:31.970 [WARN ] [org.openhab.rule.6caf048c18 ] - {2021-12-29=569
15:47:31.992 [WARN ] [org.openhab.rule.6caf048c18 ] - 2021-12-30=469}
According to the current reference documentation the get state of item block should be returning a String.
returns the state of an item as a String like ON/OFF, the temperature value etc.
but that doesnât seem to be the case for me.
Do I have something mis-configured?