Meeting aware music

So, I’m a nerd, most of us are, I’m also a nerd who works from home. So I was trying to find a way to play music throughout the day on my Sonos, but to pause it for when I need to call into a meeting, on speakerphone. Last time I did that, my boss thought he heard a UFO landing, over the phone.

Everyone at my office communicates via Microsoft Teams (which is crap in my opinion, being a linux guy). But nonetheless, that’s the evil I’ve gotta work with. So, here’s what I did.

Via Outlook, I published my work’s calendar, via email, to my personal gmail account. In the email I received, it has a link that said “Having trouble viewing the calendar? Try adding an Internet calendar and providing this url”.

I then added this link to my google calendar (settings → add calendar → from url)

Via HA I setup the google calendar component, and added the newly created calendar, with the following configuration:

- cal_id: [email protected]
  entities:
  - device_id: xxxxxxxxxx
    ignore_availability: false
    name: Xxxxxxxxxx
    track: true 

After a restart, I had a new calendar.xxxxxx which would turn on during a meeting, and off afterwards. So I used that as a trigger for the following 2 automations:

- id: Meeting Aware Telework Music - On
  alias: Meeting Aware Telework Music - On
  trigger:
    platform: state
    entity_id: calendar.xxxxxxx
    to: 'on'
  condition:
    - condition: and
      conditions:
        - condition: time
          after: '08:59:00'
          before: '17:00:00'
          weekday:
            - mon
            - tue
            - wed
            - thu
            - fri
        - condition: state
          entity_id: binary_sensor.workday_sensor
          state: 'on'
        - condition: state
          entity_id: input_boolean.telework
          state: 'on'
        - condition: state
          entity_id: input_boolean.vacation
          state: 'off'
        - condition: state
          entity_id: input_boolean.company
          state: 'off'
        - condition: state
          entity_id: group.presence
          state: 'home'
  action:
    - service: script.sonos_pause
      data:
        sonos_entity: "media_player.living_room"

- id: Meeting Aware Telework Music - Off
  alias: Meeting Aware Telework Music - Off
  trigger:
    platform: state
    entity_id: calendar.xxxxxxx
    to: 'off'
  condition:
    - condition: and
      conditions:
        - condition: time
          after: '08:59:00'
          before: '17:00:00'
          weekday:
            - mon
            - tue
            - wed
            - thu
            - fri
        - condition: state
          entity_id: binary_sensor.workday_sensor
          state: 'on'
        - condition: state
          entity_id: input_boolean.telework
          state: 'on'
        - condition: state
          entity_id: input_boolean.vacation
          state: 'off'
        - condition: state
          entity_id: input_boolean.company
          state: 'off'
        - condition: state
          entity_id: group.presence
          state: 'home'
  action:
    - service: script.sonos_resume
      data:
        sonos_entity: "media_player.living_room"

The Sonos pause/resume scripts are as follows:

  sonos_pause:
    alias: "Sonos Pause"
    sequence:
      - service: media_player.media_pause
        data_template:
          entity_id: "{{ sonos_entity }}"

  sonos_resume:
    alias: "Sonos Resume"
    sequence:
      - service: media_player.media_play
        data_template:
          entity_id: "{{ sonos_entity }}"

Conclusion: The music pauses before a scheduled meeting, and resumes afterwards. It seems to work great! There is a slight delay, by maybe 30sec, but it’s not bad, besides meetings usually don’t start on-the-dot anyways.

This setup doesn’t currently support unscheduled calls, via Teams, only pre-scheduled ones. In the future I’d like to track the Teams availability status (busy, free, in a call, etc) instead, for a more accurate trigger. Once Microsoft decides to open up the API for developers.

Todo: Currently it pauses/resumes for every calendar event, Teams meeting or not, even reminder meetings I set just for myself. So I’ll probably implement a template that only fires when the meeting location is set to “Microsoft Teams Meeting”, this would prevent false-positives.

Enjoy!

3 Likes