raetha / wyzesense2mqtt

Configurable WyzeSense to MQTT Gateway intended for use with Home Assistant or other platforms that use MQTT discovery mechanisms.
MIT License
79 stars 22 forks source link

Add friendly name to event MQTT message #25

Closed dennyfmn closed 4 years ago

dennyfmn commented 4 years ago

I wanted to be able to parse the sensors by their friendly name so I added a couple of lines to wyzesense2mqtt.py

Process event

def on_event(WYZESENSE_DONGLE, event): if (valid_sensor_mac(event.MAC)): if (event.Type == "state"): LOGGER.info(f"State event data: {event}") (sensor_type, sensor_state, sensor_battery, sensor_signal) = event.Data sensor_name = SENSORS[event.MAC]['name'] <<<--------- event_payload = { 'available': True, 'name': sensor_name, <<<------------ 'mac': event.MAC,

This works for me. Please consider adding it to the main code.

I do not run Home Assistant. I use MQTT with Node-Red and other local scripts. Thanks for the great bridge software, it gives me access to these very inexpensive sensors. Running as a service on an old Pi Model B Revision 2.0 under Buster.

dale3h commented 4 years ago

I like this idea, but I would suggest that it be configurable via config.yaml.

dennyfmn commented 4 years ago

Thank you for turning this into a proper pull request; I'm not facile with GIT. I appreciate your quick and well thought out response.

raetha commented 4 years ago

@dennyfmn thanks for the good idea here, and @dale3h thanks for the quick implementation. I submitted a few requested tweaks on the PR, but otherwise will be happy to pull this in this weekend. And I think I'll wrap 1.1 so that this is officially released as well.

dale3h commented 4 years ago

This issue can be closed as per #26 and 7684bffc309895d1f29fd1d17b0f8473fe935577.