Skip to content

Commit

Permalink
Add option to adjust off_delay
Browse files Browse the repository at this point in the history
  • Loading branch information
matijse committed Apr 20, 2021
1 parent 0eb850e commit 1de5b33
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 15 deletions.
6 changes: 5 additions & 1 deletion config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ const winston = require('winston')
class Config {
eufyUsername
eufyPassword

mqttUrl
mqttUsername
mqttPassword
mqttKeepalive

haOffDelay

constructor () {
let config
try {
Expand All @@ -26,9 +29,10 @@ class Config {
this.mqttUrl = get(config, 'mqtt.url')
this.mqttUsername = get(config, 'mqtt.username')
this.mqttPassword = get(config, 'mqtt.password')

this.mqttKeepalive = parseInt(get(config, 'mqtt.keepalive', { default: 60 }))

this.haOffDelay = parseInt(get(config, 'home_assistant.off_delay', { default: 5 }))

if (
typeof this.eufyUsername === "undefined" ||
typeof this.eufyPassword === "undefined" ||
Expand Down
4 changes: 3 additions & 1 deletion data/config.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ mqtt:
url: "mqtt://dockerhost:1883"
username: "user"
password: "password"
keepalive: 60
keepalive: 60
home_assistant:
off_delay: 5
3 changes: 2 additions & 1 deletion mqtt/ha-discovery.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { NotificationType } = require('../enums/notification_type');
const { SensorType } = require('../enums/sensor_type');
const { DeviceCapabilities } = require('../enums/device_type')
const config = require('../config')

class HaDiscovery {

Expand Down Expand Up @@ -177,7 +178,7 @@ class HaDiscovery {
state_topic: `${sensorBaseTopic}/state`,
json_attributes_topic: `${sensorBaseTopic}/attributes`,
payload_on: sensorPayloadOn,
off_delay: 5,
off_delay: config.haOffDelay,
unique_id: sensorId,
device: {
identifiers: deviceSN,
Expand Down
39 changes: 27 additions & 12 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,10 @@ help with adding support for new devices or message types that aren't supported

## Setup

### Docker configuration
### Configuration

The data folder contains the config, logs and a record of all push notifications (so new types of notifications can
be discovered). Mount this directory to a local folder. Replace `/path/to/local/data/folder`
below with the location where you want to store this data.

If you run your MQTT broker on the same host as this Docker image, it cannot simply connect to `localhost` from inside
this Docker image. In that case, add a line to add the correct IP for the Docker network inside the image as
`dockerhost`. You can then use `mqtt://dockerhost:1883` as the MQTT url. Otherwise, you can remove that line from the
example below.

In the data directory, you will need to create a `config.yml` file with your credentials. It should contain the
following contents:
In the data directory, you will need to create a `config.yml` file with your credentials. You can copy this from
`config.example.yml`. It should contain the following contents:

```yaml
eufy:
Expand All @@ -71,8 +62,32 @@ mqtt:
url: "mqtt://dockerhost:1883"
username: "user"
password: "password"
keepalive: 60
home_assistant:
off_delay: 5
```
Only the Eufy username and password and MQTT url are required. Also MQTT username and password when set at the broker.
The other options can be omitted, with the defaults shown above.
* MQTT keepalive: adjusts the keepalive interval for the MQTT connection. This is the maximum interval in seconds
between messages to/from the MQTT broker. Set this higher when you encounter disconnects.
* Home Assistant `off_delay`: Sets the delay in seconds after which a motion/doorbell sensor is set back to "No motion"
after motion is detected.

### Data folder

The data folder contains the config, logs and a record of all push notifications (so new types of notifications can
be discovered). Mount this directory to a local folder. Replace `/path/to/local/data/folder` in the Docker setups
below with the location where you want to store this data.

### Connecting to MQTT

If you run your MQTT broker on the same host as this Docker image, it cannot simply connect to `localhost` from inside
this Docker image. In that case, add a line to add the correct IP for the Docker network inside the image as
`dockerhost`. You can then use `mqtt://dockerhost:1883` as the MQTT url. Otherwise, you can remove that line from the
example below.

### Run via Docker

Run the container, with a volume mapping to the local data directory, for example:
Expand Down

0 comments on commit 1de5b33

Please sign in to comment.