I am just sharing mi automation logic. I want to turn off my tv and everything at 1:30am if I fall asleep. I first turn off the receiver and wait for 60sec and if I do not respond by turning it back on, then HASS turns everything off.
This is the automation I have:
- id: '1602516453367'
alias: TV - Sleep
description: ''
trigger:
- platform: time
at: 01:30:00
condition: []
action:
- service: switch.turn_off
data: {}
entity_id: switch.receiver
- delay: '60'
- condition: state
entity_id: switch.receiver
state: 'off'
- service: script.room_off
data: {}
mode: single