Skip to content

Commit

Permalink
Major updates and fixes
Browse files Browse the repository at this point in the history
Added availability topic in HA as V1 devices report state every
4 hours at most, and V2 devices report every 2 hours at most.
Added a state file that gets saved on shutdown and sensor reload.
This file saves the last seen timestamp and online state for each
sensor so that it has consistancy across reboots. Something to add
in the future is the shutdown timestamp, so that if the service is
down for a long time, it can just ignore the previous timestamps
instead of marking everything offline and having to wait for sensors
to individually report one by one to come back online.

Added timeout setting for sensors to configure a timeout per device
if desired. Otherwise it'll default to 4 hours for V2 devices and
8 hours for V1 and unknown devices. This is twice the max status
period to allow for one missed status update.

Also added a global availability topic that is set online when the
service is running. Both the global availability and the per device
availability must be set to online for a device to be available.

Switched mqtt connection method so it connects faster and availability
topics are sent after the connection is active rather than before.
This also allows the main thread to loop and check availability of
the sensors.

The main loop also checks communication with the dongle, by getting
the mac address, which allows us to close and reopen the dongle if
we lose communication with the device. This is an issue I've been
dealing with for a long time.

Fixed shutdown by sending the correct signal in the service file
and properly handling it in shutdown. Wait for dongle loop to finish
before closing the fd.

Updated logging. Set the sample logging conf to INFO instead of DEBUG
and updated log messages to primarily log mqtt messages/events, etc
at this level. Passing in LOGGER to the dongle class so logs from the
dongle show up in the log file.

Fix packet parsing to not throw away partial packets which can be
parsed correctly when the rest of the message is received.

Fix new device scan to add the device even if the additional calls
timeout, as long as we got a result from the scan.

Fix automatic device adding for already linked devices to default
the class to opening instead of None. This means even motion sensors
will be initially added as a contact sensor, but should get fixed when
the sensors.yaml configuration is updated.

Signed-off-by: Nathan Bahr <nabahr@users.noreply.github.com>
  • Loading branch information
nabahr committed Nov 18, 2022
1 parent 0df4056 commit ea99cba
Show file tree
Hide file tree
Showing 5 changed files with 404 additions and 214 deletions.
11 changes: 9 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ sudo systemctl start wyzesense2mqtt
sudo systemctl status wyzesense2mqtt
sudo systemctl enable wyzesense2mqtt # Enable start on reboot
```
9. Pair sensors following [instructions below](#pairing-a-sensor). You do NOT need to re-pair sensors that were already paired, they should be found automatically on start and added to the config file with default values, but the sensor version will be unknown.
9. Pair sensors following [instructions below](#pairing-a-sensor). You do NOT need to re-pair sensors that were already paired, they should be found automatically on start and added to the config file with default values, but the sensor version will be unknown and the
class will default to opening, I.E. a contact sensor.


## Config Files
Expand Down Expand Up @@ -179,16 +180,22 @@ root:
```
### sensors.yaml
This file will store basic information about each sensor paired to the Wyse Sense Bridge. The entries can be modified to set the class type and sensor name as it will show in Home Assistant. Class types can be automatically filled for `opening`, `motion`, and `moisture`, depending on the type of sensor. Since this file can be automatically generated, Python may automatically quote the MACs or not depending on if they are fully numeric.
This file will store basic information about each sensor paired to the Wyse Sense Bridge. The entries can be modified to set the class type and sensor name as it will show in Home Assistant. Class types can be automatically filled for `opening`, `motion`, and `moisture`,
depending on the type of sensor. Since this file can be automatically generated, Python may automatically quote the MACs or not depending on if they are fully numeric. Sensors that were previously linked and automatically added will default to class `opening` and will not
have a "sw_version" set. For the original version 1 devices, the sw_version should be 19. For the newer version 2 devices, the sw_version should be 23. This will be automatically have the correct settings for devices added via a scan. A custom timeout for device
availability can also be added per device by setting the "timeout" setting, in seconds. For version 1 devices, the default timeout is 8 hours and for version 2 device, the default timeout is 4 hours.
```yaml
'AAAAAAAA':
class: door
name: Entry Door
invert_state: false
sw_version: 19
'BBBBBBBB':
class: window
name: Office Window
invert_state: false
sw_version: 23
timeout: 7200
'CCCCCCCC':
class: opening
name: Kitchen Fridge
Expand Down
4 changes: 2 additions & 2 deletions wyzesense2mqtt/samples/logging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ handlers:
console:
class: logging.StreamHandler
formatter: simple
level: DEBUG
level: INFO
file:
backupCount: 7
class: logging.handlers.TimedRotatingFileHandler
Expand All @@ -22,4 +22,4 @@ root:
handlers:
- file
- console
level: DEBUG
level: INFO
Loading

0 comments on commit ea99cba

Please sign in to comment.