Problems with automation to turn off lights if tv is off

hi all,

i’ve been racking my brain (or whats left of it) trying to work out where i have gone wrong here… it’s probably something really simple like formatting but I cant see it.

anyway… i have this automation that turns the lights off at 9.30pm if the sun has already set. that works perfectly… but now i’m trying to add a condition of only if the tv is turned off… to often have i been watching a program on tv and the lights go out on me so i want to change that. problem is that when i tried to do it i got hit with all kinds of errors… so… please help…

- id: '1542575515582'
  alias: turn off lounge lamps at 21:30
  hide_entity: true
  trigger:
  - at: '21:30'
    platform: time
  condition:
  - condition: sun
    after: sunset
  - condition: state
    entity_id: media_player.sony_bravia_tv
    state: off
  action:
  - service: switch.turn_off
    entity_id:
    - switch.corner_lamp
    - switch.tall_lamp
    - switch.fan_lamp

it’s ok,

i got it!!! i knew it was something simple… i forgot my quotation marks on my state…

new automation is as follows

- id: '1542575515582'
  alias: turn off lounge lamps at 21:30
  hide_entity: true
  trigger:
  - at: '21:30'
    platform: time
  condition:
  - condition: sun
    after: sunset
  - condition: state
    entity_id: media_player.sony_bravia_tv
    state: "off"
  action:
  - service: switch.turn_off
    entity_id:
    - switch.corner_lamp
    - switch.tall_lamp
    - switch.fan_lamp

Just a thought. Would you want to turn the lights off when 1) it’s 21:30, 2) the sun sets, or 3) when the tv has been off for some amount of time (say 10 minutes), whichever comes last? If so, how about this:

- id: '1542575515582'
  alias: turn off lounge lamps
  hide_entity: true
  trigger:
  - at: '21:30'
    platform: time
  - platform: sun
    event: sunset
  - platform: state
    entity_id: media_player.sony_bravia_tv
    to: 'off'
    for:
      minutes: 10
  condition:
  - condition: time
    after: '21:30'
  - condition: sun
    after: sunset
  - condition: state
    entity_id: media_player.sony_bravia_tv
    state: 'off'
    for:
      minutes: 10
  action:
  - service: switch.turn_off
    entity_id:
    - switch.corner_lamp
    - switch.tall_lamp
    - switch.fan_lamp

Of course I have to wonder, where are you where sunset might happen after 21:30? :slight_smile:

1 Like

i’m in Scotland and during the summer sunset can be around 11pm :slight_smile:

thanks for the options, not what i’m looking for just now but it has come in handy to update another automation i have.

1 Like