Lock Code Manager Logs

I've tried searching out this topic but didn't come across anyone addressing the log issue with LCM. Is there a way to have the log also capture the time and date that specific codes/users entered? I've selected the highest level of logging in the app but it doesn't show dates and times of when each user specifically accessed each lock. Is this possible with the current app or a future feature request?

I can see when a person has unlocked any lock in my logs easily:

[dev:118] 2019-03-20 10:31:51.200 am [info] Back Door Lock was locked by digital command

[dev:118] 2019-03-20 10:31:49.889 am [info] Back Door Lock was locked by manual

[dev:118] 2019-03-20 10:31:48.264 am [info] Back Door Lock was unlocked by manual

[dev:118] 2019-03-20 10:31:36.973 am [info] Back Door Lock was locked by keypad

[dev:118] 2019-03-20 10:31:32.870 am [info] Back Door Lock was unlocked by manual

[dev:118] 2019-03-20 10:18:01.359 am [info] Back Door Lock was locked by digital command

[dev:118] 2019-03-20 10:17:59.829 am [info] Back Door Lock was locked by manual

[dev:118] 2019-03-20 10:17:57.938 am [info] Back Door Lock was unlocked by Bill

[dev:118] 2019-03-20 10:17:51.712 am [info] Back Door Lock was locked by keypad

[dev:118] 2019-03-20 10:17:45.701 am [info] Back Door Lock was unlocked by manual

[dev:118] 2019-03-20 10:16:13.510 am [info] Back Door Lock was locked by digital command

[dev:118] 2019-03-20 10:16:12.130 am [info] Back Door Lock was locked

[dev:118] 2019-03-20 10:16:10.087 am [info] Back Door Lock was unlocked by Bill

[dev:118] 2019-03-20 10:16:03.758 am [info] Back Door Lock was locked by keypad

[dev:118] 2019-03-20 10:15:57.542 am [info] Back Door Lock was unlocked by manual

[dev:118] 2019-03-20 10:14:37.265 am [info] Back Door Lock was locked by digital command

[dev:118] 2019-03-20 10:14:34.791 am [info] Back Door Lock was locked

[dev:118] 2019-03-20 10:14:32.160 am [info] Back Door Lock was unlocked by master code

[dev:118] 2019-03-20 10:14:26.616 am [info] Back Door Lock was locked by keypad

[dev:118] 2019-03-20 10:14:20.988 am [info] Back Door Lock was unlocked by manual

1 Like

It's not in there right now. You can us RM to send notifications to IFTTT for each user, then have IFTTT put that into a google spread sheet.

The only problem with this is if your internet is down, nothing gets sent to IFTTT. :frowning:

1 Like

Thanks, I understand I can retrieve them through the system logs up to a point, but if I need to go back a week or two than the information will have rolled over.

Thems are the brakes. You need internet for notifications, otherwise you're only dealing with text messages :face_vomiting:

1 Like

Use something like nodejs to pull logs using the log socket and archive them. :slight_smile: Then you can search as far back as you need to (or for however long you were archiving your logs for).

I wrote a long post on how to use NodeRed (which is really just nodejs with a fancy frontend) to pull logs and events from HE and archive them in both flat files and/or a database.

1 Like

That is true... sigh Damn you internet!!! LOL

2 Likes

This. Or some local database. Probably not that hard to do with the Maker API

Hmmmm maybe I'll look into Maker API, I really don't want to make it a very complicated process. I was hoping the log tool in LCM would accomplish this on its own.

Maker API is inbound only. You can only query for devices or pass device commands. The event history only seems to go back for 20 events and isn't configurable.

Here's a nodejs script that will listen for all events and write them out to a flat file. Not overly complicated at all.

Wherever you have nodejs installed, just create a script called 'logs.js' and run the following commands:

npm init
npm install websocket

Then, edit logs.js, and add the following code:

const WebSocket = require('ws');
const fs = require('fs');

const ws = new WebSocket('ws://[your_hubitat_ip]/eventsocket');

ws.on('message', function incoming(data) {
    var outData = {
            timestamp: new Date().toString(),
            evt: JSON.parse(data)
    };

    fs.appendFile('he-logs.json', outData, function (err) {
        if (err) throw err;
        
        //Only here for debugging purposes
        console.log('Saved!');
    });
});

Then run node logs.js and this is the output:

{ timestamp: 'Wed Mar 20 2019 11:47:50 GMT-0400 (EDT)',
evt:
{ source: 'DEVICE',
name: 'switch',
displayName: 'Office Desk Light 1',
value: 'on',
unit: null,
deviceId: 423,
hubId: null,
locationId: null,
installedAppId: null,
descriptionText: 'Office Desk Light 1 was turned on' } }
Saved!
{ timestamp: 'Wed Mar 20 2019 11:47:50 GMT-0400 (EDT)',
evt:
{ source: 'DEVICE',
name: 'switch',
displayName: 'Office Desk Light 1',
value: 'off',
unit: null,
deviceId: 423,
hubId: null,
locationId: null,
installedAppId: null,
descriptionText: 'Office Desk Light 1 was turned off' } }
Saved!
{ timestamp: 'Wed Mar 20 2019 11:47:52 GMT-0400 (EDT)',
evt:
{ source: 'DEVICE',
name: 'switch',
displayName: 'Office Desk Light 1',
value: 'on',
unit: null,
deviceId: 423,
hubId: null,
locationId: null,
installedAppId: null,
descriptionText: 'Office Desk Light 1 was turned on' } }
Saved!
{ timestamp: 'Wed Mar 20 2019 11:47:52 GMT-0400 (EDT)',
evt:
{ source: 'DEVICE',
name: 'switch',
displayName: 'Office Desk Light 1',
value: 'off',
unit: null,
deviceId: 423,
hubId: null,
locationId: null,
installedAppId: null,
descriptionText: 'Office Desk Light 1 was turned off' } }

1 Like

Could you use Rule Machine to post to influxdb?

Not without some sort of custom driver in place for InfluxDB.

I appreciate everyone's suggestions. Just seems like this is something that should be a part of the LCM logs. It already give you the option of several different levels of logging. Can we add this to the highest level and make it simple for everyone to take advantage of? I glanced at NodeRed and oh lord....no thanks! lol not for me.

That's why I did the nodejs script as an alternative. :smiley: Quick and easy.