pimatic-log-reader

Provides predicates for log entries in log files of other programs.

npm install pimatic-log-reader
3 downloads in the last day
34 downloads in the last week
52 downloads in the last month

pimatic log-reader plugin

The log-reader let you define sensors based on log entries in log files of other programs. So you can trigger rules besed on log entries. See the example-Section for more details.

Configutation:

Add the plugin to to plugins-Array in the config.json file:

{ 
  "plugin": "log-reader"
}

Then add a sensor for your log-entries to the devices section:

{
  "id": "some-id",
  "name": "some name",
  "class": "LogWatcher",
  "file": "/var/log/some-logfile",
  "attributes": [
    "someAttr"
  ],
  "lines": [
    {
      "match": "some log entry 1",
      "predicate": "entry 1",
      "someAttr": "1" 
    },
    {
      "match": "some log entry 2",
      "predicate": "entry 2",
      "someAttr": "2"
    }
  ]
}

Then you can use the predicates defined in your config.

Examples:

turn a speacker on and off when a music player starts or stops playing:

Assuming that you are using gmediarender and the log is written to "/var/log/gmediarender". Then define following sensor:

{
  "id": "gmediarender-status",
  "name": "Music Player",
  "class": "LogWatcher",
  "file": "/var/log/gmediarender",
  "attributes": [
    "music-state"
  ],
  "lines": [
    {
      "match": "TransportState: PLAYING",
      "predicate": "music starts",
      "music-state": "playing" 
    },
    {
      "match": "TransportState: STOPPED",
      "predicate": "music stops",
      "music-state": "stopped"
    }
  ]
}

and add the following rules for a existing speaker actuator:

if music starts then turn the speacker on

if music stops then turn the speacker off

turn the printer on when you start printing:

Define the following sensor:

{
  "id": "printer-status",
  "name": "Printer Log",
  "class": "LogWatcher",
  "file": "/var/log/cups/page_log",
  "attributes": [],
  "lines": [
    {
      "match": "psc_1100",
      "predicate": "new print job"
    }
  ]
}

and define the rule:

if new print job then turn printer on

Gather temperature values from a log file:

If the log file looks like this:

temperature: 21.1
temperature: 22.2

You can create a TemperatureSensor for this with:

{
  "id": "temperature-from-logfile",
  "name": "Temperature",
  "class": "LogWatcher",
  "file": "/var/log/temperature",
  "attributes": [
    {
      "name": "temperature",
      "type": "number",
      "unit": "°C"
    }
  ],
  "lines": [
    {
      "match": "temperature: (.+)",
      "temperature": "$1"
    }
  ]
}
npm loves you