Simplify code

Hello all,

I made a peace of code which works for me however in my opinion it is to much code. Can someone help me to simplify the code?

- id: '1498996958911'
  initial_state: false
  alias: Volume set to 1.0
  trigger:
  - platform: state
    entity_id: sensor.aeotec_zw100_multisensor_6_burglar
    from: '0'
    to: '8'
  action:
  - service: media_player.volume_set
    data_template:
      entity_id: media_player.woonkamer
      volume_level: 1.0
- id: '1498996958911'
  initial_state: false
  alias: Dog Bark
  trigger:
  - platform: state
    entity_id: sensor.aeotec_zw100_multisensor_6_burglar
    from: '0'
    to: '8'
  action:
  - service: media_player.play_media
    data:
      entity_id: media_player.woonkamer
      media_content_id: https://myurl.com/local/dog.mp3
      media_content_type: MUSIC
- id: '1498996958911'
  initial_state: false
  alias: Volume set to 0.2
  trigger:
  - platform: state
    entity_id: sensor.aeotec_zw100_multisensor_6_burglar
    from: '8'
    to: '0'
  action:
  - service: media_player.volume_set
    data_template:
      entity_id: media_player.woonkamer
      volume_level: 0.2

Thanks

- id: 'simpler'
  initial_state: false
  alias: Simpler
  trigger:
    platform: state
    entity_id: sensor.aeotec_zw100_multisensor_6_burglar
    to: '8'
  action:
    - service: media_player.volume_set
      data:
        entity_id: media_player.woonkamer
        volume_level: 1.0
    - service: media_player.play_media
      data:
        entity_id: media_player.woonkamer
        media_content_id: https://my.url.com:8123/local/dog.mp3
        media_content_type: MUSIC
    - delay: 00:00:20
    - service: media_player.volume_set
      data:
        entity_id: media_player.woonkamer
        volume_level: 0.2
1 Like

It works, thank you very much for teaching me this.

1 Like