#entity_id templating

1 messages · Page 1 of 1 (latest)

unborn hazel
#

alias: Dashboard Cast
sequence:

  • if:
    • condition: or
      conditions:
      • condition: not
        conditions:
        • condition: device
          device_id: "{{ device }}"
          domain: media_player
          entity_id: "{{ entity }}"
          type: is_playing
      • condition: and
        conditions:
        • condition: device
          device_id: "{{ device }}"
          domain: media_player
          entity_id: "{{ entity }}"
          type: is_playing
        • condition: state
          entity_id: "{{ entity }}"
          attribute: app_name
          state: Home Assistant Lovelace
          then:
    • service: media_player.turn_off
      data: {}
      target:
      entity_id: "{{ entity }}"
    • service: media_player.volume_mute
      data:
      is_volume_muted: true
      target:
      entity_id: "{{ entity }}"
    • service: media_player.volume_set
      data:
      volume_level: 0.99
      target:
      entity_id: "{{ entity }}"
    • service: cast.show_lovelace_view
      data:
      entity_id: "{{ entity }}"
      dashboard_path: lovelace
      view_path: "{{ view }}"
    • delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 500
    • service: media_player.volume_mute
      data:
      is_volume_muted: false
      target:
      entity_id: "{{ entity }}"
      mode: restart
glossy leafBOT
#

Please use a code share site to share code or logs, for example:

Please don't use Pastebin, since it can randomly add spaces to the main view. Please also don't share text as images since it makes it harder for people to help you. Remember that others may have colour blindness, impaired vision, etc.

buoyant stone
#

I don't think you can use templates with devices like that

#

use entities instead

#

this kind of thing won't work:

              - condition: device
                device_id: "{{ device }}"
                domain: media_player
                entity_id: "{{ entity }}"
                type: is_playing
unborn hazel
#

everything works with the exception of the "{{ entity }}" in the condition. If i remove those and use the actual entity_id everything works fine

buoyant stone
#

what you wanted was a template condition

unborn hazel
#

I'm very new to hassio and yaml so I am learning the capabilities and methods as I go. Thanks for the help

buoyant stone
#

if you're doing more advanced stuff like this, I recommend staying away from device triggers, conditions, and actions.

#

they are unnecessary and will just get you in trouble

unborn hazel
#

Use entities over devices??

#

I only used device because it seemed to offer the attribute I was needing

#

media player entity doesn't have a "playing" state that I could figure out

buoyant stone
#

sure it does

#

it's the state

#

but it doesn't matter if it's an attribute

#

it has to come from somewhere, and you're already specifying the entity in that condition

#

device conditions aren't magic

unborn hazel
#

Ok for some reason I felt I was forced to use device rather than entity and now I can't remember why. Maybe that'

#

thats been my whole problme

#

I am still unable to save after switching to entity states

buoyant stone
#

you need to use a template condition

#
              - condition: template
                value_template: "{{ is_state(entity, 'playing') }}"

for instance

#

you could just write that whole complex condition in a single template

unborn hazel
#

I think I just need to learn templating, sounds like I will be using it a lot for more of the programmer type things I will want to do

buoyant stone
#

yes

unborn hazel
#

btw the reason the list comes into play here is that I want to have a list of motion sensors and then when any of those devices change state it will trigger a script which will do different things depending on the device that changed state. The goal is to have a single list I can add/remove entities from without having to alter the actual automations/scripts

#

probably way over complicated for what I actually need it to accomplish, thats just the "right" way to do it in my head

buoyant stone
#

that's not going to be easy

unborn hazel
#

I imagine not, I am already on the dge of if it's worth it or not and with the added complexity, it sounds like not

#

Guess I'll just have 80 different scripts haha

#

Thanks for the help!

buoyant stone
#

the easiest way to do it is write an automation that uses an event trigger for state_changed, which will trigger everytime any entity changes state, then use a condition to filter for the ones you care about, and the event itself will tell you which one caused the trigger

#

you can make a Jinja list in the condition to test against, and you can just have it in that one place

#

it's a bit of a sledgehammer approach, but it's the only way to deal with limitations in what you can trigger on