Scripts execute twice or thrice on single press of 'Run Now'

Hi All, posting here after a long time.
So i created a lengthy (~188 lines) ECMA 5.1 script from UI in OH 3.4.5. When I press the Run Now button in the UI, the script executes atleast thrice. I have included logging statements in the script which show me that this is getting exectued multiple times with a single press of the Run Now button. There is no loop or anything in the script.

How can i debug this - could someone tell me which package to set TRACE level of logging to?

Here is snippet of the code and log that shows the problem.

// ... more code
function waitWithTimer(timeInMilliSeconds) {
  var future = new CompletableFuture();
  var timer = ScriptExecution.createTimer(ZonedDateTime.now().plus(timeInMilliSeconds, ChronoUnit.MILLIS), function() {
    future.complete(null);
  });
  
  future.get();
}
function waitWithThread(timeInMilliSeconds) {
  Thread.sleep(timeInMilliSeconds);
}

// .... more code

var AQIs = [
    // location1
    { AQI: JSON.parse(items["JSON_item"]).links[0].AQI, datetime: JSON.parse(items["JSON_item"]).links[0].datetime, LastUpdated: JSON.parse(items["JSON_item"]).links[0].LastUpdated, AQI_itenName: "loc1_itemname", lastUpdated_item_Name: "loc1_itemname_LU", location: "XXXX_1"},
    // location2
    { AQI: JSON.parse(items["JSON_item"]).links[1].AQI, datetime: JSON.parse(items["JSON_item"]).links[1].datetime, LastUpdated: JSON.parse(items["JSON_item"]).links[1].LastUpdated, AQI_itenName: "loc2_itemname", lastUpdated_item_Name: "loc2_itemname_LU", location: "XXXX_2"},
    // location3
    { AQI: JSON.parse(items["JSON_item"]).links[2].AQI, datetime: JSON.parse(items["JSON_item"]).links[2].datetime, LastUpdated: JSON.parse(items["JSON_item"]).links[2].LastUpdated, AQI_itenName: "loc3_itemname", lastUpdated_item_Name: "loc3_itemname_LU", location: "XXXX_3"} 
];

for (var i = 0; i < 3; i++) {
    waitWithTimer(2000);
    var currentAQI = AQIs[i];
    logger.warn("API_AQI: Iteration number: "+i)
    processAQI(
        i,
        currentAQI.AQI,
        currentAQI.datetime,
        currentAQI.LastUpdated,
        currentAQI.AQI_itenName,
        currentAQI.lastUpdated_item_Name,
        currentAQI.location
    );

This the output in log corresponding to the logger statement:

2023-08-22 23:13:10.718 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Iteration number: 0
2023-08-22 23:13:12.903 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Iteration number: 1
2023-08-22 23:13:15.007 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Iteration number: 2
2023-08-22 23:13:17.200 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Iteration number: 0
2023-08-22 23:13:19.314 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Iteration number: 1
2023-08-22 23:13:21.407 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Iteration number: 2
2023-08-22 23:13:23.589 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Iteration number: 0
2023-08-22 23:13:25.682 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Iteration number: 1
2023-08-22 23:13:27.778 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Iteration number: 2

As you can see from the timestamp the for loop gets repeated thrice. the waitWithTimer function works as intended as can also be seen from the timestamps that are 2 secs apart.
Where do i start to sort this out?

Assuming this is literally a Script (i.e. Settings → Script) and not a Script Action that’s part of a rule.

Which browser are you using?

Note, it’s completely unrelated to the question but you have a typo.

shouldn’t that be “itemName”?

The whole waitWithTimer is also a little overdone. Are you just experimenting? If you want to block a rule’s execution the waitWithThread approach is the preferred. Though the real preferred approach would be to not to block at all and use Timers where possible. Again, this doesn’t address your actual question but it’s weirdness I notice. I’ve no experience with CompletableFuture in the context of openHAB rules so cannot rule that out as a potential problem.

You can definitely add a log statement to the top of the rule to see how many times the rule is being triggered. You can change the log level of openhab.event.RuleStatusInfoEvent and you will see “ruleID updated: RUNNING” and “ruleID updated: IDLE” log entries in events.log. That will show you how many times the rule is actually being triggered.

At a minimum you can rule in or out whether this is an issue with the triggers or an issue with the logic in the script.

Thanks for replying.

Yes thats a typo :slight_smile: which has stuck for a long long time. will probably correct that.

I wanted to put a delay timer and realized its a pain to do that in ECMA 5.1. I copied this code from another old thread and while it seemed to work, its not the prioruty right now for me so i commented out the whole function as well as the call to the function. Also enabled Trace for openhab.event.RuleStatusInfoEvent. Still get multiple executions.

2023-08-23 00:38:07.935 [TRACE] [openhab.event.RuleStatusInfoEvent   ] - Received event of type 'RuleStatusInfoEvent' under the topic 'openhab/rules/AQI_API_2/state' with payload: '{"status":"RUNNING","statusDetail":"NONE"}'
2023-08-23 00:38:07.935 [INFO ] [openhab.event.RuleStatusInfoEvent   ] - AQI_API_2 updated: RUNNING


//new log statement right at the begining of the code. getting repeated too:
2023-08-23 00:38:07.935 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: starting the script

2023-08-23 00:38:08.323 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Iteration number: 0
2023-08-23 00:38:13.152 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Iteration number: 1
2023-08-23 00:38:13.337 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Iteration number: 2
2023-08-23 00:38:13.450 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: starting the script
2023-08-23 00:38:13.548 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Iteration number: 0
2023-08-23 00:38:13.795 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Iteration number: 1
2023-08-23 00:38:14.006 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Iteration number: 2
2023-08-23 00:38:14.144 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: starting the script
2023-08-23 00:38:14.370 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Iteration number: 0
2023-08-23 00:38:14.477 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Iteration number: 1
2023-08-23 00:38:14.622 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Iteration number: 2

2023-08-23 00:38:14.740 [TRACE] [openhab.event.RuleStatusInfoEvent   ] - Received event of type 'RuleStatusInfoEvent' under the topic 'openhab/rules/AQI_API_2/state' with payload: '{"status":"IDLE","statusDetail":"NONE"}'
2023-08-23 00:38:14.741 [INFO ] [openhab.event.RuleStatusInfoEvent   ] - AQI_API_2 updated: IDLE

what else can i do?

Edit: just editing to say that I am using Brave on a desktop. Would that matter? Also, yes it’s a plain script, not a rule.

But you’ve shown that the rule isn’t triggering three times. There is one trigger event, the script appears to run three times, and then it goes idle.

Note: TRACE is excessive. We don’t need to see the “Received event of type…” log statements. They don’t add anything to our understanding.

This wasn’t to stop the executions. It’s to figure out what’s going on.

Yes if for some reason the browser was interpreting that one button click on the play icon as three. It doesn’t happen in chrome and I too use brave. But some weirdness has been seen in Firefox and Safari.

The rule isn’t triggering three times so the next is to prove that the it’s not your code. 188 lines of code is not that much, post the full rule.

I just realized what you meant here. it was an edit and typo to the main script, just a place holder. have edited it below.

Here is the full script. At the moment i am only executing it from the Run Now button.
AQI and related data is already stored in an item called JSON_Item_Name by another script. It can have real values or error. This script extracts the value and checks for Error. if no error, then it will store the values in individual items or else fall back on API to get the values.

'use strict';
var logger = Java.type("org.slf4j.LoggerFactory").getLogger("org.openhab.model.script.Rules");
logger.warn("API_AQI: starting the script")

var Transformation = Java.type("org.openhab.core.transform.actions.Transformation");
var HttpUtil = Java.type("org.openhab.core.model.script.actions.HTTP");
var HashMap = Java.type("java.util.HashMap");

//baseURL to get the AQI values - there are two endpoints with this baseURL - one for the token and other for the AQI itself
var baseUrl = "<API_URL>";

var currentDate = new Date();
var commonHeaders = new HashMap();
commonHeaders.put("Host", "<API_HOST>");

//dayjs library included to format the timestamps in local timezone
(function() {
    load('https://cdn.jsdelivr.net/npm/dayjs@1.9.5/dayjs.min.js');
    load('https://cdn.jsdelivr.net/npm/dayjs@1.9.5/plugin/utc.js');
    dayjs.extend(dayjs_plugin_utc);
})();

//API token is stored in an item for re-use.
var tokenItem = ir.getItem("API_token");	
var token = tokenItem.state.toString();		
logger.warn("API_AQI: first try to get token from registry: "+token.toString());
var headers = new HashMap(commonHeaders);

//if token is avialble then add it to the headers.
if (token) {								
    headers.put("authorization", token);
}

//this function is called only if token is not availble - and is used to get the token and store in the item
function performLogin() {					
    var postData = "email=user@host.com&password=password";
    var loginHeaders = new HashMap(commonHeaders);
    loginHeaders.put("content-type", "application/x-www-form-urlencoded");
    loginHeaders.put("content-length", String(postData.length));
    loginHeaders.put("accept-encoding", "gzip");
    
	//get the token from this URL
	var loginUrl = "<API_login_URL>";		
    logger.warn("API_AQI: performing login to get token")
    
	//HTTP GET call to the API
	var loginResponse = HttpUtil.sendHttpPostRequest(loginUrl, "application/x-www-form-urlencoded", postData, loginHeaders, 10000);
    logger.warn("API_AQI: login response: "+loginResponse.toString());
    var loginData = JSON.parse(loginResponse);
    var token = loginData.data.token;
    logger.warn("API_AQI: token: "+token.toString());
    
	//store the token for later re-use
	events.sendCommand(tokenItem,token.toString());		
}

//this is the main function to check validity of token and get the AQI value from an API using the token
function apiAQI(location) {								
   logger.warn("API_AQI: calling API function for location:"+location) 

  if (token === "NULL" || token === "UNDEF") {
        logger.warn("API_AQI: Token not found in items, going for login");
        
		//if token is not found in the item registry, then go for login - call the function above.
		performLogin();									
        tokenItem = ir.getItem("API_token");
        token = tokenItem.state.toString();
        
		//recreate the header after the token has been obtained via the API, and stored in the item.
		headers.put("authorization", token);			
    }
  else
    { //if token is availble (not NULL and not UNDEF), then go for AQI API
     logger.warn("API_AQI: token available, proceeding with getting location details")
	 }		
    
	//add location information to AQI API header
	headers.put("loc_id", location);					
    headers.put("searchtype", "loc_id");
	
	//get the AQI using the API - this is first attempt as we need to check the validity of the stored token
    var apiResponse = HttpUtil.sendHttpGetRequest(baseUrl, headers, 10000);			
    var jsonObject = JSON.parse(apiResponse);

//if the previously stored token is invalid as per API response, get a new token
if (jsonObject.message && jsonObject.message.indexOf("Invalid token") !== -1) {		
        logger.warn("API_AQI: Invalid Token, going for login");
        performLogin();
        tokenItem = ir.getItem("API_token");
        token = tokenItem.state.toString();
        headers.put("authorization", token);
		
		//get the AQI using the API - this is second and final attempt
        apiResponse = HttpUtil.sendHttpGetRequest(baseUrl, headers, 10000);			
        jsonObject = JSON.parse(apiResponse);
    }
    logger.warn("API_AQI: jsonobject: "+apiResponse.toString());					
    
	//process the API response to extract the data from JSON response
	var loc_Name = jsonObject.Locations[0].loc_Name || "NA";						
    var loc_id = jsonObject.Locations[0].loc_id || "NA";							
    var last_updated_at = jsonObject.Locations[0].last_updated_at || "NA";			
	
	//this statement works - its used to extract AQI value from the json response
    var sensorData_AQI_Value = Transformation.transform("JSONPATH", "$.Locations[0].AQIComponents[?(@.sensorName == 'AQI')].sensorData",apiResponse) || "NA";
																					
    logger.warn("API_AQI: Location Name: " + loc_Name);
    logger.warn("API_AQI: Location ID: " + loc_id);
    logger.warn("API_AQI: Updated At: " + last_updated_at);
    logger.warn("API_AQI: Sensor Data AQI: " + sensorData_AQI_Value);

    return {
        last_updated_at: last_updated_at,
        sensorData_AQI_Value: sensorData_AQI_Value
    };
}

function processAQI(index, AQI, datetime, LastUpdated, AQI_itemName, lastUpdated_item_Name, location) {
    var newLastUpdated = LastUpdated;
    var timeDiff = 0;

    if (AQI !== "Error!") {
        timeDiff = calculateTimeDifference(newLastUpdated);
		
		//reject stale values of 4 hours or older
        if (timeDiff > 4) {
            AQI = "NA";
            newLastUpdated = "NA";
        }
    } else {
        //if AQI returned value is error, then just assume NA
		AQI = "NA";		
        newLastUpdated = "NA";
    }
		
	//since we got error from item, we will attempt to obtain the value from API
    if (AQI == "NA") {
        logger.warn("API_AQI: going for API")		
        var API_AQI_data = apiAQI(location);
        AQI = API_AQI_data.sensorData_AQI_Value;
        newLastUpdated = API_AQI_data.last_updated_at;
    }
	
	//send the value as received - either from the JSON_Item_name or the API
    events.sendCommand(AQI_itemName, AQI);			
    events.sendCommand(lastUpdated_item_Name, dayjs(newLastUpdated).local().format());
    logger.warn("API_AQI: Finished")
}

//AQI and related data is already stored in an item called JSON_Item_Name by another script. it can have real values or error. this script extracts the value and checks for Error. if no error, then it will store the values in individual items or else fall back on API to get the values. the JSON_item_name has AQI, a datetime value when the value was obtained (irrelevant in rest of this script), last updated time of the AQI value (used to calculated staleness of the data). we also include the corresponding item names within this json structure.

var AQIs = [
    // location1
    { AQI: JSON.parse(items["JSON_Item_Name"]).links[0].AQI, datetime: JSON.parse(items["JSON_Item_Name"]).links[0].datetime, LastUpdated: JSON.parse(items["JSON_Item_Name"]).links[0].LastUpdated, AQI_itenName: "AQI_Location1", lastUpdated_item_Name: "ObservationTime_Location1", location: "<location_ID_1>"},
    // location2
    { AQI: JSON.parse(items["JSON_Item_Name"]).links[1].AQI, datetime: JSON.parse(items["JSON_Item_Name"]).links[1].datetime, LastUpdated: JSON.parse(items["JSON_Item_Name"]).links[1].LastUpdated, AQI_itenName: "AQI_Location2", lastUpdated_item_Name: "ObservationTime_Location2", location: "<location_ID_2>"},
    // location3
    { AQI: JSON.parse(items["JSON_Item_Name"]).links[2].AQI, datetime: JSON.parse(items["JSON_Item_Name"]).links[2].datetime, LastUpdated: JSON.parse(items["JSON_Item_Name"]).links[2].LastUpdated, AQI_itenName: "AQI_Location3", lastUpdated_item_Name: "ObservationTime_Location3", location: "<location_ID_3>"} 
];

for (var i = 0; i < 3; i++) {
	
	//this is the main loop that needs to be iterated only 3 times. 
    var currentAQI = AQIs[i];						
    logger.warn("API_AQI: Iteration number: "+i)
    processAQI(
        i,
        currentAQI.AQI,
        currentAQI.datetime,
        currentAQI.LastUpdated,
        currentAQI.AQI_itenName,
        currentAQI.lastUpdated_item_Name,
        currentAQI.location
    );

}

here is the log in two diffferent situations. First one where API is invoked - the script executes 6 times within 2 seconds and a single press of the Run Now. And the second set is when API is not invoked - executed a total of 3 times. I am totally lost here why this is happening.

2023-08-23 14:08:35.473 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: starting the script
2023-08-23 14:08:35.601 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: first try to get token from registry: <<token>>

2023-08-23 14:08:35.602 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Iteration number: 0
2023-08-23 14:08:35.604 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Error value retreived. discarding state values
2023-08-23 14:08:35.605 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: going for API
2023-08-23 14:08:35.612 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: calling API function for location:location_ID_1
2023-08-23 14:08:35.613 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: token available, proceeding with getting location details
2023-08-23 14:08:35.824 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: jsonobject: <<AQI JSON response>>
2023-08-23 14:08:35.826 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Location Name: location_name_1
2023-08-23 14:08:35.827 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Location ID: location_ID_1
2023-08-23 14:08:35.827 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Updated At: 23 Aug 2023, 01:56pm
2023-08-23 14:08:35.828 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Sensor Data AQI-IN: 87
2023-08-23 14:08:35.842 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Finished

2023-08-23 14:08:35.843 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Iteration number: 1
2023-08-23 14:08:35.845 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Error value retreived. discarding state values
2023-08-23 14:08:35.846 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: going for API
2023-08-23 14:08:35.847 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: calling API function for location:location_ID_2
2023-08-23 14:08:35.848 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: token available, proceeding with getting location details
2023-08-23 14:08:35.953 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: jsonobject: <<AQI JSON response>>
2023-08-23 14:08:35.955 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Location Name: location_name_2
2023-08-23 14:08:35.956 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Location ID: location_ID_2
2023-08-23 14:08:35.957 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Updated At: 23 Aug 2023, 01:56pm
2023-08-23 14:08:35.957 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Sensor Data AQI: 48
2023-08-23 14:08:35.960 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Finished

2023-08-23 14:08:35.961 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Iteration number: 2
2023-08-23 14:08:35.961 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Error value retreived. discarding state values
2023-08-23 14:08:35.962 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: going for API
2023-08-23 14:08:35.963 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: calling API function for location:location_ID_3
2023-08-23 14:08:35.963 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: token available, proceeding with getting location details
2023-08-23 14:08:36.053 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: jsonobject: <<AQI JSON response>>
2023-08-23 14:08:36.054 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Location Name: location_name_3
2023-08-23 14:08:36.055 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Location ID: location_ID_3
2023-08-23 14:08:36.056 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Updated At: 23 Aug 2023, 01:56pm
2023-08-23 14:08:36.056 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Sensor Data AQI: 47
2023-08-23 14:08:36.058 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Finished

2023-08-23 14:08:36.060 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: starting the script
2023-08-23 14:08:36.118 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: first try to get token from registry: <<token>>

2023-08-23 14:08:36.119 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Iteration number: 0
2023-08-23 14:08:36.120 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Error value retreived. discarding state values
2023-08-23 14:08:36.120 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: going for API
2023-08-23 14:08:36.121 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: calling API function for location:location_ID_1
2023-08-23 14:08:36.121 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: token available, proceeding with getting location details
2023-08-23 14:08:36.210 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: jsonobject: <<AQI JSON  response>>
2023-08-23 14:08:36.212 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Location Name: location_name_1
2023-08-23 14:08:36.212 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Location ID: location_ID_1
2023-08-23 14:08:36.213 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Updated At: 23 Aug 2023, 01:56pm
2023-08-23 14:08:36.213 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Sensor Data AQI: 87
2023-08-23 14:08:36.216 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Finished

2023-08-23 14:08:36.217 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Iteration number: 1
2023-08-23 14:08:36.218 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Error value retreived. discarding state values
2023-08-23 14:08:36.218 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: going for API
2023-08-23 14:08:36.219 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: calling API function for location:location_ID_2
2023-08-23 14:08:36.219 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: token available, proceeding with getting location details
2023-08-23 14:08:36.308 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: jsonobject: <<AQI JSON response>>
2023-08-23 14:08:36.309 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Location Name: location_name_2
2023-08-23 14:08:36.310 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Location ID: location_ID_2
2023-08-23 14:08:36.310 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Updated At: 23 Aug 2023, 01:56pm
2023-08-23 14:08:36.311 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Sensor Data AQI: 48
2023-08-23 14:08:36.313 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Finished

2023-08-23 14:08:36.315 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Iteration number: 2
2023-08-23 14:08:36.315 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Error value retreived. discarding state values
2023-08-23 14:08:36.316 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: going for API
2023-08-23 14:08:36.316 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: calling API function for location:location_ID_3
2023-08-23 14:08:36.317 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: token available, proceeding with getting location details
2023-08-23 14:08:36.403 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: jsonobject: <<AQI JSON response>>
2023-08-23 14:08:36.404 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Location Name: location_name_3
2023-08-23 14:08:36.405 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Location ID: location_ID_3
2023-08-23 14:08:36.405 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Updated At: 23 Aug 2023, 01:56pm
2023-08-23 14:08:36.405 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Sensor Data AQI: 47
2023-08-23 14:08:36.408 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Finished

2023-08-23 14:08:36.409 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: starting the script
2023-08-23 14:08:36.457 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: first try to get token from registry: <<token>>

2023-08-23 14:08:36.459 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Iteration number: 0
2023-08-23 14:08:36.460 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Error value retreived. discarding state values
2023-08-23 14:08:36.460 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: going for API
2023-08-23 14:08:36.461 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: calling API function for location:location_ID_1
2023-08-23 14:08:36.461 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: token available, proceeding with getting location details
2023-08-23 14:08:36.555 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: jsonobject: <<AQI JSON response>>
2023-08-23 14:08:36.556 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Location Name: location_name_1
2023-08-23 14:08:36.557 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Location ID: location_ID_1
2023-08-23 14:08:36.557 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Updated At: 23 Aug 2023, 01:56pm
2023-08-23 14:08:36.558 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Sensor Data AQI: 87
2023-08-23 14:08:36.563 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Finished

2023-08-23 14:08:36.564 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Iteration number: 1
2023-08-23 14:08:36.564 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Error value retreived. discarding state values
2023-08-23 14:08:36.564 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: going for API
2023-08-23 14:08:36.565 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: calling API function for location:location_ID_2
2023-08-23 14:08:36.565 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: token available, proceeding with getting location details
2023-08-23 14:08:36.650 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: jsonobject: <<AQI JSON response>>
2023-08-23 14:08:36.651 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Location Name: location_name_2
2023-08-23 14:08:36.652 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Location ID: location_ID_2
2023-08-23 14:08:36.652 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Updated At: 23 Aug 2023, 01:56pm
2023-08-23 14:08:36.652 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Sensor Data AQI: 48
2023-08-23 14:08:36.654 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Finished

2023-08-23 14:08:36.655 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Iteration number: 2
2023-08-23 14:08:36.655 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Error value retreived. discarding state values
2023-08-23 14:08:36.655 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: going for API
2023-08-23 14:08:36.656 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: calling API function for location:location_ID_3
2023-08-23 14:08:36.656 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: token available, proceeding with getting location details
2023-08-23 14:08:36.741 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: jsonobject: <<AQI JSON response>>
2023-08-23 14:08:36.742 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Location Name: location_name_3
2023-08-23 14:08:36.742 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Location ID: location_ID_3
2023-08-23 14:08:36.743 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Updated At: 23 Aug 2023, 01:56pm
2023-08-23 14:08:36.743 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Sensor Data AQI: 47
2023-08-23 14:08:36.745 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Finished

2023-08-23 14:08:36.747 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: starting the script
2023-08-23 14:08:36.796 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: first try to get token from registry: <<token>>

2023-08-23 14:08:36.798 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Iteration number: 0
2023-08-23 14:08:36.798 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Error value retreived. discarding state values
2023-08-23 14:08:36.799 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: going for API
2023-08-23 14:08:36.799 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: calling API function for location:location_ID_1
2023-08-23 14:08:36.800 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: token available, proceeding with getting location details
2023-08-23 14:08:36.886 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: jsonobject: <<AQI JSON response>>
2023-08-23 14:08:36.887 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Location Name: location_name_1
2023-08-23 14:08:36.888 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Location ID: location_ID_1
2023-08-23 14:08:36.888 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Updated At: 23 Aug 2023, 01:56pm
2023-08-23 14:08:36.889 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Sensor Data AQI: 87
2023-08-23 14:08:36.891 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Finished

2023-08-23 14:08:36.892 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Iteration number: 1
2023-08-23 14:08:36.893 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Error value retreived. discarding state values
2023-08-23 14:08:36.893 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: going for API
2023-08-23 14:08:36.894 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: calling API function for location:location_ID_2
2023-08-23 14:08:36.894 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: token available, proceeding with getting location details
2023-08-23 14:08:36.977 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: jsonobject: <<AQI JSON response>>
2023-08-23 14:08:36.978 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Location Name: location_name_2
2023-08-23 14:08:36.979 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Location ID: location_ID_2
2023-08-23 14:08:36.979 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Updated At: 23 Aug 2023, 01:56pm
2023-08-23 14:08:36.980 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Sensor Data AQI: 48
2023-08-23 14:08:36.982 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Finished

2023-08-23 14:08:36.982 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Iteration number: 2
2023-08-23 14:08:36.983 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Error value retreived. discarding state values
2023-08-23 14:08:36.983 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: going for API
2023-08-23 14:08:36.984 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: calling API function for location:location_ID_3
2023-08-23 14:08:36.984 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: token available, proceeding with getting location details
2023-08-23 14:08:37.066 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: jsonobject: <<AQI JSON response>>
2023-08-23 14:08:37.066 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Location Name: location_name_3
2023-08-23 14:08:37.067 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Location ID: location_ID_3
2023-08-23 14:08:37.067 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Updated At: 23 Aug 2023, 01:56pm
2023-08-23 14:08:37.067 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Sensor Data AQI: 47
2023-08-23 14:08:37.069 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Finished

2023-08-23 14:08:37.070 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: starting the script
2023-08-23 14:08:37.120 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: first try to get token from registry: <<token>>

2023-08-23 14:08:37.122 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Iteration number: 0
2023-08-23 14:08:37.122 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Error value retreived. discarding state values
2023-08-23 14:08:37.123 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: going for API
2023-08-23 14:08:37.123 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: calling API function for location:location_ID_1
2023-08-23 14:08:37.124 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: token available, proceeding with getting location details
2023-08-23 14:08:37.207 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: jsonobject: <<AQI JSON response>>
2023-08-23 14:08:37.208 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Location Name: location_name_1
2023-08-23 14:08:37.209 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Location ID: location_ID_1
2023-08-23 14:08:37.210 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Updated At: 23 Aug 2023, 01:56pm
2023-08-23 14:08:37.210 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Sensor Data AQI: 87
2023-08-23 14:08:37.215 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Finished

2023-08-23 14:08:37.216 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Iteration number: 1
2023-08-23 14:08:37.216 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Error value retreived. discarding state values
2023-08-23 14:08:37.217 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: going for API
2023-08-23 14:08:37.217 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: calling API function for location:location_ID_2
2023-08-23 14:08:37.217 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: token available, proceeding with getting location details
2023-08-23 14:08:37.303 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: jsonobject: <<AQI JSON response>>
2023-08-23 14:08:37.305 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Location Name: location_name_2
2023-08-23 14:08:37.305 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Location ID: location_ID_2
2023-08-23 14:08:37.306 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Updated At: 23 Aug 2023, 01:56pm
2023-08-23 14:08:37.306 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Sensor Data AQI: 48
2023-08-23 14:08:37.308 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Finished

2023-08-23 14:08:37.309 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Iteration number: 2
2023-08-23 14:08:37.309 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Error value retreived. discarding state values
2023-08-23 14:08:37.310 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: going for API
2023-08-23 14:08:37.310 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: calling API function for location:location_ID_3
2023-08-23 14:08:37.310 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: token available, proceeding with getting location details
2023-08-23 14:08:37.396 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: jsonobject: <<AQI JSON response>>
2023-08-23 14:08:37.397 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Location Name: location_name_3
2023-08-23 14:08:37.397 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Location ID: location_ID_3
2023-08-23 14:08:37.398 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Updated At: 23 Aug 2023, 01:56pm
2023-08-23 14:08:37.398 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Sensor Data AQI: 47
2023-08-23 14:08:37.400 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Finished

2023-08-23 14:08:37.401 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: starting the script
2023-08-23 14:08:37.436 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: first try to get token from registry: <<token>>

2023-08-23 14:08:37.438 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Iteration number: 0
2023-08-23 14:08:37.438 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Error value retreived. discarding state values
2023-08-23 14:08:37.439 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: going for API
2023-08-23 14:08:37.439 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: calling API function for location:location_ID_1
2023-08-23 14:08:37.439 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: token available, proceeding with getting location details
2023-08-23 14:08:37.522 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: jsonobject: <<AQI JSON response>>]}
2023-08-23 14:08:37.523 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Location Name: location_name_1
2023-08-23 14:08:37.523 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Location ID: location_ID_1
2023-08-23 14:08:37.523 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Updated At: 23 Aug 2023, 01:56pm
2023-08-23 14:08:37.524 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Sensor Data AQI: 87
2023-08-23 14:08:37.526 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Finished

2023-08-23 14:08:37.526 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Iteration number: 1
2023-08-23 14:08:37.527 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Error value retreived. discarding state values
2023-08-23 14:08:37.527 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: going for API
2023-08-23 14:08:37.528 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: calling API function for location:location_ID_2
2023-08-23 14:08:37.528 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: token available, proceeding with getting location details
2023-08-23 14:08:37.614 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: jsonobject: <<AQI JSON response>>
2023-08-23 14:08:37.615 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Location Name: location_name_2
2023-08-23 14:08:37.616 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Location ID: location_ID_2
2023-08-23 14:08:37.616 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Updated At: 23 Aug 2023, 01:56pm
2023-08-23 14:08:37.617 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Sensor Data AQI: 48
2023-08-23 14:08:37.619 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Finished

2023-08-23 14:08:37.620 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Iteration number: 2
2023-08-23 14:08:37.621 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Error value retreived. discarding state values
2023-08-23 14:08:37.622 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: going for API
2023-08-23 14:08:37.622 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: calling API function for location:location_ID_3
2023-08-23 14:08:37.623 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: token available, proceeding with getting location details
2023-08-23 14:08:37.710 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: jsonobject: <<AQI JSON response>>
2023-08-23 14:08:37.712 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Location Name: location_name_3
2023-08-23 14:08:37.713 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Location ID: location_ID_3
2023-08-23 14:08:37.714 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Updated At: 23 Aug 2023, 01:56pm
2023-08-23 14:08:37.715 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Sensor Data AQI: 47
2023-08-23 14:08:37.718 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Finished```

2023-08-23 13:53:02.567 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: starting the script
2023-08-23 13:53:02.963 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: first try to get token from registry: <<token>>

2023-08-23 13:53:03.129 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Iteration number: 0
2023-08-23 13:53:03.147 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Non Error values retreived. Not invoking API
2023-08-23 13:53:03.486 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Finished
2023-08-23 13:53:03.487 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Iteration number: 1
2023-08-23 13:53:03.489 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Non Error values retreived. Not invoking API
2023-08-23 13:53:03.506 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Finished
2023-08-23 13:53:03.507 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Iteration number: 2
2023-08-23 13:53:03.508 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Non Error values retreived. Not invoking API
2023-08-23 13:53:03.513 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Finished

2023-08-23 13:53:03.515 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: starting the script
2023-08-23 13:53:03.575 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: first try to get token from registry: <<token>>

2023-08-23 13:53:03.581 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Iteration number: 0
2023-08-23 13:53:03.583 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Non Error values retreived. Not invoking API
2023-08-23 13:53:03.588 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Finished
2023-08-23 13:53:03.589 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Iteration number: 1
2023-08-23 13:53:03.589 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Non Error values retreived. Not invoking API
2023-08-23 13:53:03.591 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Finished
2023-08-23 13:53:03.592 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Iteration number: 2
2023-08-23 13:53:03.592 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Non Error values retreived. Not invoking API
2023-08-23 13:53:03.594 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Finished

2023-08-23 13:53:03.595 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: starting the script
2023-08-23 13:53:03.651 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: first try to get token from registry: <<token>>

2023-08-23 13:53:03.653 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Iteration number: 0
2023-08-23 13:53:03.654 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Non Error values retreived. Not invoking API
2023-08-23 13:53:03.660 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Finished
2023-08-23 13:53:03.661 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Iteration number: 1
2023-08-23 13:53:03.662 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Non Error values retreived. Not invoking API
2023-08-23 13:53:03.664 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Finished
2023-08-23 13:53:03.665 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Iteration number: 2
2023-08-23 13:53:03.665 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Non Error values retreived. Not invoking API
2023-08-23 13:53:03.667 [WARN ] [org.openhab.model.script.Rules      ] - API_AQI: Finished

function processAQI is calling itself. You probably just wanted to log it out but you do a function call.

hi Oliver, i cant see anywhere that processAQI is called twice. Which line are you referring to?
Also from the logs if you notice the first logger.warn statement that logs API_AQI: starting the script gets executed multiple times. from the script we can see that this statement is outside any function, and infact right at the start of the script (line 3) which leads me to beleive that the whole script starts executing itself again and again.

I might be wrong. Reading your code on a mobile phone.
Within your function processAQI after your last console.warn statement there is another processAQI call.

EDIT
Sorry. I am wrong. Forget my post

EDIT
At least there is a „;“ missing after your last logger.warn statement

what happens if you simply copy the loop into a separate rule and execute it?

It’s still there. Inside the for loop you have currentAQI.AQI_itenName. Though looking at where you populate AQIs you use itenName there too so it’s still a typo but because it’s in both places the code still works.

When posting logs, please keep the events showing when the rule goes to RUNNING and back to IDLE so we can continue to confirm that the rule is only triggering once.

I see nothing in the code that stands out as a problem (beyond the fact that it’s ECMAScript 5.1 :wink: ).

Does this happen to all manually triggered scripts on your machine or just this one?

Does this happen if this script is called from another rule?

If it’s just this one, try reducing it to the bare minimum code where the problem persists. We’ll need that to help reproduce it when/if we file an issue.

I’m currently unable to reproduce the error and until we can do that I’m not sure what can be done. The one difference is I don’t have Nashorn installed. Maybe there’s a bug in the add-on?

I am not sure why or what happened. but it seems to be solved for now. i copied the whole script into a new script and disabled the old one. I wanted to remove parts of the code one by one to see what happens, but even before i did that, it turned out to be ok in the new script with the whole code. its executing only once as inteded. No clue what happened here. But i’ll keep monitoring. thanks for the suggestions.

Very weird indeed. The only think I can think of is somehow something weird got saved to the JSONDB.

If you still have the broken rule, have a look at the JSONDB entry for it. Maybe something is going on like it has three identical actions saved or something like that. It’s the only thing I can think of as to what would cause the behavior.

Bingo. Thanks for the pointer. the JSONDB indeed had a few lines repeated for this script. below is the extract from the JSONDB. top part is the problem script AQI_API_2 that is getting executed multiple times. I have marked out the repeated lines, there are three script.ScriptAction - two are clearly redundant. The new script AQI_API_Test with the same script code doesnt have these extra scriptAction lines.

Now I also removed these two sets of lines from the JSONDB to test and the script was executing only once and then I reverted the changes and the script started executing thrice again. So this is reproducible and definitely the issue here. I dont know why this got saved like this in the JSONDB. Maybe something went wrong at the time of first saving this script.

"AQI_API_2": {
    "class": "org.openhab.core.automation.dto.RuleDTO",
    "value": {
      "triggers": [],
      "conditions": [],
      "actions": [
        {
          "inputs": {},
          "id": "script",
          "configuration": {
            "script": <<script>>,				//removed the actual script
            "type": "application/javascript"
          },
          "type": "script.ScriptAction"
        },
		
		// problem part of the json object starts here
        {
          "inputs": {},
          "id": "script",
          "configuration": {
            "script": "",
            "type": "application/javascript"
          },
          "type": "script.ScriptAction"
        },
        {
          "inputs": {},
          "id": "script",
          "configuration": {
            "script": "",
            "type": "application/javascript"
          },
          "type": "script.ScriptAction"
        }
		// problem part of the json object ends here
		
      ],
      "configuration": {},
      "configDescriptions": [],
      "uid": "AQI_API_2",
      "name": "AQI_API_2",
      "tags": [
        "Script"
      ],
      "visibility": "VISIBLE",
      "description": ""
    }
  },
  "AQI_API_Test": {
    "class": "org.openhab.core.automation.dto.RuleDTO",
    "value": {
      "triggers": [],
      "conditions": [],
      "actions": [
        {
          "inputs": {},
          "id": "script",
          "configuration": {
            "script": <<script>>,
            "type": "application/javascript"
          },
          "type": "script.ScriptAction"
        }
      ],
      "configuration": {},
      "configDescriptions": [],
      "uid": "AQI_API_Test",
      "name": "AQI API TEST",
      "tags": [
        "Script"
      ],
      "visibility": "VISIBLE",
      "description": ""
    }
  },

Thanks a ton for the guidance! was a good learning experience.

Now we know what caused it and can watch out for that in the future. I couldn’t begin to guess how the entry in JSONDB got saved like this. In a normal rule, it’s possible to have more than one action. In that case the “id” of the action becomes a one up number.

Scripts are a special case of a rule. They only have one Script Action and the ID of the Action gets set to “Script”. Somehow this Script ended up with three actions, all with the unique ID of script. I’m guessing that the actual code gets saved in a map keyed on the ID. When the rule runs it iterates over the actions and calls the code with the for that action. Since the IDs are all the same, the same script executes three times.

I can’t imagine how these extra two actions became part of the Script. But there might be some better error checking in OH core to detect and deal with this situation so I’ll open an issue.

1 Like

Great stuff. thank you!!