Asterisk in Home Assistant – Part 3

The automation

The final part is to glue things together in an automation. In configuration.yaml i added:

  - alias: 'Flash lights'
      - platform: state
        entity_id: sensor.asterisk_extension_1000
        to: 'Ringing'
      - service: light.turn_on
          entity_id: light.living_room
          flash: long


Now calling myself will flash the lighs in my living room πŸ™‚


When things go wrong.

I wanted to see what happened if my Asterisk server wasn’t running. It seemed pretty bad for my Home Assistant πŸ™ It took almost 5 minutes to start up!

So I did a little investigation and found out the the pyst2-library wasn’t handling this situation very well. I did a small modification toΒ /srv/homeassistant/lib/python3.5/site-packages/asterisk/manager.pyΒ in the connect() method:

            _sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            _sock.connect((host, port))
            if PY3:

I added a timeout for the socket connect and then set it back to normal after the connection was made. This seemed to solve my problem.

End of project.

I hope you found my little writeup useful. Post a note if you like it or not πŸ™‚



4 thoughts to “Asterisk in Home Assistant – Part 3”

  1. Just want to say I use Tasker for this.

    Of course you learned way more building all this, and maybe it does more than my solution (to be honest I didn’t read through all the guides because I am not going to use it).

  2. Very interesting!
    I’m an Asterisk/FreePBX user for many years. Long time ago i had some code on my Linux server to announce a callers name or number on my SqueezeBox radio. I’m running HA for a couple of months now and it would be nice to have a callers name or number anounced on my SqueezeBox(es).

    I wil start trying to implement your custom component to just anounce that there is an incoming call.
    If that works i will try to extend it to provide the number and maybe the name later.

    I’m also using Tasker (Automation app for Android) for presence detection etc., but i prefer to do as much as i can from a central place (i.e. HA, Domoticz, Node-Red, MQTT). This to avoid having to implement a solution on all my mobile devices.

    Thanks Alex, for sharing and explaining the details πŸ‘πŸ»

Leave a Reply

Your email address will not be published. Required fields are marked *