TV automation is not working

I am having some trouble getting an automation to work. I have one automation that turns my children’s smart tv off at a certain time of day and it is working just fine. I wrote another automation that would send me a notification and power off the smart tv if they tried to turn it back on after said time. For some reason it doesn’t work. This is the code:

- id: '1619990750279'
  alias: Darren's TV
  trigger:
  - platform: device
    device_id: b8e4cf3030321b083ddc1468afbdcba4
    domain: media_player
    entity_id: media_player.darren_s_tv
    type: turned_on
  - platform: device
    device_id: b8e4cf3030321b083ddc1468afbdcba4
    domain: media_player
    entity_id: media_player.darren_s_tv
    type: playing
  condition:
  - condition: time
    after: '20:15:30'
    before: '12:00:00'
    weekday:
    - mon
    - tue
    - wed
    - thu
    - fri
  - condition: time
    after: '20:15:30'
    before: '10:00:00'
    weekday:
    - sat
    - sun
  action:
  - service: notify.mobile_app_jacobs_iphone
    data:
      message: Darren's TV is on
  - service: media_player.turn_off
    target:
      device_id: b8e4cf3030321b083ddc1468afbdcba4

I have also tried using the device state:

- id: '1619990596215'
  alias: Lilly's TV
  trigger:
  - platform: state
    entity_id: media_player.lilly_s_tv
    from: 'Off'
    to: 'On'
    for: 5 seconds
  condition:
  - condition: time
    after: '20:45:05'
    before: '12:00:00'
    weekday:
    - mon
    - tue
    - wed
    - thu
    - fri
  - condition: time
    after: '20:45:05'
    before: '10:00:00'
    weekday:
    - sat
    - sun
  action:
  - service: notify.mobile_app_jacobs_iphone
    data:
      message: Lilly's TV is on
  - service: media_player.turn_off
    target:
      device_id: 4b9cb9da7fbc9fab8367c36db6ba5331

I must be missing something or overlooking something simple. Any help is greatly appreciated.

Thanks

Have you tried looking at the automation debug trace information to see where it is failing?

Also try removing the from: 'Off' since this isn’t needed and perhaps the TV was ‘unavailable’ before turning on rather than ‘off’.

I have never heard of that before. Where can I find the information?

I removed that piece but unfortunately the kids are already in the bed so I will have to try this tomorrow. Don’t want to scare a child with a tv that just mysteriously turns itself on and off. Haha

Well, you know, that’s a good question. I couldn’t find anything in the docs about it but it was in the release notes for the latest release found here:

If that doesn’t get you the info you need come back and let me know.

Still didn’t work. I have updated my Home Assistant to the latest version and will try to debug the automation this evening when it activates.

Read the doc and realized that I was on v. 2021.3.4 so I updated to v. 2021.5 today and will try and debug this evening after it is scheduled to trigger. I will keep you posted on what the problem is. Thanks again.

1 Like

So tracing the automation showed me the flawed area and I was able to write the automation like this

- id: '1619990750279'
  alias: Darren's TV
  trigger:
  - platform: device
    device_id: b8e4cf3030321b083ddc1468afbdcba4
    domain: media_player
    entity_id: media_player.darren_s_tv
    type: turned_on
  condition:
  - condition: time
    after: '20:15:00'
    before: '10:00:00'
    weekday:
    - mon
    - tue
    - wed
    - thu
    - fri
    - sat
    - sun
  action:
  - service: notify.mobile_app_jacobs_iphone
    data:
      message: Darren's TV is on
  - service: media_player.turn_off
    target:
      device_id: b8e4cf3030321b083ddc1468afbdcba4

The problem turned out to be when the automation got to the weekend portion of the time condition, it would prove false and not trigger since it was a weekday. I just decided to use the same time limit for all days of the week to eliminate that section and it worked. Thanks for telling me about this service in the new release. I will definitely be using this from now on.

1 Like

You could still use the two different conditions by using the “choose:” function in the actions if you really need it.