So I have an automation that turns off our TVS. It’s quite complex and it does so starting at 10pm (based on a helper device) for the kids TVs and then starting at 1am, it will turn off any TVs that were turned back on every hour until 5am (I often wake up and will watch TV to go back to sleep. Don’t judge me! LOL)
Anyways, in my son’s room, the automation correctly turns off his TV, but then a few seconds later, it turns it back on! I can’t figure this out.
This is the Trace Timeline from last night’s execution:
Here is my automation yaml:
id: '1686578849785'
alias: Turn off TVs at night.
description: ''
triggers:
- at: input_datetime.turn_off_tv_time
id: Turn off all tvs
trigger: time
- entity_id:
- binary_sensor.kids_tv_off
id: Kids TV Sensor Changed
to:
- 'on'
- 'off'
trigger: state
- value_template: |-
{% set rightNow = now().replace(second=0,microsecond=0) %}
{% set startTime = today_at(states('input_datetime.turn_off_tv_time')) %}
{% set endTime = today_at('05:00:00') %}
{{ rightNow > startTime and rightNow <= endTime
and rightNow.minute == 0 }}
id: Turn off all tvs
trigger: template
- value_template: >-
{% set rightNow = now() %}
{% set startTime = today_at(states('input_datetime.turn_off_tv_time')) -
timedelta(minutes=10) %}
{% set endTime = today_at('5:00') %}
{% if timedelta(minutes=0) < (rightNow - (startTime+ timedelta(days=1))) <
timedelta(minutes=1) %}
{% set startTime = startTime + timedelta(days=1) %}
{% set endTime = endTime + timedelta(days=1) %}
{% endif %}
{{ rightNow >= startTime
and rightNow <= endTime
and rightNow.minute == startTime.minute }}
id: Notify TVs will be turning off
trigger: template
conditions: []
actions:
- choose:
- conditions:
- condition: trigger
id:
- Turn off all tvs
sequence:
- if:
- condition: device
type: is_on
device_id: 789c80edfc8da7b976f8ca5cad665f44
entity_id: c7cd5e201ed041de60279f8dc2998925
domain: remote
then:
- type: turn_off
device_id: 789c80edfc8da7b976f8ca5cad665f44
entity_id: remote.front_bedroom_harmony
domain: remote
alias: Turn off front bedroom harmony if it's on
- if:
- condition: device
type: is_on
device_id: e4a14e8b13307745b509cd2b988b6a2b
entity_id: ee95a2a5f270f1d2a11ffe6784c64e6f
domain: remote
then:
- type: turn_off
device_id: e4a14e8b13307745b509cd2b988b6a2b
entity_id: ee95a2a5f270f1d2a11ffe6784c64e6f
domain: remote
alias: Turn off middle bedroom harmony if it's on
- if:
- condition: device
type: is_on
device_id: 1dc17bef2b089f9c75b9157abb70e8a1
entity_id: 130f87f0387f7225db8028288025f68b
domain: remote
then:
- type: turn_off
device_id: 1dc17bef2b089f9c75b9157abb70e8a1
entity_id: remote.back_bedroom_harmony
domain: remote
enabled: true
alias: Turn off back bedroom harmony if it's on
- if:
- condition: device
type: is_on
device_id: da60c2d867476ed304694196285ca1d8
entity_id: b0fadeb1cab7ca220337c507ae49ec85
domain: remote
then:
- type: turn_off
device_id: da60c2d867476ed304694196285ca1d8
entity_id: remote.master_bedroom_harmony
domain: remote
enabled: true
alias: Turn off master bedroom harmony if it's on
- alias: Turn off living room harmony if it's on
if:
- condition: device
type: is_on
device_id: 29b1717e190031db1a44aa78e9dd8318
entity_id: ed597dfb50fd107e3f31667e1cd5d078
domain: remote
then:
- type: turn_off
device_id: 29b1717e190031db1a44aa78e9dd8318
entity_id: ed597dfb50fd107e3f31667e1cd5d078
domain: remote
- conditions:
- condition: trigger
id:
- Kids TV Sensor Changed
sequence:
- choose:
- conditions:
- condition: state
entity_id: binary_sensor.kids_tv_off
state: 'on'
sequence:
- type: turn_off
device_id: e4a14e8b13307745b509cd2b988b6a2b
entity_id: ee95a2a5f270f1d2a11ffe6784c64e6f
domain: remote
- delay:
hours: 0
minutes: 1
seconds: 0
milliseconds: 0
enabled: true
- type: turn_off
device_id: 53b5bb662e1226cda3e2bbce33216b29
entity_id: e8170e3285431c20f9f449d0e6e8f91d
domain: switch
- metadata: {}
data:
message: Boys tv off
action: notify.mobile_app_pixel_6_pro
enabled: false
- type: turn_off
device_id: 789c80edfc8da7b976f8ca5cad665f44
entity_id: c7cd5e201ed041de60279f8dc2998925
domain: remote
- conditions:
- condition: state
entity_id: binary_sensor.kids_tv_off
state: 'off'
sequence:
- type: turn_on
device_id: 53b5bb662e1226cda3e2bbce33216b29
entity_id: e8170e3285431c20f9f449d0e6e8f91d
domain: switch
- metadata: {}
data:
message: Boys tv on
action: notify.mobile_app_pixel_6_pro
enabled: false
- if:
- condition: state
entity_id: input_boolean.kids_tv_exception
state: 'on'
then:
- metadata: {}
data: {}
target:
entity_id: input_boolean.kids_tv_exception
action: input_boolean.turn_off
- conditions:
- condition: trigger
id:
- Notify TVs will be turning off
sequence:
- if:
- condition: device
type: is_on
device_id: 1dc17bef2b089f9c75b9157abb70e8a1
entity_id: 130f87f0387f7225db8028288025f68b
domain: remote
then:
- data:
data:
duration: 4
position: bottom-lright
fontsize: medium
transparency: 90%
color: black
interrupt: 0
message: The TV is going to turn off in 10 minutes.
action: notify.back_bedroom_tv
alias: If Back Bedroom TV is on, send notification
- if:
- condition: device
type: is_on
device_id: 29b1717e190031db1a44aa78e9dd8318
entity_id: ed597dfb50fd107e3f31667e1cd5d078
domain: remote
then:
- data:
entity_id: media_player.lg_webos_smart_tv
command: system.notifications/createAlert
payload:
message: The TV is going to turn off in 10 minutes.
action: webostv.command
- delay:
hours: 0
minutes: 0
seconds: 15
milliseconds: 0
- data:
entity_id: media_player.lg_webos_smart_tv
button: ENTER
action: webostv.button
alias: If Living Room TV is on, send notification
- alias: If Middle Bedroom TV is on, send notification
if:
- condition: device
type: is_on
device_id: e4a14e8b13307745b509cd2b988b6a2b
entity_id: ee95a2a5f270f1d2a11ffe6784c64e6f
domain: remote
then:
- data:
data:
duration: 4
position: bottom-lright
fontsize: medium
transparency: 90%
color: black
interrupt: 0
message: The TV is going to turn off in 10 minutes.
action: notify.middle_bedroom_tv
mode: parallel
max: 5
trace:
stored_traces: 20