# Alarm query status write to text file

**URL:** <https://forum.inductiveautomation.com/t/alarm-query-status-write-to-text-file/14765>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [July 12, 2017, 12:55am UTC](https://forum.inductiveautomation.com/t/alarm-query-status-write-to-text-file/14765 "2017-07-12T00:55:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![trentbliss](https://avatars.discourse-cdn.com/v4/letter/t/e19b73/32.png) [@trentbliss](https://forum.inductiveautomation.com/u/trentbliss)\
**Post date:** [July 12, 2017, 12:55am UTC](https://forum.inductiveautomation.com/t/alarm-query-status-write-to-text-file/14765/1 "2017-07-12T00:55:12Z")

</div>

When i run the following i get the output i require from print. Then i am trying ti insert the results into my create file. I can input a property.text value in there and it works fine or just 'string' but when i try to call the results in there it just dosen't do anything.

alarms = system.alarm.queryStatus(state=["ActiveUnacked", "ClearAcked"])

for alarm in alarms:  
print alarm.getName(), alarm.getState()

result

> > >

Dryer 7 Temp low Cleared, Acknowledged  
Dryer 10 Temp High Cleared, Acknowledged  
Dryer 5 Burner Fault Cleared, Acknowledged

when i run this  
alarms = system.alarm.queryStatus(state=["ActiveUnacked", "ClearAcked"])  
for alarm in alarms:  
alarm1 = alarm.getName(), alarm.getState()

my\_file = open('D:\send\_file3.txt','w')  
my\_file.write('from call import Client\n')  
my\_file.write('account\_sid = "test"\n')  
my\_file.write('auth\_token = "test"\n')  
my\_file.write('client = Client(account\_sid, auth\_token)\n')  
my\_file.write('message = client.api.account.messages.create(to="+6140000000", from\_="+614000000000", body=" ')  
my\_file.write(alarm1)  
my\_file.write(' ")')  
my\_file.close()

text file output

it writes all lines to  
body="

then blank. If i change alarm1 to 'hello'

i get body="hello ").

What i want to achieve is  
body="Dryer 7 Temp low Cleared, Acknowledged Dryer 10 Temp High Cleared, Acknowledged Dryer 5 Burner Fault Cleared, Acknowledged"

Any help would be appreciated.

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [July 12, 2017, 12:36pm UTC](https://forum.inductiveautomation.com/t/alarm-query-status-write-to-text-file/14765/2 "2017-07-12T12:36:15Z")

</div>

Make alarm1 a string?

my\_file.write(str(alarm1))

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 12, 2017, 12:43pm UTC](https://forum.inductiveautomation.com/t/alarm-query-status-write-to-text-file/14765/3 "2017-07-12T12:43:40Z")

</div>

It’s hard to follow the code since it’s not formatted (need to use triple-backquotes before and after), but the `for` loop needs to include `my_file.write(str(alarm1))`. As shown, alarm1 only has the last alarm object when written out.

---

<div class="post-metadata">

**Author:** ![trentbliss](https://avatars.discourse-cdn.com/v4/letter/t/e19b73/32.png) [@trentbliss](https://forum.inductiveautomation.com/u/trentbliss)\
**Post date:** [July 16, 2017, 7:27am UTC](https://forum.inductiveautomation.com/t/alarm-query-status-write-to-text-file/14765/4 "2017-07-16T07:27:27Z")

</div>

hi. i ended up doing the following

```
alarms = system.alarm.queryStatus(state=[])
for alarm in alarms:
      msg = '%s %s' % (alarm.getName(), alarm.getState())

```

And gave me the output i required in my write file.  
i didn’t get to try str(alarm1)

---

<div class="post-metadata">

**Author:** ![Sanderd17](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sanderd17/32/8735_2.png) [@Sanderd17](https://forum.inductiveautomation.com/u/Sanderd17)\
**Post date:** [July 16, 2017, 9:12am UTC](https://forum.inductiveautomation.com/t/alarm-query-status-write-to-text-file/14765/5 "2017-07-16T09:12:03Z")

</div>

`'%s' % value` means to format the value as a string. So it’s exactly the same as `str(value)`, but I guess `str(value)` is more readable for a single value, and the `%s` substitutions are better when formatting longer strings (like you formatted the string with the space).
