Fork me on GitHub

pimatic-netcheck by Peter Müller (crycode) | github | npm

pimatic-netcheck

build status npm version

pimatic-netcheck is a pimatic plugin that allows you to check if some network or bluetooth devices are present.

The main goal of this plugin is to send specific messages (using other plugins like pimatic-telegram) or do some actions if a contact sensor is opened and nobody is at home (no smartphones are at home).

You can trigger a NetCheck by a rule and execute other rules as a result of this check. Example: When contact-sensor-door is opened then check netcheck-1 if absent exec rule send-alarm-message

Additionally a check can be triggert automatically using an interval.

Device configuration localized in:

  • en - English
  • de - German

Supported checks

There are two supported check methods:

  1. Check one or more network devices using the IPv4 addresses or hostnames.
  2. Check one or more bluetooth devicees using the MAC addresses. To use this you must pair your bluetooth device with your Raspberry Pi running pimatic. (see below)

NetCheckDevice

You have to create at least one NetCheckDevice, which will act as a PresenceSensor (present = NetCheck successfull, absent = NetCheck not successfull).

To this device you may add some IP addresses/hostnames and/or bluetooth MAC addresses. These are the external devices (e.g. smartphones) which will be checked.

Using the needAll option, you can define if all listed devices must be peresent or only one.

You may also set a check interval to do a scheduled automatic check.

NetCheckDevice

Rules

Syntax

When <some condition> then check <NetCheckDevice> [if present exec rule <RuleID>] [if absent exec rule <RuleID>]

Example

If a ContactSensor is opened, then do a NetCheck and only if the NetCheck failed send a message using telegram.

First create a new rule containing the action to send the message. Here you should use a When condition which is never fulfilled, e.g. 1 is 0:

When 1 is 0 then send text telegram to "test"

Rule 1

Then create a second rule to run the NetCheck and if needed trigger the first rule:

When contact-sensor-1 is opened then check netcheck-test if absent exec rule tg-send-test

Rule 2

This will run the NetCheck of the device netcheck-test and if this check reported absent (the check failed) the action of the first rule tg-send-test is executed.

You may also add a rule which gets executed if the check reported present.

Bluetooth requirements

Hardware

You need a Raspberry Pi with integrated bluetooth (e.g. 3B) or an additional bluetooth dongle.

Software

If your hardware is ready you need to install the bluetooth package from command line:

sudo apt-get install bluetooth

Bluetooth paring

To use the bluetooth netcheck you must pair your bluetooth device with your Raspberry Pi running pimatic.

This can be done using the commant line as follows:

  1. Set your bluetooth device to "visible".
  2. Run hcitool scan from your command line to get the MAC address (e.g. BA:BE:13:37:BE:EF).
  3. Pair the devices by running sudo hcitool cc <MAC>; sudo hcitool auth <MAC> from your command line. Make shure to replace <MAC> with your MAC address from step 2.
  4. Set your bluetooth device back to "invisible".
  5. Check the pairing by running sudo hcitool info <MAC> from your command line. This should print some information about your device.

If the pairing was successfull you can add the MAC address to a NetCheckDevice in pimatic.

License

Licensed under GPL Version 2

Copyright (c) 2017 Peter Müller peter@crycode.de (https://crycode.de/)

Plugin Config Options

NetCheck config options
OptionDescriptionDefault
debug
boolean
Enable debug output
false

Device Config Options

NetCheck device config schemes

NetCheckDevice

NetCheckDevice config options
OptionDescriptionDefault
networkIpAddresses
array of strings
Array of IP addresses of network devices which will be checked.
bluetoothMacAddresses
array of strings
Array of MAC addresses of bluetooth devices which will be checked. Leave blank if you have no bluetooth.
needAll
boolean
Do we need all devices to be present to succeed?
true
checkInterval
number
Interval in milliseconds for a scheduled automatic check. Use default or 0 to disable automatic checking.
0
bluetoothDevice
string
The used hardware device for the bluetooth checks.
"hci0"
bluetoothUseSudo
boolean
Use 'sudo' for bluetooth checking? Needed if pimatic isn't started as root.
false
pingTimeout
number
Timeout in seconds for a ping.
2
pimatic-netcheck is written by Peter Müller (crycode)