Window Alert Automation: Notify When Windows Are Open for Over an Hour

Hi everyone! I just wanted to share a quick automation I set up using AppDaemon that might be helpful for others. It’s a simple yet useful feature that notifies me when any window in my home has been open for more than an hour. This helps me catch any accidental open windows that might be letting in cold air or pests.

Entities Involved:

  • binary_sensor.bedroom_window
  • binary_sensor.kitchen_window

Groups Used:
yaml
windows:
name: Windows
view: no
entities:
- binary_sensor.bedroom_window
- binary_sensor.kitchen_window

Automation Code:
python
import appdaemon.plugins.hass.hassapi as hass
class WindowAlert(hass.Hass):
def initialize(self):
self.log(‘Initializing Window Alert…’)
group = self.get_state(self.args[‘windows’], attribute=‘all’)
sensors = group[‘attributes’][‘entity_id’]
for sensor in sensors:
self.listen_state(self.on_windows_open, sensor, new=‘on’, duration=3.600)

def on_windows_open(self, entity, attribute, old, new, kwargs):
    window_name = self.friendly_name(entity)
    self.log(f'Alert! The {window_name} has been open for more than one hour.')
    # Add your notification logic here

This setup works seamlessly with Home Assistant and AppDaemon. It’s a great example of how small automations can make a big difference in daily life. If anyone has suggestions for improvements or wants to share similar setups, I’d love to hear them! Happy coding! :rocket: