Hi,
I was wondering if there is a more DRY way to apply the same condition (or trigger) to multople automations, rather than copy and pasting the same condition into all automations.
- alias: Media player paused
trigger:
- platform: state
entity_id: media_player.tv
to: 'paused'
condition:
condition: template
value_template: "{{states.media_player.tv.attributes.media_content_type != 'music' }}"
action:
service: light.turn_on
entity_id: light.living_room_table_lamp
- alias: Media player idle
trigger:
- platform: state
entity_id: media_player.tv
to: 'idle'
condition:
condition: template
value_template: "{{states.media_player.tv.attributes.media_content_type != 'music' }}"
action:
service: light.turn_on
entity_id: light.living_room_table_lamp
- alias: Media player playing
trigger:
platform: state
# entity_id: media_player.plex_web_chrome
entity_id: media_player.tv
to: 'playing'
for:
seconds: 5
condition:
condition: template
value_template: "{{states.media_player.tv.attributes.media_content_type != 'music' }}"
action:
- service: media_player.turn_off
entity_id: media_player.soundtouch
- service: light.turn_off
entity_id: light.living_room_table_lamp
I think this could be achieved with a new concept. The idea is derived from the way unit tests can be grouped in Javascript.
Example:
describe('it works as expected', () => {
it(...);
it(...);
});
These describe
blocks group similar unit tests together. They can be nested as well.
I was wondering if a similar syntax can be achieved for automations. For example:
- block:
alias: "Blcok with condition that is imposed on all automations within the block'
condition:
condition: template
value_template: "{{states.media_player.tv.attributes.media_content_type != 'music' }}"
entities:
- alias: Media player idle
trigger:
- platform: state
entity_id: media_player.tv
to: 'idle'
action:
service: light.turn_on
entity_id: light.living_room_table_lamp
Is there a workaround or better way to do this? This would help keep the configuration DRY. Let me know what you think.