# Logging Boolean Tag

**URL:** <https://forum.inductiveautomation.com/t/logging-boolean-tag/93866>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [July 29, 2024, 7:59pm UTC](https://forum.inductiveautomation.com/t/logging-boolean-tag/93866 "2024-07-29T19:59:41Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![thomas\_wallace](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@thomas\_wallace](https://forum.inductiveautomation.com/u/thomas_wallace)\
**Post date:** [July 29, 2024, 7:59pm UTC](https://forum.inductiveautomation.com/t/logging-boolean-tag/93866/1 "2024-07-29T19:59:41Z")

</div>

Has anyone ever setup a way to log how long a boolean is true for a set time. Then reset the counter at a specific time.  
Example. Count for how long a boolean tag is true for 24hrs,log that data, reset at midnight, and repeat everyday. So one data point everyday.

I tried making a transaction group, then a querie that gets the data, then a timeseries chart that plots the data from the querie. I cant get the data to reset to 0 everyday though.

---

<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 29, 2024, 8:14pm UTC](https://forum.inductiveautomation.com/t/logging-boolean-tag/93866/2 "2024-07-29T20:14:04Z")

</div>

That is normally done in your PLC, using a retentive timer. The difference between a PLC's scan time and SCADA's poll time will make a difference in many applications.

The general recommendation in Ignition is to record every transition's timestamp in your database. Then it is relatively simply to query the database for the intervals, substituting start and end of day timestamps for any "on" intervals that cross those boundaries.

Some reading:

[https://forum.inductiveautomation.com/search?q=duration%20calculations%20lead%20order%3Alatest](https://forum.inductiveautomation.com/search?q=duration%20calculations%20lead%20order%3Alatest)

---

<div class="post-metadata">

**Author:** ![thomas\_wallace](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@thomas\_wallace](https://forum.inductiveautomation.com/u/thomas_wallace)\
**Post date:** [July 29, 2024, 10:01pm UTC](https://forum.inductiveautomation.com/t/logging-boolean-tag/93866/3 "2024-07-29T22:01:38Z")

</div>

@pturmel So if i make a retentive timer in the PLC i can use that tag in an ignition querie instead of getting the data from my transaction group.

It just seems like its so close to working with a transaction group. Just if the counters in it would reset back to zero at a certain time.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/e/ae2fca203abe68dc8b83da1bdac6698eb7cac53d.png)

---

<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 29, 2024, 10:09pm UTC](https://forum.inductiveautomation.com/t/logging-boolean-tag/93866/4 "2024-07-29T22:09:56Z")

</div>

No, with a retentive timer, you would write PLC logic to move the final time value into a separate tag at the end of the day, followed by the zeroing operation (in one scan in the PLC). At some short time after that (using schedule for the transaction group), you would record the separate tag to your database, using the boundary as the timestamp.

If you don't want to use a timer in the PLC, and you only have a boolean tag brought to Ignition, you should record every transition to the database. (Triggering the transaction group on change of the boolean, or using a simple tag change event script.) This latter will need followup computations with your DB's `lead()` function to assemble the durations per day.

Another option would be to use a retentive timer in the PLC that **never resets**. (You'd have it roll over like an odometer instead.) In Ignition, you'd record its value at the top of every hour, or every five minutes, or some other desired granularity. Then you can easily compute deltas from row to row at any recording granularity.

More reading:

> [@Historicizing running time](https://forum.inductiveautomation.com/t/historicizing-running-time/75853/2):
>
> The least DB storage is to simply record the value every time it changes. You can use a database's lead() or lag() window functions to convert these to durations, trim them to desired time periods, and handle duplicate records (such as those triggered by system restarts). This method does require a reliable connection to the PLC, and ensuring that Ignition runs any time the machine is running. (If you use Ignition's historian to capture these events, you will need to post-process queried hist…

---

<div class="post-metadata">

**Author:** ![thomas\_wallace](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@thomas\_wallace](https://forum.inductiveautomation.com/u/thomas_wallace)\
**Post date:** [July 29, 2024, 10:15pm UTC](https://forum.inductiveautomation.com/t/logging-boolean-tag/93866/5 "2024-07-29T22:15:28Z")

</div>

@pturmel Ok. I'll have to go the retentive timer route. Unfortunately I have very little knowledge when it comes to scripting. (which I'm finding is a huge hinderance with ignition)

---

<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 29, 2024, 10:17pm UTC](https://forum.inductiveautomation.com/t/logging-boolean-tag/93866/6 "2024-07-29T22:17:07Z")

</div>

> [@thomas\_wallace](#):
>
> very little knowledge when it comes to scripting

We can help with that. 😆

> [@thomas\_wallace](#):
>
> a huge hinderance with ignition

It is, even though, for performance, other features (expression bindings, especially) should be used before scripting in most cases.

---

<div class="post-metadata">

**Author:** ![thomas\_wallace](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@thomas\_wallace](https://forum.inductiveautomation.com/u/thomas_wallace)\
**Post date:** [July 29, 2024, 10:18pm UTC](https://forum.inductiveautomation.com/t/logging-boolean-tag/93866/7 "2024-07-29T22:18:27Z")

</div>

@pturmel Part of me wants to figure this out with ignition. Since ive already got so much time invested with it. If you or someone else is willingI'd love to learn how.

---

<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 29, 2024, 10:20pm UTC](https://forum.inductiveautomation.com/t/logging-boolean-tag/93866/8 "2024-07-29T22:20:17Z")

</div>

Start by setting up a transaction group that will record your boolean every time it changes (triggered). Let it collect data for a day. We can exercise the results of that tomorrow. (I'm headed for the house now.)

---

<div class="post-metadata">

**Author:** ![thomas\_wallace](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@thomas\_wallace](https://forum.inductiveautomation.com/u/thomas_wallace)\
**Post date:** [July 29, 2024, 10:21pm UTC](https://forum.inductiveautomation.com/t/logging-boolean-tag/93866/9 "2024-07-29T22:21:04Z")

</div>

@pturmel I have it already. Several days of data. Sounds good though. Thanks!

---

<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 29, 2024, 10:22pm UTC](https://forum.inductiveautomation.com/t/logging-boolean-tag/93866/10 "2024-07-29T22:22:19Z")

</div>

If you don't want to wait for me, I'm sure others will pitch in.

---

<div class="post-metadata">

**Author:** ![thomas\_wallace](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@thomas\_wallace](https://forum.inductiveautomation.com/u/thomas_wallace)\
**Post date:** [July 30, 2024, 5:36pm UTC](https://forum.inductiveautomation.com/t/logging-boolean-tag/93866/11 "2024-07-30T17:36:02Z")

</div>

@pturmel You have some spare time to start this?

---

<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 30, 2024, 6:18pm UTC](https://forum.inductiveautomation.com/t/logging-boolean-tag/93866/12 "2024-07-30T18:18:37Z")

</div>

Yes, this is a good time. Let's start by getting yesterday's data. Create a named query with SQL like so:

```python
SELECT *
FROM "my_table"
WHERE "t_stamp" >= :startts AND "t_stamp" < :endts

```

(Use your actual table name from your transaction group in place of `my_table`.)

Configure `startts` and `endts` as **Value** parameters with Data Type **DateTime**.

In a Perspective testing view, create a table that fills the view. Make view custom properties for `start` and `end`. Use the following expression binding on `view.custom.end`:

```python
setTime(now(0), 7, 0, 0)

```

(Replace the `7` with your start hour of day shift.)

Use the following expression binding on `view.custom.start`:

```python
addDays({view.custom.end}, -1)

```

Now your view will initialize itself to have start and end timestamps covering yesterday, startof first shift, through today, start of first shift.

On the table, on `props.data`, bind the testing named query, using the view custom properties to supply the parameters. Choose **Dataset** return format.

You table should now be filled with all of the transitions you recorded yesterday.

Click on the dataset editor icon next to the `[RxC]` indicator beside `props.data`. Use the copy to clipboard button to capture the dataset's CSV. Reply here, pasting that CSV, then selecting it all and clicking the "preformatted text" button. That will preserve the format of the CSV here on the forum.

---

<div class="post-metadata">

**Author:** ![thomas\_wallace](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@thomas\_wallace](https://forum.inductiveautomation.com/u/thomas_wallace)\
**Post date:** [July 30, 2024, 7:27pm UTC](https://forum.inductiveautomation.com/t/logging-boolean-tag/93866/13 "2024-07-30T19:27:59Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/0/409b49b962b46457cc9f1c6c7dd04c8fae674242.png)

so far so good?

---

<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 30, 2024, 7:31pm UTC](https://forum.inductiveautomation.com/t/logging-boolean-tag/93866/14 "2024-07-30T19:31:01Z")

</div>

- Your parameter names and data types need fixing.

- Use \>= with start, \< with end.

- I recommend you use `startts` and `endts` or similar as your parameter names--they aren't dates, but datetime (aka timestamp) objects.

- Use `Select *` so we can get the true column layout of your table. (Explicit column names are good for production code, but this is just testing.)

---

<div class="post-metadata">

**Author:** ![thomas\_wallace](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@thomas\_wallace](https://forum.inductiveautomation.com/u/thomas_wallace)\
**Post date:** [July 30, 2024, 7:36pm UTC](https://forum.inductiveautomation.com/t/logging-boolean-tag/93866/15 "2024-07-30T19:36:17Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/1/91dd65f3898bdda86c2dc8ee74f2768f6da651ca.png)

Im not sure what you mean on the 4th bulletin with select\*

---

<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 30, 2024, 7:40pm UTC](https://forum.inductiveautomation.com/t/logging-boolean-tag/93866/16 "2024-07-30T19:40:42Z")

</div>

In line1 of your query you have spelled out your column names. Using `*` simply returns all columns in the table. I want to see that.

I suspect part of your difficulties may be due to your use of multiple columns--if those are different machines, then triggered inserts won't be efficient. Multiple columns is ideal when you use odometer-style retentive timers, with inserts that are _scheduled_, not _triggered_.

---

<div class="post-metadata">

**Author:** ![thomas\_wallace](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@thomas\_wallace](https://forum.inductiveautomation.com/u/thomas_wallace)\
**Post date:** [July 30, 2024, 7:45pm UTC](https://forum.inductiveautomation.com/t/logging-boolean-tag/93866/17 "2024-07-30T19:45:06Z")

</div>

Ok. Yes each one is a different machine.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/9/994ac458a66e8a7641627b8156da3f78ba20660c.png)

---

<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 30, 2024, 7:48pm UTC](https://forum.inductiveautomation.com/t/logging-boolean-tag/93866/18 "2024-07-30T19:48:23Z")

</div>

Missing a colon with `startts` in your query.

It's getting quite close to what you'd have if you'd copy-n-pasted my recommended SQL and replaced the table name. 🤷‍♂️

---

<div class="post-metadata">

**Author:** ![thomas\_wallace](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@thomas\_wallace](https://forum.inductiveautomation.com/u/thomas_wallace)\
**Post date:** [July 30, 2024, 7:52pm UTC](https://forum.inductiveautomation.com/t/logging-boolean-tag/93866/19 "2024-07-30T19:52:00Z")

</div>

Didnt know I could do that lol....I just did it changed the name

---

<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 30, 2024, 7:54pm UTC](https://forum.inductiveautomation.com/t/logging-boolean-tag/93866/20 "2024-07-30T19:54:15Z")

</div>

> [@thomas\_wallace](#):
>
> each one is a different machine.

If these are booleans, you need a transaction group for each machine, that records t\_stamp and boolean value when **triggered** by **any change** of the boolean. You can use a single table if you include a third column, "machine number" or "machine ID", and include the right value as a constant in each transaction group.

If the values from the machines are retentive timer that roll over like odometers, then you can use one transaction group that records the timer values at the top of every hour. **Scheduled**.

Decide.

[Next page](https://forum.inductiveautomation.com/t/logging-boolean-tag/93866.md?page=2)
