Pause SONOS when OBIHAI phone is in use

Just thought I would share a couple of short automations I just created, thanks to the new integration for OBIHAI devices. I wanted to PAUSE the music playing on my office SONOS when the phone was in use. Hope it is useful for someone. If you can think of improvements, please post a reply!

#--------------------------------------------------------------------------------- 
#-- Monitor the Office Phones - If a call is made or answered, pause Sonos
#--------------------------------------------------------------------------------- 
- alias: "Office Phones off hook"
  initial_state: true
  trigger:
    - platform: state
      entity_id: 'sensor.obihai_phone1_port'
      from: "On Hook"
    - platform: state
      entity_id: 'sensor.obihai_phone2_port'
      from: 'On Hook'
  condition:
    - condition: and
      conditions:
        - condition: state
          entity_id: 'media_player.office'
          state: 'playing'
  action:
    - service: sonos.snapshot
      data_template:
        entity_id: media_player.office
    - service: sonos.unjoin
      data_template:
        entity_id: media_player.office
    - service: media_player.media_play_pause
      data_template:
        entity_id: media_player.office
    
- alias: "Office Phones on hook"
  initial_state: true
  trigger:
    - platform: state
      entity_id: 'sensor.obihai_phone1_port'
      to: 'On Hook'
    - platform: state
      entity_id: 'sensor.obihai_phone2_port'
      to: 'On Hook'
  condition:
    - condition: and
      conditions:
      - condition: state
        entity_id: 'sensor.obihai_phone1_port'
        state: 'On Hook'
      - condition: state
        entity_id: 'sensor.obihai_phone2_port'
        state: 'On Hook'
  action:
    - service: sonos.restore
      data_template:
        entity_id: media_player.office


3 Likes

Will this work with all media types, local and streaming services?

Yes, though pausing streaming services acts more like STOP, and when you unpause, it will start the streaming service again with a different song. Hope that makes sense!

I don’t know if it is an improvement but maybe temporarily turning the volume down could work for some. It would avoid issues with pause/stop and groups.

hi Orphan264, i am using the Obitalk sensor,

  • platform: obihai
    host: 192.168.1.X

i get connection errors, when i use it on browser, Admin with default password works fine, Any suggestions ?

error:
[pyobihai] HTTPConnectionPool(host=‘192.168.1.X’, port=80): Max retries exceeded with url: /DI_S_.xml (Caused by ConnectTimeoutError(<urllib3

Make sure you input the correct IP address for the host. Also what device do you have?

Ip address is correct(i did confirm from IVR menu on the device). I am using Obhi202.

ok the Obi202 is definitely supported, can you try setting username and password? even if its default? Id like to get this solved :slight_smile: for me the password was actually displayed in the UI and it was not default even though I did not set it.

Edit: also please paste the full error

I tired with username and password, get the same error. One thing that is different is by HA is on ip 192.168.149.X but my obhi is on 192.168.1.165. when i ping i am able to get response and when i enter it on browser i do get obi device page and default password admin , admin also works.

2019-10-07 20:13:06 WARNING (MainThread) [homeassistant.components.http] Configuring api_password via the http integration has been deprecated. Use the legacy api password auth provider instead. For instructions, see https://www.home-assistant.io/docs/authentication/providers/#legacy-api-password
2019-10-07 20:13:06 WARNING (MainThread) [homeassistant.components.http.auth] legacy_api_password support has been enabled.
2019-10-07 20:13:22 WARNING (MainThread) [homeassistant.setup] Setup of homekit is taking over 10 seconds.
2019-10-07 20:13:22 ERROR (MainThread) [homeassistant.components.hue] Error connecting to the Hue bridge at 192.168.149.240
2019-10-07 20:13:22 WARNING (MainThread) [homeassistant.config_entries] Config entry for hue not ready yet. Retrying in 5 seconds.
2019-10-07 20:13:25 WARNING (MainThread) [homeassistant.setup] Setup of xiaomi_aqara is taking over 10 seconds.
2019-10-07 20:13:26 ERROR (SyncWorker_17) [pyobihai] HTTPConnectionPool(host=‘192.168.1.165’, port=80): Max retries exceeded with url: /DI_S_.xml (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x7f7e615390>, ‘Connection to 192.168.1.165 timed out. (connect timeout=2)’))
2019-10-07 20:13:29 ERROR (SyncWorker_17) [pyobihai] HTTPConnectionPool(host=‘192.168.1.165’, port=80): Max retries exceeded with url: /PI_FXS_1_Stats.xml (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x7f7d4f2a90>, ‘Connection to 192.168.1.165 timed out. (connect timeout=2)’))

I think this may be a network issue on your end. Can you make sure the HA subnet has access to the Obi device? For some reason it looks like its not allowing the data to be pulled.

It worked once i had the obihai box on same DNS as Homeassistant, Thanks for your help

1 Like

Thank you for this, it is moving me closer to my own goal. Do you see any way to modify it to have Alexa announce CLID? I am beating myself up trying to get it working, but it seems that the easiest way to get her talking is to expose entities to the Alexa app, then use a routine. I am chasing my tail trying to figure out the best way to do this.

Sorry, I haven’t tried to send any announcements to Alexa - But I do use Sonos with TTS to make announcements so it seems it may be possible to at least speak the phone number. Don’t see how the caller ID could work though. My OBIHAI is configured for two providers and two phone lines (one is for me, the other for my wife) I may take a shot at getting the sonos to announce who the call is for and perhaps reading the number.
If you come across any solutions, please share! Thanks!

If you are still interested, say the word. It works perfectly.

Just install the Obihai integration, then make a sensor like this:

### CALLER ID ###

- platform: template
  sensors:
    clid_name:
      friendly_name: "Caller ID"
      value_template: >-
        {% if is_state('sensor.obihai_phone1_port_last_caller_info', '\'\' COUNTRYCODENPAxxxxxxx') %}
             Jane Doe
        {% elif is_state('sensor.obihai_phone1_port_last_caller_info', '\'\' COUNTRYCODENPAxxxxxxx') %}
             John Doe
        {% else %}
             Unknown
        {% endif %} 

It is time consuming to build your entire contacts database, if you have ~100 numbers like we do, but it is worthwhile, IMHO. It lets you customize that name, rather than rely on an external service like OpenCNAM or something.

Then make an automation something like this:

 id: 'xxxxxxxxxxxxxxxxxx'
  alias: Phone - Caller ID Name Announce
  description: ''
  trigger:
  - platform: state
    entity_id: sensor.obihai_call_direction
    to: Inbound Call
    from: No Active Calls
  condition:
  - condition: time
    after: 07:30:00
    before: '21:00:00'
  - condition: not
    conditions:
    - condition: state
      entity_id: sensor.clid_name
      state: Unknown
  action:
  - service: notify.all_condo_alexa
    data:
      message: Incoming call from {{ states("sensor.clid_name") }} . Incoming call
        from {{ states("sensor.clid_name") }} .
      data:
        type: tts
  - service: notify.all_firestick_notify
    data:
      message: Incoming Call from {{ states("sensor.clid_name") }}
      title: Phone
      data:
        color: green
        file:
          url: http://192.168.75.240:8123/local/images/ringingphone.png
  mode: single

I turned the ringer on all our phones off, and just use the voice announcement. If the caller is not in the sensor template, I don’t hear it, which is a big bonus if you get a lot of spam calls.

There are probably easier ways to do this, and I would love any advice anyone might feel like giving to make this more efficient, but this does work well for us.

1 Like

Nice job! I will be using that!

Please don’t hesitate to post if you have any questions, and likewise if you have any improvements.

Be sure to use the ‘’’ in front of the phone numbers, as the Obihai integration returns two ’ before the number, for reasons unknown. Otherwise, it is really straightforward.

Home Assistant has been a mental health saver during quarantine. I love my wife (and our cats), but with the kids grown and the house mostly empty - well, let’s just say “All work and no play makes Bill a dull boy”. Fifty thousand times. :slight_smile: Learning is salvation.

So the reason why it showed up like that is because thats the data Obihai gives on the device, I didn’t do any data stripping just wanted to give raw data. I recently got a PR to remove it, so it should hit HA soonish depends on when the reboot service PR gets accepted. So when that PR gets merged expect to see a breaking change :slight_smile:

1 Like

Sweet, thanks mate!

Please don’t regard what I said as a complaint though, this integration provides great benefit, and thank you for that! My understanding of these things is very limited, but thanks to this forum, it grows daily, and every day, my appreciation for those of you who contribute knowledge and effort grows. Best wishes to you, dshokouhi!