Obihai device details to Home assistant - incoming/outgoing calls, line status, system status etc

I have setup that provides Obihai phone details to my Home Assistance instance.
It provides details like:

  • Each line status if device supports multiple lines
  • Call status
  • Call history with inbound/outbound indication

I have telegram notifications setup in Home Assistant so my family gets notified for any incoming call while we are not at home. I have AppDaemon app to handle status change and then send notifications.

Some technical details:
I am listening system logs events from Obihai device to analyze all kind of activity happening there and then update Home Assistant as log it. There is a configuration file to fit your need. You can also configure to use opencnam web service to find out caller name from the number and update Home Assistant with name and number.

Here are the screenshots how it looks in Home Assistant:

Hope this helps someone, more details on how to use on my github:

3 Likes

This is going to be great !! I haven’t hooked up my Obihai yet, but this will surely push me to do so. Thanks for your contribution! Bookmarked !!

Thanks.
Sure, here to help if anyone has any question, issue or even suggestion!
I am still learning to how to create Home Assistant component so it can be natively integrated.
Enjoy!

@scadaguru

I’ve been looking for something like this since I couldn’t get that hass.io add on working. That add on polls the obihai decice every x seconds. This seems better since the notification can be instant and you arent needlessly polling.

However, I think the instructions are over my head. Any chance you can make this a bass.io add on?

I am learning how to create HA components, once I do that it should work for hass.io too.
By the way if you try to follow the instruction, I can help you if you get stuck or need any help meanwhile.

Is it possible to add this to the hass.io homeassistant, or is it better running on a separate device?

As of now I have it to run separate but I am planning to make HA component.
If any developer interested can do that now!

Tried as I may, I’ve had limited success. I have everything configured correctly, and I’m launching manually for now. I do see some items changing, but not receiving status updates on everything. Using Homeassistant 0.72 (not hass.io), no docker, Obi 200 device.

One error I encountered I was able to tweak to get things to work:

Config folder: /config/
Traceback (most recent call last):
  File "main_obihai.py", line 34, in <module>
    main_object = ObihaiMonitor(root_path)
  File "main_obihai.py", line 10, in __init__
    self.helper = ObihaiHelper(config_folder)
  File "/home/aaron/scripts/obihai/obisyslog/obihai_helper.py", line 21, in __init__
    self.config = yaml.load(open(self.config_folder + 'config.yaml'))
FileNotFoundError: [Errno 2] No such file or directory: '/config/config.yaml'

If I edit obihai_helper.py and change line 21 from

self.config = yaml.load(open(self.config_folder + 'config.yaml'))

to:

self.config = yaml.load(open('config.yaml'))

it works fine… I am however missing a couple of sensors

working:
sensor.obihai_reboot_required
sensor.obihai_up_time
sensor.obihai_software_version
sensor.obihai_statuses
sensor.obihai_last_updated
sensor.phone_details_(1-10)
sensor.active_call_direction_port1

not working:
sensor.phone_status_port1
sensor.phone_details_port1

Additionally, the sensor.active_call_direction_port1 does not show when the call has completed, so it still shows as outgoing even after the phone has been hung up.

The likelihood that I screwed something up is high, but hope to get this working just to take action when the phone is ringing, the one sensor I can’t get to work :slight_smile:

–edit–

Also figured out if I change line 30 of config.yaml I now see a value for ‘sensor.phone_status_port1’
changed from

onoffhook: "<7> [SLIC]:Slic#1"

to

onoffhook: "<7> [SLIC]:Slic#0"

It is good to know is working for you now.
I advised that rather than changing the code you should run with specifying the current folder using period (.) as documented shown below: Notice that period at the end!

python3 main_obihai.py .

Now about the other issue you had:

I would advise to provide port# in config.yaml under monitor section then you will not have to change the part of the config.yaml which not for user editing purpose. Here is what you could do: (make sure indentation in your config.yaml after copy/paste)

monitor: # Add a line for each connected phone to obihai device
      port2: Home

Enjoy!

scadguru, I’ve cloned the repo to a freshly imaged raspberry pi stretch lite system and edited the configuration files. I’m unable to run the python script. Error Message:

Traceback (most recent call last):
File “main_obihai.py”, line 3, in
from obihai_helper import ObihaiHelper
File “/home/pi/obisyslog/obihai_helper.py”, line 6, in
import yaml # this needs package called PyYAML
ImportError: No module named ‘yaml’

I’ve used pip to instyall PyYAML, but the message persists.

The dockerfile command doesn’t work either. docker docker-compose up -d
yields the usage message and

unknown shorthand flag: ‘d’ in -d

duly noted scadaguru … I’m really just a monkey doing a math problem, just poking around until it works.
That being said, I had an unfortunate incident with an SD card taking a nose dive and have had to start over from scratch.

I am also having the same issue as ubergoober with the latest version

Can you try installing like this:

pip3 install requests PyYAML

About docker I think command should be:(I have just corrected this on github)

sudo docker-compose up -d

Try the solution I just posted above please.

docker still experiencing an issue. I used the docker repo to install docker-compose. here goes:

pi@rpilite:~/obisyslog $ sudo docker-compose up -d
ERROR: Version in “./docker-compose.yaml” is unsupported. You might be seeing this error because you’re using the wrong Compose file version. Either specify a version of “2” (or “2.0”) and place your service definitions under the services key, or omit the version key and place your service definitions at the root of the file to use version 1.
For more on the Compose file format versions, see https://docs.docker.com/compose/compose-file/
pi@rpilite:~/obisyslog $ docker-compose version
docker-compose version 1.8.0, build unknown
docker-py version: 1.9.0
CPython version: 2.7.13
OpenSSL version: OpenSSL 1.1.0f 25 May 2017

They pip3 enabled me to start without docker.

Should I be concerned with:

ObihaiSyslog:monitor():Exception: [Errno 13] Permission denied

messages?

I wiped my folder and did a fresh clone, and edited my config.yaml
Ran pip3 install request PyYAML, which installed ver 3.13

Running sudo python3 main_obihai.py . yields:

File "main_obihai.py", line 3, in <module>
from obihai_helper import ObihaiHelper
File "/home/obisyslog/obihai_helper.py", line 6, in <module>
import yaml  # this needs package called PyYAML
ImportError: No module named 'yaml'

Can you share your group.yaml file from HomeAssistant? (and maybe sensor.yaml) So we can get the icons and the look that you have. This is all fantastic work!!

Icons are part of the code and don’t need configuration to show automatically in the Home Assistant from the obisyslog. Hope this helps.

I am not sure why pyyaml not getting installed on the raspberry pi.

Yes, Looks like it failed to establish a connection to the IP:Port you have configured for the Obihai device.
And hence obisyslog will not get any updates from the Obihai device and will not update Home Assistant with real time updates. It still may work for scheduled polls using poll_interval from the config.yaml file.