Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sensor Status Updates #50

Merged
merged 4 commits into from
Nov 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions wyzesense2mqtt/wyzesense.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,10 @@ def __init__(self, mac, timestamp, event_type, event_data):

def __str__(self):
s = "[%s][%s]" % (self.Timestamp.strftime("%Y-%m-%d %H:%M:%S"), self.MAC)
if self.Type == 'state':
s += "StateEvent: sensor_type=%s, state=%s, battery=%d, signal=%d" % self.Data
if self.Type == 'alarm':
s += "AlarmEvent: sensor_type=%s, state=%s, battery=%d, signal=%d" % self.Data
elif self.Type == 'status':
s += "StatusEvent: sensor_type=%s, state=%s, battery=%d, signal=%d" % self.Data
else:
s += "RawEvent: type=%s, data=%s" % (self.Type, bytes_to_hex(self.Data))
return s
Expand All @@ -258,7 +260,7 @@ def _OnSensorAlarm(self, pkt):
timestamp = datetime.datetime.fromtimestamp(timestamp / 1000.0)
sensor_mac = sensor_mac.decode('ascii')
alarm_data = pkt.Payload[17:]
if event_type == 0xA2:
if event_type == 0xA2 or event_type == 0xA1:
if alarm_data[0] == 0x01:
sensor_type = "switch"
sensor_state = "open" if alarm_data[5] == 1 else "close"
Expand All @@ -271,7 +273,7 @@ def _OnSensorAlarm(self, pkt):
else:
sensor_type = "unknown"
sensor_state = "unknown"
e = SensorEvent(sensor_mac, timestamp, "state", (sensor_type, sensor_state, alarm_data[2], alarm_data[8]))
e = SensorEvent(sensor_mac, timestamp, ("alarm" if event_type == 0xA2 else "status"), (sensor_type, sensor_state, alarm_data[2], alarm_data[8]))
elif event_type == 0xE8:
if alarm_data[0] == 0x03:
# alarm_data[7] might be humidity in some form, but as an integer
Expand Down
3 changes: 2 additions & 1 deletion wyzesense2mqtt/wyzesense2mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ def on_event(WYZESENSE_DONGLE, event):
STATES_ON = ['active', 'open', 'wet']

if (valid_sensor_mac(event.MAC)):
if (event.Type == "state"):
if (event.Type == "alarm") or (event.Type == "status"):
LOGGER.info(f"State event data: {event}")
(sensor_type, sensor_state, sensor_battery, sensor_signal) = event.Data

Expand All @@ -445,6 +445,7 @@ def on_event(WYZESENSE_DONGLE, event):

# Build event payload
event_payload = {
'event' : event.Type,
'available': True,
'mac': event.MAC,
'device_class': DEVICE_CLASSES.get(sensor_type),
Expand Down