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' }}

Hey mate

yeah i only want the lights to turn on if the tv is not playing. (and after 9:00pm until 5:00am)

i will report back once i have implemented the bove you you have supllied. thank you!

Hey mate, I still cant seem to get this to work based on the template sensor.
looking at the log, it is not changing wheter the tv in on or not.

I have done this automation which seems to work on paper, but again, in practice the automation isnt firing when required.

alias: test boi night light
description: ""
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.hue_motion_sensor_5_motion
    to: "on"
conditions:
  - condition: state
    entity_id: media_player.sony_kd_75x9400e
    state: "off"
  - condition: time
    after: "18:00:00"
    weekday:
      - sat
      - fri
      - thu
      - wed
      - tue
      - mon
      - sun
actions:
  - type: turn_on
    device_id: 06db584e6a31fe5ef2d21de77f2a5c3f
    entity_id: 24b3d6ea6deb66231f15153b64dc0619
    domain: light
    brightness_pct: 20
  - delay:
      hours: 0
      minutes: 5
      seconds: 0
      milliseconds: 0
  - type: turn_off
    device_id: 06db584e6a31fe5ef2d21de77f2a5c3f
    entity_id: 24b3d6ea6deb66231f15153b64dc0619
    domain: light
mode: single

You can test that template in Developer tools → TEMPLATE

got to the bottom of it. the fucking motion sensor was turned off. i am an absolute spud. all is working as intended.

Even if I don’t know what it means, I will not argue with you!

Anyways, good you got it solved.

Please mark the post with the answer that helped you as the solution so anyone who’s searching for this can benefit from it.
You do that by selecting the three dots under the post:

image

Then select the check box:

image

Also, by doing so this prevents that someone else steps in for trying to help.