Hour Meter by month

Is it possible to use the hour meter and have it save the data by totals per month? How?

I have a tag in the PLC that will indicate when the machine is running.


Hour meters can update a single row of a database table. If you want the hour meter to accumulate for a given month you just need to have a new record get inserted into the table monthly. If you set the item mode of the hour meter to bi-directional db wins the hour meter will get reset for the new month. So maybe you just have two groups, one that inserts a new record each month and one that updates the last record with the hour meter.

Another idea would be to use the hour meter for a much smaller timeframe (say, logging the minutes of counted uptime every hour), and use SQL querying to turn that hourly data into monthly data.

The GROUP BY clause and the SUM function would make quick work of it.


Here is what I did and not working as I expected.

Made a table with a “On” and “Off” date time field.

Made a transaction group (Run Time On) to watch the tag in the PLC. When it goes to a “1” it Stores timestamp to the “On” field. Works!

Made another transaction group (Run Time Off) to watch for it to flip back to a “0” then write time stamp to “Off”. Not working

In the Table action I selected update/select I placed this :

"UPDATE tbl_DC71101_rt SET tbl_DC71101_rt.Off = CURRENT_TIMESTAMP WHERE tbl_DC71101_rt.Off is NULL"

It is not writing it in there :scratch:

I thought once I had this I could do a Date or Time Difference and be able to filter and sum by date.

Is this the hard or wrong way?

Forgot to mention if I place the code in the “Database Query Browser” and execute it it works fine.

You put that query in the “where clause” of a group? That definitely wouldn’t work. Instead, you’d need it to be in an Expression item, set to run on trigger, in a group triggered off your bit. The actually group wouldn’t be writing to the table (the expression item would be doing that), so it would be set to update the first row of a “dummy” table.


Here is what I did, please let me know of any problems you may foresee in this. It is working.

Table has 4 fields:

Made 2 transaction groups:
Run Time On
Run Time Off
(Only evaluate when values have changed must be unchecked on both)

In the On group I watch for tag to go to “1” , the write target is set to Read-Only.
Store the timestamp to “OnDate” field

The Off group watches the same trigger to go back to “0”
It is set to write to the database field “Trigger” (With out this it don’t work)
Store timestamp in “OffDate” field.
Table action is set to update last.

Yes, that should be fine. I think what you noticed is that group won’t write the “group timestamp” if nothing else in the group is being written.

If necessary you can have the trigger item in both groups write to the trigger column in the table, doesn’t matter since you’re not using it.