Tag Change Help

Hello all!

I currently have a script that needs to save a value to a tag.

client = system.net.httpClient()
location_id = '1234'
token = '1234'

params = { 'location': location_id, 'start_time': '2023-03-13 00:00', 'end_time': '2023-03-13 00:10', 'data_type': '2' }

response = client.get('https://www.someurl.com/', params = params, headers = headers)
system.tag.write('Tag Name', response.json)

In the above script, start_time and end_time need to change every 10 minutes to get the updated value and then written to the tag. Currently, I have the tag set up as a Memory but I'm not quite sure if it needs to be done as a Gateway Tag Change or as an event on the tag itself.

Any info would be greatly appreciated, thank you!

  1. Put your script into a project library package (e.g., named utils):
_client = system.net.httpClient()

def getLocationInfo(location_id, token, start_time=None, end_time=None):
	date_format = "yyyy-MM-dd HH:mm"

	if start_time is None:
		start_time = system.date.now()
	start_time = system.date.format(start_time, date_format)
	if end_time is None:
		end_time = system.date.addMinutes(start_time, 10)
	end_time = system.date.format(end_time, date_format)

	params = { 
		'location': location_id,
		'start_time': start_time,
		'end_time': end_time,
		'data_type': '2'
	}

	response = client.get('https://www.someurl.com/', params = params, headers = headers)
	return response.json
  1. Set your 'Gateway Scripting Project' to the project that contains the project library.
  2. Create an expression tag. Make sure it's set to 'event driven' execution.
  3. Give it an expression like this:
    runScript("utils.getLocationInfo", 1000 * 60 * 10, 'locationId', 'token')

runScript will automatically trigger at a ten minute rate. The function will be invoked with the passed in arguments, which will automatically end up as now and now + 10 minutes.

@PGriffith What do you mean by Set your 'Gateway Scripting Project' to the project that contains the project library? Do I create a new script under the Project Library and name it utils?

To use runScript in an expression tag, you need to have your gateway scripting project (set in the gateway settings via the web interface) defined. You will want to create a project, a project library script within it, and use that reference in the expression. You don't have to use the actual name utils, just make sure the names line up.

I am getting an Error_Configuration. I'm sure I'm probably messing up some where.