Does anybody by chance know how I could reset a tag’s value to a coded default value day after day?
Also I want to see how much energy I’ve been using dialy, from a totalizer energy RTU
Greetings
Does anybody by chance know how I could reset a tag’s value to a coded default value day after day?
Also I want to see how much energy I’ve been using dialy, from a totalizer energy RTU
Greetings
Assuming you want this to happen at midnight, you could create an expression tag dayOfMonth
with this expression:
getDayOfMonth(now())
Then create a project gateway tag change script that runs when dayOfMonth
changes and writes the default value to the tag you want to reset daily.
Change the trigger tag expression and script conditions as needed if you want the reset to happen at some other time of day.
witman, I did accurately the things you write, but there isn’t a new assignment
in the gateway script I put when the tag value has changed,
E_dia=0
but although was compiled, there’s no variable assignment. please help.
Post your tag change script
That script assigns the value zero to the script local variable E_dia
. Which then ceases to exist at the end of the script.
You must use system.tag.write() to assign a value to a persistent tag.
I continue with this issue. The gateway doesn’t trigger anymore, although I have enabled the tag change
then I go to Tag browser and E_acum did’t change anymore
the script is with no errors (i probe in the script console) and the trigger tag is changing each second. Also the tag path is correct.
what’s the problem then??
Check on your gateway web page under Status->Gateway Scripts–>Tag Change:
You can also add your own logs there by adding code like this to your script:
# Get logger with name 'GatewayEventScripts.TagChange' (you can name it nearly anything you want).
logger = system.util.getLogger('GatewayEventScripts.TagChange')
# Log your message. You can include variables in log too.
logger.info('your log message with calc value: %i' %(calcValue))
system.tag.write("tagpath", value)
needs to have a qualified tag path when you’re running on the gateway - meaning, system.tag.write("[default]tagpath", value)
almost certainly.
No way guys, in the script the tag change value, there’s no error,
Even If I only put print(“a”), the variable doesn’t appear in the console. Sounds that the trigger doesn’t run.
and 10_segundos is setted
dateFormat(now(), "ss")/10
an integer that changes every 10 seconds.
The script runs fine in the script console because it’s not running on the gateway, meaning it doesn’t need to have a tag provider specified. Qualify the tag path, and the script should work.
That’s a gateway tag change script in a project – tag provider is implied.
So? guys, if I only put print(“a”) the ouput console is not printing. My opinion is that the trigger is not running.
A gateway script won’t print to a designer/client output console. It will go to the gateway logs I believe(don’t quote me on this part).
What does the page witman mentioned above say? Is it showing that it executed?
Yes, it is showing that, but version 7.8 only says that is executed but doesn’t show a response (this time the script is called “Energia_dia”)
then I go again to te referred tags and… no changes. I also called the tag in the last post
system.tag.write("[default]E_dia",0)
does anybody knows what’s the hell going on?
It's never going to print to your designer's console. It's a gateway script. Any print operation is only going to show up in your gateway's wrapper log. A logger operation will show in the gateway web interface logs.
I thought v7.8 showed any script errors below on that page too, but maybe that came in v7.9.
Is your tag set read only?
Add the logger code in my post above to your script to get something showing in your gateway logs. Once something is showing, modify it as desired to give you useful debugging information.
Are you sure your tag provider is "default"? Or have you changed it to something else? Check here: http://YourIgnitionServerAddress:8088/main/web/config/tags.realtime?3. You should see something like this and you'll need to use the same name as shown (example below is not the default name--if you're running one project on multiple servers, you don't want to use default):
Thanks pturnel, witman an all !
I’ve tried other manner: add a Timer Script that run each minute with this code:
import datetime
now = datetime.datetime.now()
if now.day != system.tag.read("[default]Last_day").value:
system.tag.write("[default]Last_day", now.day)
system.tag.write("[default]E_dia", int(0))
system.tag.write("[default]E_ant_dia","[default]E_acum")
It runs at the gateway. the right tag name have to be qualified, in my case [default].
7.8 version haven’t a console response, but I test the script by tag changes.
Regards to all
You can make things a little more efficient by using system.tag.writeAll anytime you’re writing more than one tag. If you want the value of E_acum written to E_ant_dia, you’ll need to read it too (ignore this if you want the value of E_ant_dia to be the string “[default]E_acum”). Script below reads E_acum value to later write it to E_ant_dia and uses single calls to read and write multiple tags at once for better efficiency:
import datetime
# Get current date.
now = datetime.datetime.now()
# Read last day and e acum.
readTags = ['[default]%s' %s for s in ['Last_day', 'E_acum']]
lastDay, eAcum = [x.value for x in system.tag.readAll(readTags)]
# If it's a new day, write new values to tags.
if now.day != lastDay:
writeTags = ['[default]%s' %s for s in ['Last_day', 'E_dia', 'E_ant_dia']]
writeValues = [now.day, int(0), eAcum]
system.tag.writeAll(writeTags, writeValues)