From e4b148458bf97162509acc59b96ba52c52ce905e Mon Sep 17 00:00:00 2001
From: Erik Montnemery <erik@montnemery.com>
Date: Mon, 4 Apr 2022 11:02:30 +0200
Subject: [PATCH] Unsubscribe from listeners when removing threshold binary
 sensor (#69236)

---
 homeassistant/components/threshold/binary_sensor.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/homeassistant/components/threshold/binary_sensor.py b/homeassistant/components/threshold/binary_sensor.py
index 49a97d84f0e..802aa22d759 100644
--- a/homeassistant/components/threshold/binary_sensor.py
+++ b/homeassistant/components/threshold/binary_sensor.py
@@ -151,8 +151,10 @@ class ThresholdSensor(BinarySensorEntity):
             _update_sensor_state()
             self.async_write_ha_state()
 
-        async_track_state_change_event(
-            hass, [entity_id], async_threshold_sensor_state_listener
+        self.async_on_remove(
+            async_track_state_change_event(
+                hass, [entity_id], async_threshold_sensor_state_listener
+            )
         )
         _update_sensor_state()