From 96f49101817586187594c419cae4c6872d2b3c5b Mon Sep 17 00:00:00 2001 From: Ak5nowman Date: Sun, 9 May 2021 20:52:21 -0800 Subject: [PATCH 01/13] Add V2 Motion and Contact Sensor support --- wyzesense2mqtt/wyzesense.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/wyzesense2mqtt/wyzesense.py b/wyzesense2mqtt/wyzesense.py index 189b4e8..9569936 100755 --- a/wyzesense2mqtt/wyzesense.py +++ b/wyzesense2mqtt/wyzesense.py @@ -270,9 +270,15 @@ def _OnSensorAlarm(self, pkt): elif alarm_data[0] == 0x03: sensor_type = "leak" sensor_state = "wet" if alarm_data[5] == 1 else "dry" + elif alarm_data[0] == 0xE: + sensor_type = "switchv2" + sensor_state = "open" if alarm_data[5] == 1 else "close" + elif alarm_data[0] == 0xF: + sensor_type = "motionv2" + sensor_state = "active" if alarm_data[5] == 1 else "inactive" else: - sensor_type = "unknown" - sensor_state = "unknown" + sensor_type = "unknown (" + alarm_data[0] + ")" + sensor_state = "unknown (" + alarm_data[5] + ")" 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: From f5efe9d76274bbd1b9d6963a7d61f718db3b85c5 Mon Sep 17 00:00:00 2001 From: drinfernoo Date: Thu, 13 May 2021 09:30:05 -0700 Subject: [PATCH 02/13] Refactor V2 support --- wyzesense2mqtt/wyzesense.py | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/wyzesense2mqtt/wyzesense.py b/wyzesense2mqtt/wyzesense.py index 9569936..d25bbe6 100755 --- a/wyzesense2mqtt/wyzesense.py +++ b/wyzesense2mqtt/wyzesense.py @@ -260,22 +260,24 @@ def _OnSensorAlarm(self, pkt): timestamp = datetime.datetime.fromtimestamp(timestamp / 1000.0) sensor_mac = sensor_mac.decode('ascii') alarm_data = pkt.Payload[17:] + + # {sensor_id: "sensor type", "states": ["off state", "on state"]} + contact_ids = {0x01: "switch", 0xE: "switchv2", "states": ["close", "open"]} + motion_ids = {0x02: "motion", 0xF: "motionv2", "states": ["inactive", "active"]} + leak_ids = {0x03: "leak", "states": ["dry", "wet"]} + 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" - elif alarm_data[0] == 0x02: - sensor_type = "motion" - sensor_state = "active" if alarm_data[5] == 1 else "inactive" - elif alarm_data[0] == 0x03: - sensor_type = "leak" - sensor_state = "wet" if alarm_data[5] == 1 else "dry" - elif alarm_data[0] == 0xE: - sensor_type = "switchv2" - sensor_state = "open" if alarm_data[5] == 1 else "close" - elif alarm_data[0] == 0xF: - sensor_type = "motionv2" - sensor_state = "active" if alarm_data[5] == 1 else "inactive" + sensor = {} + if alarm_data[0] in contact_ids: + sensor = contact_ids + elif alarm_data[0] in motion_ids: + sensor = motion_ids + elif alarm_data[0] in leak_ids: + sensor = leak_ids + + if sensor: + sensor_type = sensor[alarm_data[0]] + sensor_state = sensor["states"][alarm_data[5]] else: sensor_type = "unknown (" + alarm_data[0] + ")" sensor_state = "unknown (" + alarm_data[5] + ")" From d074c9606c5d8b1de972a3e27c66e17ae49a4336 Mon Sep 17 00:00:00 2001 From: drinfernoo Date: Thu, 13 May 2021 09:47:53 -0700 Subject: [PATCH 03/13] Add V2 sensor device classes --- wyzesense2mqtt/wyzesense2mqtt.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/wyzesense2mqtt/wyzesense2mqtt.py b/wyzesense2mqtt/wyzesense2mqtt.py index f402017..6aa1932 100755 --- a/wyzesense2mqtt/wyzesense2mqtt.py +++ b/wyzesense2mqtt/wyzesense2mqtt.py @@ -428,7 +428,9 @@ def on_event(WYZESENSE_DONGLE, event): DEVICE_CLASSES = { 'leak': 'moisture', 'motion': 'motion', + 'motionv2': 'motion', 'switch': 'opening', + 'switchv2': 'opening' } # List of states that correlate to ON. From 14d236a01c156f00b04f59993b94bf9608b71061 Mon Sep 17 00:00:00 2001 From: drinfernoo Date: Thu, 13 May 2021 15:02:40 -0700 Subject: [PATCH 04/13] Consistent device IDs --- wyzesense2mqtt/wyzesense.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wyzesense2mqtt/wyzesense.py b/wyzesense2mqtt/wyzesense.py index d25bbe6..6871996 100755 --- a/wyzesense2mqtt/wyzesense.py +++ b/wyzesense2mqtt/wyzesense.py @@ -262,8 +262,8 @@ def _OnSensorAlarm(self, pkt): alarm_data = pkt.Payload[17:] # {sensor_id: "sensor type", "states": ["off state", "on state"]} - contact_ids = {0x01: "switch", 0xE: "switchv2", "states": ["close", "open"]} - motion_ids = {0x02: "motion", 0xF: "motionv2", "states": ["inactive", "active"]} + contact_ids = {0x01: "switch", 0x0E: "switchv2", "states": ["close", "open"]} + motion_ids = {0x02: "motion", 0x0F: "motionv2", "states": ["inactive", "active"]} leak_ids = {0x03: "leak", "states": ["dry", "wet"]} if event_type == 0xA2 or event_type == 0xA1: From 34110b534eb596df31e05378c3e4412942300bd6 Mon Sep 17 00:00:00 2001 From: drinfernoo Date: Thu, 13 May 2021 16:28:31 -0700 Subject: [PATCH 05/13] Add device_class automatically --- wyzesense2mqtt/wyzesense2mqtt.py | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/wyzesense2mqtt/wyzesense2mqtt.py b/wyzesense2mqtt/wyzesense2mqtt.py index 6aa1932..ddb47dc 100755 --- a/wyzesense2mqtt/wyzesense2mqtt.py +++ b/wyzesense2mqtt/wyzesense2mqtt.py @@ -26,6 +26,15 @@ LOGGING_CONFIG_FILE = "logging.yaml" SENSORS_CONFIG_FILE = "sensors.yaml" +# Simplify mapping of device classes. +# { sensor_id: {'type': 'sensor_type', 'class', 'device_class'} } +DEVICE_CLASSES = { + 0x01: {'type': 'switch', 'class': 'opening'}, + 0x02: {'type': 'motion', 'class': 'motion'}, + 0x03: {'type': 'leak', 'class': 'moisture'}, + 0x0E: {'type': 'switchv2', 'class': 'opening'}, + 0x0F: {'type': 'motionv2', 'class': 'motion'} +} # Read data from YAML file def read_yaml_file(filename): @@ -227,10 +236,7 @@ def add_sensor_to_config(sensor_mac, sensor_type, sensor_version): LOGGER.info(f"Adding sensor to config: {sensor_mac}") SENSORS[sensor_mac] = dict() SENSORS[sensor_mac]['name'] = f"Wyze Sense {sensor_mac}" - SENSORS[sensor_mac]['class'] = ( - "motion" if (sensor_type == "motion") - else "opening" - ) + SENSORS[sensor_mac]['class'] = DEVICE_CLASSES.get(sensor_type, {'type': 'unknown', 'class': 'opening'}).get('class') SENSORS[sensor_mac]['invert_state'] = False if (sensor_version is not None): SENSORS[sensor_mac]['sw_version'] = sensor_version @@ -380,7 +386,6 @@ def on_message_scan(MQTT_CLIENT, userdata, msg): LOGGER.debug(f"Scan result: {result}") if (result): sensor_mac, sensor_type, sensor_version = result - sensor_type = ("motion" if (sensor_type == 2) else "opening") if (valid_sensor_mac(sensor_mac)): if (SENSORS.get(sensor_mac)) is None: add_sensor_to_config( @@ -424,15 +429,6 @@ def on_message_reload(MQTT_CLIENT, userdata, msg): def on_event(WYZESENSE_DONGLE, event): global SENSORS - # Simplify mapping of device classes. - DEVICE_CLASSES = { - 'leak': 'moisture', - 'motion': 'motion', - 'motionv2': 'motion', - 'switch': 'opening', - 'switchv2': 'opening' - } - # List of states that correlate to ON. STATES_ON = ['active', 'open', 'wet'] @@ -447,12 +443,13 @@ def on_event(WYZESENSE_DONGLE, event): if(CONFIG['hass_discovery']): send_discovery_topics(event.MAC) + device = [DEVICE_CLASSES[i] for i in DEVICE_CLASSES if DEVICE_CLASSES[i].get('type') == sensor_type][0] # Build event payload event_payload = { 'event': event.Type, 'available': True, 'mac': event.MAC, - 'device_class': DEVICE_CLASSES.get(sensor_type), + 'device_class': device.get('class'), 'last_seen': event.Timestamp.timestamp(), 'last_seen_iso': event.Timestamp.isoformat(), 'signal_strength': sensor_signal * -1, From e00c08462a65f0d59a66fc5df65f2b76ddcfb7bd Mon Sep 17 00:00:00 2001 From: drinfernoo Date: Thu, 13 May 2021 18:58:31 -0700 Subject: [PATCH 06/13] Refactor device_class lookup --- wyzesense2mqtt/wyzesense2mqtt.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/wyzesense2mqtt/wyzesense2mqtt.py b/wyzesense2mqtt/wyzesense2mqtt.py index ddb47dc..9f7cbe9 100755 --- a/wyzesense2mqtt/wyzesense2mqtt.py +++ b/wyzesense2mqtt/wyzesense2mqtt.py @@ -27,13 +27,11 @@ SENSORS_CONFIG_FILE = "sensors.yaml" # Simplify mapping of device classes. -# { sensor_id: {'type': 'sensor_type', 'class', 'device_class'} } +# { **dict.fromkeys(['list', 'of', 'possible', 'identifiers'], 'device_class') } DEVICE_CLASSES = { - 0x01: {'type': 'switch', 'class': 'opening'}, - 0x02: {'type': 'motion', 'class': 'motion'}, - 0x03: {'type': 'leak', 'class': 'moisture'}, - 0x0E: {'type': 'switchv2', 'class': 'opening'}, - 0x0F: {'type': 'motionv2', 'class': 'motion'} + **dict.fromkeys([0x01, 0x0E, 'switch', 'switchv2'], 'opening'), + **dict.fromkeys([0x02, 0x0F, 'motion', 'motionv2'], 'motion'), + **dict.fromkeys([0x03, 'leak'], 'moisture') } # Read data from YAML file @@ -236,7 +234,7 @@ def add_sensor_to_config(sensor_mac, sensor_type, sensor_version): LOGGER.info(f"Adding sensor to config: {sensor_mac}") SENSORS[sensor_mac] = dict() SENSORS[sensor_mac]['name'] = f"Wyze Sense {sensor_mac}" - SENSORS[sensor_mac]['class'] = DEVICE_CLASSES.get(sensor_type, {'type': 'unknown', 'class': 'opening'}).get('class') + SENSORS[sensor_mac]['class'] = DEVICE_CLASSES.get(sensor_type) SENSORS[sensor_mac]['invert_state'] = False if (sensor_version is not None): SENSORS[sensor_mac]['sw_version'] = sensor_version @@ -443,13 +441,12 @@ def on_event(WYZESENSE_DONGLE, event): if(CONFIG['hass_discovery']): send_discovery_topics(event.MAC) - device = [DEVICE_CLASSES[i] for i in DEVICE_CLASSES if DEVICE_CLASSES[i].get('type') == sensor_type][0] # Build event payload event_payload = { 'event': event.Type, 'available': True, 'mac': event.MAC, - 'device_class': device.get('class'), + 'device_class': DEVICE_CLASSES.get(sensor_type), 'last_seen': event.Timestamp.timestamp(), 'last_seen_iso': event.Timestamp.isoformat(), 'signal_strength': sensor_signal * -1, From 904ceded454ab9fc923d5bcfd1beff3549a4fe1f Mon Sep 17 00:00:00 2001 From: drinfernoo Date: Thu, 13 May 2021 20:46:33 -0700 Subject: [PATCH 07/13] More performant dict initialization --- wyzesense2mqtt/wyzesense2mqtt.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/wyzesense2mqtt/wyzesense2mqtt.py b/wyzesense2mqtt/wyzesense2mqtt.py index 9f7cbe9..ee51d7f 100755 --- a/wyzesense2mqtt/wyzesense2mqtt.py +++ b/wyzesense2mqtt/wyzesense2mqtt.py @@ -166,7 +166,7 @@ def init_wyzesense_dongle(): def init_sensors(): # Initialize sensor dictionary global SENSORS - SENSORS = dict() + SENSORS = {} # Load config file LOGGER.debug("Reading sensors configuration...") @@ -232,10 +232,11 @@ def valid_sensor_mac(sensor_mac): def add_sensor_to_config(sensor_mac, sensor_type, sensor_version): global SENSORS LOGGER.info(f"Adding sensor to config: {sensor_mac}") - SENSORS[sensor_mac] = dict() - SENSORS[sensor_mac]['name'] = f"Wyze Sense {sensor_mac}" - SENSORS[sensor_mac]['class'] = DEVICE_CLASSES.get(sensor_type) - SENSORS[sensor_mac]['invert_state'] = False + SENSORS[sensor_mac] = { + 'name': f"Wyze Sense {sensor_mac}", + 'class': DEVICE_CLASSES.get(sensor_type), + 'invert_state': False + } if (sensor_version is not None): SENSORS[sensor_mac]['sw_version'] = sensor_version From 2858d872aa3911dc30a765523a6e3abd956033a4 Mon Sep 17 00:00:00 2001 From: drinfernoo Date: Thu, 13 May 2021 21:06:04 -0700 Subject: [PATCH 08/13] Update readme.md regarding device_class options --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 845d3ff..7dfcba2 100644 --- a/readme.md +++ b/readme.md @@ -179,7 +179,7 @@ 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. 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. More class types that Home Assistant recgonizes can be found in the [`binary_sensor` documentation](https://www.home-assistant.io/integrations/binary_sensor/) Since this file can be automatically generated, Python may automatically quote the MACs or not depending on if they are fully numeric. ```yaml 'AAAAAAAA': class: door From 509d9f7c37d9745c433d336cb5eebcaf1901657d Mon Sep 17 00:00:00 2001 From: drinfernoo Date: Thu, 13 May 2021 21:21:54 -0700 Subject: [PATCH 09/13] Use os.path.join for paths --- wyzesense2mqtt/wyzesense2mqtt.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/wyzesense2mqtt/wyzesense2mqtt.py b/wyzesense2mqtt/wyzesense2mqtt.py index ee51d7f..f80d202 100755 --- a/wyzesense2mqtt/wyzesense2mqtt.py +++ b/wyzesense2mqtt/wyzesense2mqtt.py @@ -20,8 +20,8 @@ # Configuration File Locations -CONFIG_PATH = "config/" -SAMPLES_PATH = "samples/" +CONFIG_PATH = "config" +SAMPLES_PATH = "samples" MAIN_CONFIG_FILE = "config.yaml" LOGGING_CONFIG_FILE = "logging.yaml" SENSORS_CONFIG_FILE = "sensors.yaml" @@ -62,13 +62,13 @@ def write_yaml_file(filename, data): # Initialize logging def init_logging(): global LOGGER - if (not os.path.isfile(CONFIG_PATH + LOGGING_CONFIG_FILE)): + if (not os.path.isfile(os.path.join(CONFIG_PATH, LOGGING_CONFIG_FILE))): print("Copying default logging config file...") try: - shutil.copy2(SAMPLES_PATH + LOGGING_CONFIG_FILE, CONFIG_PATH) + shutil.copy2(os.path.join(SAMPLES_PATH, LOGGING_CONFIG_FILE), CONFIG_PATH) except IOError as error: print(f"Unable to copy default logging config file. {str(error)}") - logging_config = read_yaml_file(CONFIG_PATH + LOGGING_CONFIG_FILE) + logging_config = read_yaml_file(os.path.join(CONFIG_PATH, LOGGING_CONFIG_FILE)) log_path = os.path.dirname(logging_config['handlers']['file']['filename']) try: @@ -87,12 +87,12 @@ def init_config(): LOGGER.debug("Initializing configuration...") # load base config - allows for auto addition of new settings - if (os.path.isfile(SAMPLES_PATH + MAIN_CONFIG_FILE)): - CONFIG = read_yaml_file(SAMPLES_PATH + MAIN_CONFIG_FILE) + if (os.path.isfile(os.path.join(SAMPLES_PATH, MAIN_CONFIG_FILE))): + CONFIG = read_yaml_file(os.path.join(SAMPLES_PATH, MAIN_CONFIG_FILE)) # load user config over base - if (os.path.isfile(CONFIG_PATH + MAIN_CONFIG_FILE)): - user_config = read_yaml_file(CONFIG_PATH + MAIN_CONFIG_FILE) + if (os.path.isfile(os.path.join(CONFIG_PATH, MAIN_CONFIG_FILE))): + user_config = read_yaml_file(os.path.join(CONFIG_PATH, MAIN_CONFIG_FILE)) CONFIG.update(user_config) # fail on no config @@ -103,7 +103,7 @@ def init_config(): # write updated config file if needed if (CONFIG != user_config): LOGGER.info("Writing updated config file") - write_yaml_file(CONFIG_PATH + MAIN_CONFIG_FILE, CONFIG) + write_yaml_file(os.path.join(CONFIG_PATH, MAIN_CONFIG_FILE), CONFIG) # Initialize MQTT client connection @@ -170,8 +170,8 @@ def init_sensors(): # Load config file LOGGER.debug("Reading sensors configuration...") - if (os.path.isfile(CONFIG_PATH + SENSORS_CONFIG_FILE)): - SENSORS = read_yaml_file(CONFIG_PATH + SENSORS_CONFIG_FILE) + if (os.path.isfile(os.path.join(CONFIG_PATH, SENSORS_CONFIG_FILE))): + SENSORS = read_yaml_file(os.path.join(CONFIG_PATH, SENSORS_CONFIG_FILE)) sensors_config_file_found = True else: LOGGER.info("No sensors config file found.") @@ -199,7 +199,7 @@ def init_sensors(): # Save sensors file if didn't exist if (not sensors_config_file_found): LOGGER.info("Writing Sensors Config File") - write_yaml_file(CONFIG_PATH + SENSORS_CONFIG_FILE, SENSORS) + write_yaml_file(os.path.join(CONFIG_PATH, SENSORS_CONFIG_FILE), SENSORS) # Send discovery topics if(CONFIG['hass_discovery']): @@ -240,7 +240,7 @@ def add_sensor_to_config(sensor_mac, sensor_type, sensor_version): if (sensor_version is not None): SENSORS[sensor_mac]['sw_version'] = sensor_version - write_yaml_file(CONFIG_PATH + SENSORS_CONFIG_FILE, SENSORS) + write_yaml_file(os.path.join(CONFIG_PATH, SENSORS_CONFIG_FILE), SENSORS) # Delete sensor from config @@ -249,7 +249,7 @@ def delete_sensor_from_config(sensor_mac): LOGGER.info(f"Deleting sensor from config: {sensor_mac}") try: del SENSORS[sensor_mac] - write_yaml_file(CONFIG_PATH + SENSORS_CONFIG_FILE, SENSORS) + write_yaml_file(os.path.join(CONFIG_PATH, SENSORS_CONFIG_FILE), SENSORS) except KeyError: LOGGER.debug(f"{sensor_mac} not found in SENSORS") From 2618241e158533b45512de27653b69b43660bf41 Mon Sep 17 00:00:00 2001 From: drinfernoo Date: Thu, 13 May 2021 21:20:59 -0700 Subject: [PATCH 10/13] Replace last %s format with f-string --- wyzesense2mqtt/wyzesense2mqtt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wyzesense2mqtt/wyzesense2mqtt.py b/wyzesense2mqtt/wyzesense2mqtt.py index f80d202..9676331 100755 --- a/wyzesense2mqtt/wyzesense2mqtt.py +++ b/wyzesense2mqtt/wyzesense2mqtt.py @@ -148,7 +148,7 @@ def init_wyzesense_dongle(): if (("e024" in line) and ("1a86" in line)): for device_name in line.split(" "): if ("hidraw" in device_name): - CONFIG['usb_dongle'] = "/dev/%s" % device_name + CONFIG['usb_dongle'] = f"/dev/{device_name}" break LOGGER.info(f"Connecting to dongle {CONFIG['usb_dongle']}") From eb2daa2762ab1a0e55ecb66983fa09fb77a3290f Mon Sep 17 00:00:00 2001 From: Elias Hunt Date: Fri, 14 May 2021 09:38:47 -0400 Subject: [PATCH 11/13] Update version.txt Moving version to 2.0 with the addition of V2 sensor support. --- version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.txt b/version.txt index 5625e59..cd5ac03 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.2 +2.0 From 29de8180158ea6762067bb51cc4bd3b4bca4c645 Mon Sep 17 00:00:00 2001 From: drinfernoo Date: Fri, 14 May 2021 07:32:01 -0700 Subject: [PATCH 12/13] Update readme.md regarding device classes --- readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 7dfcba2..daead7e 100644 --- a/readme.md +++ b/readme.md @@ -179,7 +179,7 @@ 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. More class types that Home Assistant recgonizes can be found in the [`binary_sensor` documentation](https://www.home-assistant.io/integrations/binary_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. ```yaml 'AAAAAAAA': class: door @@ -233,7 +233,7 @@ Once run it will present a menu of its functions: ## Home Assistant -Home Assistant simply needs to be configured with the MQTT broker that the gateway publishes topics to. Once configured, the MQTT integration will automatically add devices for each sensor along with entites for the state, battery_level, and signal_strength. By default these entities will have a device_class of "opening" for contact sensors and "motion" for motion sensors. They will be named for the sensor type and MAC, e.g. Wyze Sense Contact Sensor AABBCCDD. To adjust the device_class to door or window, and set a custom name, update the sensors.yaml configuration file and replace the defaults, then restart WyzeSense2MQTT. +Home Assistant simply needs to be configured with the MQTT broker that the gateway publishes topics to. Once configured, the MQTT integration will automatically add devices for each sensor along with entites for the state, battery_level, and signal_strength. By default these entities will have a device_class of "opening" for contact sensors, "motion" for motion sensors, and "moisture" for leak sensors. They will be named for the sensor type and MAC, e.g. Wyze Sense Contact Sensor AABBCCDD. To adjust the device_class to "door" or "window", and set a custom name, update the sensors.yaml configuration file and replace the defaults, then restart WyzeSense2MQTT. For a comprehensive list of device classes the Home Assistant recognizes, see the [`binary_sensor` documentation](https://www.home-assistant.io/integrations/binary_sensor/). ## Tested On From b04bb5d4a7d3bc9bbf2f90329d0f0c3ee81a48e2 Mon Sep 17 00:00:00 2001 From: drinfernoo Date: Fri, 19 Nov 2021 09:34:47 -0800 Subject: [PATCH 13/13] :speech_balloon: - Add sensor name to log entries Closes #47 --- wyzesense2mqtt/wyzesense2mqtt.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/wyzesense2mqtt/wyzesense2mqtt.py b/wyzesense2mqtt/wyzesense2mqtt.py index 9676331..f990157 100755 --- a/wyzesense2mqtt/wyzesense2mqtt.py +++ b/wyzesense2mqtt/wyzesense2mqtt.py @@ -431,17 +431,17 @@ def on_event(WYZESENSE_DONGLE, event): # List of states that correlate to ON. STATES_ON = ['active', 'open', 'wet'] - if (valid_sensor_mac(event.MAC)): + if valid_sensor_mac(event.MAC): 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 # Add sensor if it doesn't already exist - if (event.MAC not in SENSORS): + if event.MAC not in SENSORS: add_sensor_to_config(event.MAC, sensor_type, None) - if(CONFIG['hass_discovery']): + if CONFIG['hass_discovery']: send_discovery_topics(event.MAC) + LOGGER.info(f"State event data from {SENSORS[event.MAC]['name']}: {event}") # Build event payload event_payload = { 'event': event.Type,