Unrelaiable Automation

Hi,
I’ve created an auotmation (yaml below) that triggers very unreliably. The idea is that when the TV is on for more that 30s after 19:45 in the evening the automation will trigger a scene, but works only half of the times. The scene work correctly if manually triggered and checking the status of the media_player entity for the TV is indeed “on” even when the automation doesn’t trigger.
Any idea on what could be messing with it?

alias: Night TV
description: ""
triggers:
  - trigger: state
    entity_id:
      - media_player.tv_soggiorno_2
    from:
      - "off"
    for:
      hours: 0
      minutes: 0
      seconds: 30
    to:
      - "on"
conditions:
  - condition: time
    after: "19:45:00"
    before: "01:00:00"
    weekday:
      - sun
      - sat
      - fri
      - thu
      - wed
      - tue
      - mon
actions:
  - action: scene.turn_on
    metadata: {}
    target:
      entity_id: scene.movie_night
    data:
      transition: 5
mode: single

Are you sure about the control of the lights from HA outside of the yaml? Assuming the scene is turning on lights? What technology are the lights or whatever is being controlled with the scene is being used, eg like zwaver, wifi bulbs, etc?

If manually triggered just from HA, and not the automation, does it work 100% of the time?

Yes, the scene turn on some lights, off others and close the shutters. All are controlled by my custom integration (they are controlled by a BTicino server). the scene works every time if I trigger it manually, also the same lights/shutters work with the same integration without any issue every time so I exclude that the culprit is the MyHome integration

Check this explainer for why it probably does not work the way you expect and how to fix it:

Make sure to also check the bit about; “My automation does not always work”

Thanks for the link, my issue wasn’t correlated with what was in it but it helped me think about my automation and I solved the problem. The fact is that when my tv is off not always HA sees it as “off” so settings up the trigger from off to on not always worked. Using from any solved. Thanks a lot again.

This still wont work if you turn your TV on at 19:44

And that’s exactly what I want it to do.

You need to trigger when the TV turns on and add another trigger for time. with a condition that checks if the tv is on.

Probably easiest to do as 2 automations.