#Template trigger

1 messages · Page 1 of 1 (latest)

quiet terrace
#

As with everything I do I am trying to do something I think is complicated. In my project, I have custom template sensors for satellite devices. It looks something like this:

- sensor:
  - name: ViewAssist-kitchen
    state: ""
    attributes:
      type: view_audio
      mode: "normal"
      mic_device: "sensor.viewassist_kitchen_stt"
      mediaplayer_device: "media_player.viewassist_kitchen"
      musicplayer_device: "media_player.viewassist_kitchentsv"      
      display_device: "sensor.viewassist_kitchen_browser_path"
      browser_id: "ViewAssist-kitchen" 

I want to trigger an automation if this template sensor's mediaplayer_device entity (ie media_player.viewassist_kitchen) attribute is_volume_muted changes (can be either true or false).

I am hoping that this can be done with a template trigger. I have this template that will return the value but I do not know how to write the trigger:

state_attr((state_attr('sensor.viewassist_masterbedroom', 'mediaplayer_device')), 'is_volume_muted'

Any help is most appreciated.

quiet terrace
#

At worse, can I set a normal state change trigger for sensor.viewassist_masterbedroom and then use a condition to check if things are changing with the atrributes' attribute? Wow this is tough.

knotty valley
#

A template trigger only fires when the value that the template renders changes from false to true... there is currently no way to make a template trigger on the change from true to false as well. You would need to set up two triggers... one for each direction of change:

- id: muted_true
  trigger: template
  value_template: |
    {% set ent = state_attr('sensor.viewassist_masterbedroom', 'mediaplayer_device') %}
    {{ state_attr(ent, 'is_volume_muted') | bool }}
- id: muted_false
  trigger: template
  value_template: |
    {% set ent = state_attr('sensor.viewassist_masterbedroom', 'mediaplayer_device') %}
    {{ not state_attr(ent, 'is_volume_muted') | bool }}
At worse, can I set a normal state change trigger for sensor.viewassist_masterbedroom  and then use a condition to check if things are changing with the atributes' attribute?

Assuming sensor.viewassist_masterbedroom is analogous to the Kitchen version shown above... You can, but it will never trigger because the state and all the attributes are static; a State trigger requires a change event.

quiet terrace
#

I think your two examples above will be something I can work with. I will try it out tomorrow. Thanks for the continued support!