Automation with multiple triggers?

I have a simple automation that turns on the back lights on the tv when the tv is turned on after sunset (see below). the issue i am having is that if you turn on the TV before sunset, then the back lights don’t come one. i am pretty sure i can manage this with another automation that turns them on after the sun sets if the TV is on, but was wondering if there is a way to manage it within a single automation?

alias: ROOM - Living Room - TV back lights sync with TV power
description: ''
trigger:
  - platform: state
    entity_id:
      - media_player.big_tv
condition:
  - condition: state
    entity_id: sun.sun
    state: below_horizon
action:
  - service: light.turn_{{trigger.to_state.state}}
    data: {}
    target:
      entity_id: light.big_tv_lights
mode: single

I don’t really see a good way of doing it since you want two different events really. the first is anytime someone turns it on when the sun is down, you turn on the lights. The second is if it’s on already (could have been all day) and the sun sets then you want that to turn on.

I would just make a second automation with a trigger of sunset and condition of it being on.

You can add a sunset trigger. And also add a condition that the TV is on. So it would always try to trigger when the TV is on and at sunset, but it would have to meet both conditions that the sun is below the horizon and the TV is on. Make sense?

… Although it looks like you are trying to also turn the lights OFF when the TV turns off. I would create a separate automation for that piece. And you’re going to have to get rid of your {{trigger.to_state.state}} if you’re adding a sunset trigger.

Although I am sure there are more elegant ways of doing it, you could for example set the automation as follows:

Trigger 1 = Media player goes from off to on
Trigger 2 = Media player goes from on to off
Trigger 3 = Sun below horizon

Then in action use choose function:

Choice 1 = Trigger 1 - condition sun below - turn on lights
Choice 2 = Trigger 2 - turn off lights (you could add a condition of them being on but probably pointless)
Choice 3 = Trigger 3 - condition media player = on - turn on lights

As I am on a mobile device I have not attempted yaml but hopefully you get the idea.

2 Likes

i built it using the visual editor, but here is the automation. i will test it for a bit and let you all know the result. thanks for all the help!

alias: ROOM - Living Room - TV and back lights sync
description: ''
trigger:
  - platform: state
    entity_id:
      - media_player.big_tv
    id: tv_off
    from: 'on'
    to: 'off'
  - platform: state
    entity_id:
      - media_player.big_tv
    id: tv_on
    from: 'off'
    to: 'on'
  - platform: state
    entity_id:
      - sun.sun
    id: tv_on_sunset
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: tv_off
        sequence:
          - type: turn_off
            device_id: 76f3e96815323426161938e75e535fc8
            entity_id: light.big_tv_lights
            domain: light
      - conditions:
          - condition: trigger
            id: tv_on
          - condition: state
            entity_id: sun.sun
            state: below_horizon
        sequence:
          - type: turn_on
            device_id: 76f3e96815323426161938e75e535fc8
            entity_id: light.big_tv_lights
            domain: light
      - conditions:
          - condition: trigger
            id: tv_on_sunset
          - condition: device
            device_id: 5f3f155a7995b74b6a36ec9555cfc217
            domain: media_player
            entity_id: media_player.big_tv
            type: is_on
        sequence:
          - type: turn_on
            device_id: 76f3e96815323426161938e75e535fc8
            entity_id: light.big_tv_lights
            domain: light
    default:
      - choose: []
        default: []
mode: single

Looks good to me, it may however be beneficial to add the below_horizon to the initial sun.sun trigger.

1 Like

good call… Thanks!

1 Like