Turn off or on an automation depending on an appliance

i have this automation that i want to have running when the tv is not in use

I have set this up up and would like to know if its correct.

lias: if tv on. no light autoamtion
description: ""
triggers:
  - trigger: state
    entity_id:
      - media_player.living_room_tv
    to: playing
conditions: []
actions:
  - action: automation.turn_off
    target:
      entity_id: automation.new_automation
    data:
      stop_actions: true
  - if:
      - condition: state
        entity_id: media_player.living_room_tv_2
        state: "off"
        for:
          hours: 0
          minutes: 10
          seconds: 0
    then:
      - action: automation.turn_on
        target:
          entity_id: automation.new_automation
        data: {}
mode: single

What specifically is your goal for this?

The practice of disabling and enabling automations in other automations isn’t generally considered an optimal design. It is better to add a condition so that it only executes when you want it to.

When you programmatically enable/disable automations rather than controlling them with their own conditional logic, you loses the ability to definitively and reliably disable them. Sometimes you need to manually disable an automation because it isn’t working properly. If you have other automations that can enable it outside your control, you can’t be certain it will stay off.

hey mate.

ok so the idea behind this is:

the light automation have is, if motion is detected after 9:30pm then 2 lights will turn on (like a night light for navigating the kitchen area) as it it usually dark. However, if my wife is watching the tv with the lights off inside this time frame, i don’t want the me walking past the sensor or her moving off the couch etc to activate the lights as per the original automation. its a bit niche

below is the light automation

alias: night light automation - kitchen dining living
description: lamps turn on after 9:30pm
use_blueprint:
  path: Blackshome/sensor-light.yaml
  input:
    motion_trigger:
      - binary_sensor.hue_motion_sensor_5_motion
    light_switch:
      entity_id:
        - light.signify_netherlands_b_v_lct010_light
        - light.lounge_room_floor_lamp_light
    time_delay: 2
    include_light_control:
      - use_brightness
    light_brightness: 30
    include_time: time_enabled
    after_time: "21:30:00"
    before_time: "04:00:00"

ah, you are trying to do this with a blueprint. that’s why you aren’t doing a condition.

one way to do this is to create a template binary sensor helper.

have the sensor template be

{{ states('binary_sensor.hue_motion_sensor_5_motion') and states('media_player.living_room_tv') == 'playing' }}

use this for your motion trigger in your blueprint

would i be better creating a separate automation with specific conditions?

better off? not sure how to weigh that.

doing the sensor template that i said above is super easy…

sorry mate, i am not very good with making templates etc.

I have done this. so will the motion sensor fire when the tv is not playing anything?

i only want the lights to come on if the tv is not on

Go to helpers in the UI, choose create helper. Pick template . Pick binary sensor. Paste that template in.

sorry mate, i have only just got around to doing this. i will test tonight and see how it goes.

thank you!

so i have tried this and it doesn’t trigger the lights to come on when the tv is not playing media. so i changed it to the below and it “works” but its always detected. so it wont turn the lights on when i walk past? its very hard to descirbe i guess.

alias: night light automation - kitchen dining living
description: lamps turn on after 9:30pm
use_blueprint:
  path: Blackshome/sensor-light.yaml
  input:
    motion_trigger:
      - binary_sensor.motion_sensor_based_on_tv_state
    light_switch:
      entity_id:
        - light.signify_netherlands_b_v_lct010_light
        - light.lounge_room_floor_lamp_light
    time_delay: 2
    include_light_control:
      - use_brightness
    light_brightness: 30
    include_time: time_enabled
    after_time: "20:00:00"
    before_time: "05:00:00"
    motion_bypass_lights_stop: []

sorry, let me make sure i understand what you want…

if the tv is playing, you essentially want the motion detectors to be disabled. so that it doesn’t turn on or off. but if the tv is not playing, you want the motion detectors to operate normally. is that right? anything else?

if that’s right, then i apologize i misunderstood the original request. i’d still use the helper sensor, but i’d use this template. i had the playing state exactly inverted:

{{ states('binary_sensor.hue_motion_sensor_5_motion') and states('media_player.living_room_tv') != 'playing' }}