How to make the script run time change

Hello. I have a gateway script that fires at a given time. How can I make a given time tied to a tag? I need to change the execution time of a script by entering the time in a memory tag.

type or paste code here
```from time import localtime, strftime 
curTime = strftime("%H:%M", localtime())
if curTime == "07:47":
	PR_value = system.tag.read('[default]TESTSTARTSTOP/09:00').value
	tags = ['[default]TESTSTARTSTOP/Active power9']
	values = [PR_value]
	system.tag.writeAll(tags, values)

I need instead of the value β€œ07:47” to take the values ​​of the memory tag.

from time import localtime, strftime 
curTime = strftime("%H:%M", localtime())
setpointTime = strftime("%H:%M", system.tag.read("[default]DateTypeMemoryTag").value)
if curTime == setpointTime:
	PR_value = system.tag.read('[default]TESTSTARTSTOP/09:00').value
	tags = ['[default]TESTSTARTSTOP/Active power9']
	values = [PR_value]
	system.tag.writeAll(tags, values)

No?

Error
Traceback (most recent call last):
File β€œβ€, line 3, in
TypeError: strftime(): 2nd arg can’t be coerced to org.python.core.PyTuple

from time import localtime, strftime 
curTime = system.date.format(system.date.now(), 'HH:mm')
setpointTime = system.date.format(system.tag.read("[default]DateTypeMemoryTag").value, 'HH:mm')
if curTime == setpointTime:
	PR_value = system.tag.read('[default]TESTSTARTSTOP/09:00').value
	tags = ['[default]TESTSTARTSTOP/Active power9']
	values = [PR_value]
	system.tag.writeAll(tags, values)

there is no error, it does not work.
What type of tag do I need to enter the time?

You need to make your memory tag a Date data type. Is that what you have?
Also, what are the settings you’ve configured on the gateway script? i.e. execution rate, etc. got a screenshot?

Thank`s. The script worked.
Is it possible to enter into the memory tag with the data type data not the whole date β€œFri Jun 12 09:08:20 EEST 2020” ?.I need to enter only time HH:mm to memory tag.

You could use a string type and just enter that in. You would need to ensure that it’s entered in the correct format though. You could use the formatted input field with the right format mask expression (e.g. ##:##), if this is something you want to display on the screen for editing.

Then you would just use:

from time import localtime, strftime 
curTime = system.date.format(system.date.now(), 'HH:mm')
setpointTime = system.tag.read("[default]StringTypeMemoryTag").value # assumes value in the format "HH:mm"
if curTime == setpointTime:
	PR_value = system.tag.read('[default]TESTSTARTSTOP/09:00').value
	tags = ['[default]TESTSTARTSTOP/Active power9']
	values = [PR_value]
	system.tag.writeAll(tags, values)

You could do some error checking in the script to check format if you wanted to

Thank you so much!

1 Like

How to control the execution of this script and if the value is not recorded make one more record of this value after 5 minutes?