diff --git a/homeassistant/components/sensor/mysensors.py b/homeassistant/components/sensor/mysensors.py index 5b772182d9c..4451b7d7755 100644 --- a/homeassistant/components/sensor/mysensors.py +++ b/homeassistant/components/sensor/mysensors.py @@ -16,7 +16,7 @@ import homeassistant.external.pymysensors.mysensors.mysensors as mysensors import homeassistant.external.pymysensors.mysensors.const as const from homeassistant.helpers.entity import Entity -from homeassistant.const import ATTR_BATTERY_LEVEL +from homeassistant.const import (ATTR_BATTERY_LEVEL, EVENT_HOMEASSISTANT_STOP) CONF_PORT = "port" @@ -49,6 +49,9 @@ def setup_platform(hass, config, add_devices, discovery_info=None): gateway = mysensors.SerialGateway(port, sensor_update) gateway.start() + hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, + lambda event: gateway.stop()) + class MySensorsNode(Entity): """ Represents a MySensors node. """