I need help with a Home Assistant blueprint I created for adjusting lights while watching Plex. It works well, but I had to detach it for one TV to add a helper toggle that acts as a condition for the automation.
I want to integrate this toggle functionality into the blueprint itself, making it optional. If a user provides a toggle entity, the automation should only run when the toggle is on. If no toggle is provided, the automation should run normally, syncing the lights with Plex regardless.
I was going to say something clever like check line 58, but you have not provided any code or what you have tried so far.
Is it possible, well most things are possible. Not all things, but most things.
Yes, it is absolutely trivial. Any blueprint selector which has a default value is considered optional, even if that default value is blank. So simply add a default: to your (presumably) entity: selector and you’re done.
Well, almost. This will not work as-is in a state condition as those won’t like if entity_id: none. It will work if you also add multiple: true and use default: [], or rather than use a state condition you write your own template condition.
Hi, my apologies.What a massive oversight haha. Here’s my blueprint, with the conditional, which doesn’t make any sense at the moment. Thank you for taking the time to reply to my post. I massively appreciate it.
blueprint:
name: Plex Lights
description: Make your lights respond to what you watch.
domain: automation
input:
light_target:
name: Light
description: Select the lights you'd like this automation to control.
selector:
entity:
multiple: true
filter:
domain: light
# wait_time:
# name: Wait
# description: Minutes to wait after sunset.
# selector:
# number:
# mode: box
# min: 0
# max: 360
# unit_of_measurement: minutes
# default: 0
plex_player:
name: Plex Player
description: Select the Plex device that you're going to be watching.
selector:
entity:
filter:
domain: media_player
should_activate:
name: Plex Player
description: Select the Plex device that you're going to be watching.
selector:
entity:
filter:
domain: media_player
bedtime:
name: Time that lights won't activate after
description: If you stop watching Plex after this time, the lights will remain off when you've finished.
selector:
time:
triggers:
- trigger: state
entity_id: !input plex_player
to: playing
id: Playing
- trigger: state
entity_id: !input plex_player
to: paused
id: Paused
- trigger: state
entity_id: !input plex_player
to: unavailable
id: Stopped
- trigger: state
entity_id: !input plex_player
to: idle
id: Stopped
conditions:
- condition: sun
after: sunset
enabled: true
- condition: state
state: "on"
entity_id: !input should_activate
actions:
- choose:
- conditions:
- condition: trigger
id:
- Playing
sequence:
- action: light.turn_off
metadata: {}
data: {}
target:
entity_id: !input light_target
# - delay:
# hours: 0
# minutes: 0
# seconds: 1
# milliseconds: 0
# - action: light.turn_on
# metadata: {}
# data:
# brightness_pct: 0
# kelvin: 2500
# target:
# entity_id: !input light_target
- conditions:
- condition: trigger
id:
- Paused
sequence:
- action: light.turn_on
metadata: {}
data:
brightness_pct: 15
kelvin: 2500
transition: 1
target:
entity_id: !input light_target
- conditions:
- condition: and
conditions:
- condition: trigger
id:
- Stopped
- condition: time
before: !input bedtime
sequence:
- action: light.turn_on
metadata: {}
data:
# kelvin: 4000
# brightness_pct: 100
transition: 1
target:
entity_id: !input light_target
mode: single
The should_activate was just copied and pasted, but I was trying to replace that with something that would be optional and then I can put the entity toggle as the condition which is easy. It’s just the optional bit I’m struggling with.