Obihai Integration Setup

I’m trying to setup the Obihai Integration: https://www.home-assistant.io/integrations/obihai/

I followed the setup and added this to my config:

sensor:
  - platform: obihai
    host: <Obihai 1032 IP address>

In my logs I see this:

2020-01-19 11:54:27 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up platform obihai
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/xml/etree/ElementTree.py", line 1630, in feed
    self.parser.Parse(data, 0)
xml.parsers.expat.ExpatError: mismatched tag: line 3, column 58

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 150, in _async_setup_platform
    await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/obihai/sensor.py", line 58, in setup_platform
    line_services = pyobihai.get_line_state()
  File "/usr/local/lib/python3.7/site-packages/pyobihai/__init__.py", line 72, in get_line_state
    root = xml.etree.ElementTree.fromstring(resp.text)
  File "/usr/local/lib/python3.7/xml/etree/ElementTree.py", line 1315, in XML
    parser.feed(text)
  File "/usr/local/lib/python3.7/xml/etree/ElementTree.py", line 1632, in feed
    self._raiseerror(v)
  File "/usr/local/lib/python3.7/xml/etree/ElementTree.py", line 1531, in _raiseerror
    raise err
  File "<string>", line None
xml.etree.ElementTree.ParseError: mismatched tag: line 3, column 58

Is anyone else using this? The sensor also doesn’t seem to have a way to set a name. I have two Obihai phones, so is there no way to set this up?

Thanks!

I have a seperate Sensor file to keep my configuration from getting to cluttered

my Obihai is configured like this in it

- platform: obihai
  host: 192.168.1.92

if you are putting directly in configuration file then you need the line with sensor: on it like on the intergrations page

also, if this is directly in your configuration.yaml, you can only have the sensor: tag once in that file. You would just have all the various sensors, including this one, under that single tag.

I only have sensor: in my configuration.yaml one time. I’m not sure what else to do with this because it seems like it’s setup correctly. I restarted the HA server to make sure I had done it in the right order and got the same errors in my log file.

Are you using a Obihai phone, or one of their adaptor devices? I have an OBi1022 and an OBi1032. I changed the IP address to test with both, but am getting the same errors after restarting.

When I looked into pyobihai, I see that it looks for line status here: PI_FXS_1_Stats.xml. When I got to that url on my local device (ip/PI_FXS_1_Stats.xml), I get a requested URL not found error. So I’m wondering if this won’t work with the phones that I have.

As an update, I couldn’t get the integration to work, so I just built a command line sensor to grep the XML page that I did have for my phone:

  - platform: command_line
    name: office_phone_active
    command: curl --digest -u <<user:password>> -k --silent "http://<<phone IP>>/DI_S_.xml" | grep -Po '\<value hash=\"d61dd7df\".*\K([0-9])'
    scan_interval: 5

This brings back the number of active calls on the main line of the phone. I’m not sure it’s perfect, but it’s good enough to get an indicator flipped when the phone is in use. I’m also not sure what that hash value is that I’m looking for, except that it seems to be consistent on my phone…

I have the adapter OBi202

Hey I worked on this integration.

When you login to your obihai device from a browser do you have an option for “Phone port status” or some thing similar? This is where we grab some data for a few sensors like last caller info or on hook status etc… If you open an issue in pyobihai and provide the xml (masking any passwords or anything like that) I can take a look at things to see if we can update pyobihai for your device. You may need to hunt somethings down in developer tools network tab.

I don’t see “Phone port status.” The thing in the XML that triggers me to know that I’m on the phone is dependent on the line. The 1032 supports 6 different SP lines. So in the XML I “CallState” in the XML 6 times.

I’ll open up an issue and provide the XML. Thanks!