Happy Bubbles / Phone Calls / Pausing Media / Fun

I work from home a lot and like to listen to music, im usally fumbling around trying to get my bluetooth out when im getting calls and its hard to make it to pause the music also. I made this to solve that problem. Basically when my phone rings I use tasker to turn an input boolean on. When that boolean gets switched on there is a couple automations that look to see what room I am in based on happy bubbles room presence, then looks to see if i am watching tv or listening to music in that room. It will pause the music or pause the tv for that room, and as soon as I hang up it will hit play. This has been working solid, Im sure the code could be layed out a better way, but im learnin. I thought I would share in case someone was looking to do something similar.

Ill post the config for one room, the light flash argument never seems to work for me so I just did a couple 2 second delays.

First I setup tasker to send an http post command to HA and turn on input_boolean.phone and then again to turn it off once I hang up.

Then I created one automation that triggers when i get a call and it looks to see where I am and if the tv is on. If it is on it will pause that and then hit play after the call. along with flashing some lights.
The second automation for each room looks to see where I am, if the tv is not on in that room it looks to see if the music is playing in there, if so it will pause and then play the music once the call is over.

input_boolean.phone:
  name: Phone Call

automations:

- alias: Phone Call Living Room Sonos
  trigger:
    - platform: state
      entity_id: input_boolean.phone
      to: 'on'
  condition:
    - condition: time
      before: '23:00:00'
      after: '08:30:00'
    - condition: state
      entity_id: sensor.dustin
      state: 'Living Room'
    - condition: state
      entity_id: remote.living_room_remote
      state: 'off'
  action:
    - service_template: >
        {% if states.media_player.living_room.state == 'playing' %}
          script.turn_on
        {% endif %}
      entity_id: script.phonecall_lr
    - delay: '00:00:02'
    - service: light.turn_on
      data:
        entity_id: light.strips
        brightness: 255
        color_name: 'green'
    - delay: '00:00:02'
    - service: light.turn_on
      data:
        entity_id: light.strips
        brightness: 255
        color_name: 'white'
    - delay: '00:00:02'
    - service: light.turn_on
      data:
        entity_id: light.strips
        brightness: 255
        color_name: 'green'
    - delay: '00:00:02'
    - service: light.turn_on
      data:
        entity_id: light.strips
        brightness: 255
        color_name: 'white'
    - delay: '00:00:02'
    - service: light.turn_on
      data:
        entity_id: light.strips
        brightness: 255
        color_name: 'blue'


- alias: Phone Call Living Room Watching TV
  trigger:
    - platform: state
      entity_id: input_boolean.phone
      to: 'on'
  condition:
    - condition: time
      before: '00:00:00'
      after: '08:30:00'
    - condition: state
      entity_id: sensor.dustin
      state: 'Living Room'
    - condition: state
      entity_id: remote.living_room_remote
      state: 'on'
  action:
    - service: script.turn_on
      entity_id: script.phonecall_livingroom_watchingtv



Scripts:

phonecall_lr:
  sequence:
    - service: media_player.sonos_snapshot
      entity_id: media_player.living_room
    - service: media_player.media_play_pause
      entity_id: media_player.living_room
    - delay: '00:00:05'
    - wait_template: "{{ is_state('input_boolean.phone', 'off') }}"
    - service: media_player.sonos_restore
      entity_id: media_player.living_room

phonecall_livingroom_watchingtv:
  sequence:
    - service: remote.send_command
      data_template:
        device: '49106839'
        command: 'Pause'
        entity_id: remote.living_room_remote
    - delay: '00:00:02'
    - service: light.turn_on
      data:
        entity_id: light.strips
        brightness: 255
        color_name: 'green'
    - delay: '00:00:02'
    - service: light.turn_on
      data:
        entity_id: light.strips
        brightness: 255
        color_name: 'white'
    - delay: '00:00:02'
    - service: light.turn_on
      data:
        entity_id: light.strips
        brightness: 255
        color_name: 'green'
    - delay: '00:00:02'
    - service: light.turn_on
      data:
        entity_id: light.strips
        brightness: 255
        color_name: 'white'
    - delay: '00:00:02'
    - service: light.turn_on
      data:
        entity_id: light.strips
        brightness: 255
        color_name: 'blue'
    - wait_template: "{{ is_state('input_boolean.phone', 'off') }}"
    - service: remote.send_command
      data_template:
        device: '49106839'
        command: 'Play'
        entity_id: remote.living_room_remote
3 Likes