- alias: Play Webradio
  id: "1739182562809"
  description: ""
  triggers:
    - trigger: state
      entity_id:
        - input_select.webradio_streams
        - input_select.media_player
  conditions: []
  actions:
    - action: script.webradio
      metadata: {}
      data:
        action: play
  mode: single
- alias: Auto pause media players
  id: "1742063263118"
  description: When another player plays in the same room
  triggers:
    - trigger: state
      entity_id:
        - media_player.spotify_player
      to: playing
      id: spotify
    - trigger: state
      entity_id:
        - media_player.vlc_games_room_2
      to: playing
      id: vlc_games
    - trigger: state
      entity_id:
        - media_player.vlc_lucy_s_room_2
      to: playing
      id: vlc_lucy
  conditions: []
  actions:
    - choose:
        - conditions:
            - condition: and
              conditions:
                - condition: trigger
                  id:
                    - spotify
                - condition: template
                  value_template:
                    "{{state_attr('media_player.spotify_player','source')
                    == 'Spotify (Games Room)'}}"
          sequence:
            - action: media_player.media_pause
              metadata: {}
              data: {}
              target:
                entity_id: media_player.vlc_games_room_2
          alias: Pause Lucy VLC on  Spotify - Lucy-PC playing
        - conditions:
            - condition: and
              conditions:
                - condition: trigger
                  id:
                    - spotify
                - condition: template
                  value_template:
                    "{{state_attr('media_player.spotify_player','source')
                    == 'LUCY-PC'}}"
          sequence:
            - action: media_player.media_pause
              metadata: {}
              data: {}
              target:
                entity_id: media_player.vlc_lucy_s_room_2
          alias: Pause Games VLC on  Spotify - Games Room playing
        - conditions:
            - condition: and
              conditions:
                - condition: trigger
                  id:
                    - vlc_lucy
                - condition: template
                  value_template:
                    "{{state_attr('media_player.spotify_player','source')
                    == 'LUCY-PC'}}"
          sequence:
            - action: media_player.media_pause
              metadata: {}
              data: {}
              target:
                entity_id: media_player.spotify_player
          alias: Pause Spotify on Lucy VLC playing
        - conditions:
            - condition: and
              conditions:
                - condition: trigger
                  id:
                    - vlc_games
                - condition: template
                  value_template:
                    "{{state_attr('media_player.spotify_player','source')
                    == 'Spotify (Games Room)'}}"
          sequence:
            - action: media_player.media_pause
              metadata: {}
              data: {}
              target:
                entity_id: media_player.spotify_player
          alias: Pause Spotify on Games VLC playing
  mode: single
- alias: fuchscast_progress
  id: "1733968439364"
  description: ""
  triggers:
    - trigger: state
      entity_id:
        - media_player.fuchscast
  conditions: []
  actions:
    - variables:
        position: 0
    - action: variable.update_sensor
      metadata: {}
      data:
        replace_attributes: false
        value: "{{state_attr('media_player.fuchscast', 'media_position')}}"
      target:
        entity_id: sensor.fuchscast_position
    - repeat:
        sequence:
          - action: variable.update_sensor
            metadata: {}
            data:
              replace_attributes: false
              value: "{{states('sensor.fuchscast_position')|float + 1}}"
            target:
              entity_id: sensor.fuchscast_position
          - delay:
              hours: 0
              minutes: 0
              seconds: 1
              milliseconds: 0
        while:
          - condition: state
            entity_id: media_player.fuchscast
            state: playing
    - if:
        - condition: template
          value_template:
            "{{ trigger.from_state.state != 'paused' and trigger.from_state.state
            != 'playing'}}"
      then:
        - action: variable.update_sensor
          metadata: {}
          data:
            replace_attributes: false
            value: "0"
          target:
            entity_id: sensor.fuchscast_position
      enabled: false
  mode: single
- alias: Stream2TV
  id: "1729856794459"
  description: ""
  triggers:
    - trigger: template
      value_template: "{{states('binary_sensor.stream')}}"
  conditions: []
  actions:
    - repeat:
        sequence:
          - data:
              media_player: media_player.fuchscast
              format: hls
            action: camera.play_stream
            target:
              entity_id: camera.meow_cam_sd_stream
          - delay:
              hours: 0
              minutes: 1
              seconds: 0
              milliseconds: 0
          - data:
              media_player: media_player.fuchscast
              format: hls
            action: camera.play_stream
            target:
              entity_id: camera.meow_cam_2_sd_stream
          - delay:
              hours: 0
              minutes: 1
              seconds: 0
              milliseconds: 0
        while:
          - condition: template
            value_template: "{{is_state('binary_sensor.stream','on')}}"
  mode: single
- alias: Change Volume
  id: "1727801591913"
  description: ""
  trigger:
    - platform: state
      entity_id:
        - input_number.volumeslider
        - sensor.current_volume_absolute
      from:
      to:
      for:
        hours: 0
        minutes: 0
        seconds: 1
      enabled: true
  condition:
    - condition: template
      value_template:
        "\n  {{not is_state('sensor.current_volume_absolute','false')
        and states('sensor.current_volume_absolute')|int != states('input_number.volumeslider')|int}}\n"
      enabled: true
  action:
    - action: script.notify
      metadata: {}
      data:
        duration:
          hours: 0
          minutes: 0
          seconds: 5
        silent: false
        content: "trigger: {{trigger.entity_id}} \n"
      enabled: false
    - choose:
        - conditions:
            - condition: template
              value_template: "{{trigger.entity_id=='input_number.volumeslider'}}"
          sequence:
            - action: mqtt.publish
              metadata: {}
              data:
                evaluate_payload: false
                topic: homeassistant/button/LUCY-PC/MediaVolumeSet/action
                payload: "{{states('input_number.volumeslider')|int}}"
    - choose:
        - conditions:
            - condition: template
              value_template: "{{trigger.entity_id=='sensor.current_volume_absolute'}}"
          sequence:
            - action: input_number.set_value
              metadata: {}
              data:
                value: "{{states('sensor.current_volume_absolute')|int}}"
              target:
                entity_id: input_number.volumeslider
    - delay:
        hours: 0
        minutes: 0
        seconds: 1
        milliseconds: 0
  mode: queued
  max: 2
