Asterisk binding not found in bindings

Hi Everyone,

I’m looking after the asterisk binding and it is missing from my add-ons->binding list (OpenHab 2.3) ?

Was it removed ?

Kind regards,

asterisk is not listed as compatible to openHAB2. I did install it manually by downloading the openhab-addons1

and copying the jar to the addons folder (see for details)

You will have to create the asterisk.cfg manually (see for details)

Please be aware that the binding does not work for me under OH2.4, I decided to change to mqtt (there is an agi mqtt script for asterisk out there… ) :slight_smile:

1 Like

Hi Udo

Can you tell us more about how you integrated the script? The script needs mosquitto but my centos box with asterisk does not have that, it has paho-mqtt


The script needs an active mqtt broker somewhere. openHAB2.4 ships with an option for an embedded mqtt broker, but the common solution would be to also install mosquitto somewhere in the LAN, e.g. parallel to openHAB

Of course, the script itself needs to act as a mqtt client, so you will need to use a lib to do that. If preferring paho-mqtt, you will have to adapt the calls in the script: This part of the script:

client = mosquitto.Mosquitto('agi')
client.username_pw_set(mqtt_username, mqtt_password)
client.connect(mqtt_server, port=mqtt_port)
client.on_connect = on_connect
client.on_publish = on_publish

client.publish(topic, payload=json.dumps(agi))

Hi Udo

ive got a MQTT broker on the LAN, I already use MQTT so its just the latter part I need to do (adapt the script)

Ill try that, thank you

Hi Udo

Gave up on paho-mqtt and installed mosquitto. It appears running but its like its unable to find mosquitto on the server. Do I also require a port in the IP mqtt.cfg

Documentation is very light on :confused:

[root@Asterisk agi-mqtt]# systemctl status mosquitto
● mosquitto.service - Mosquitto MQTT v3.1/v3.1.1 Broker
   Loaded: loaded (/usr/lib/systemd/system/mosquitto.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2019-02-02 11:52:06 AEDT; 3s ago
     Docs: man:mosquitto.conf(5)
 Main PID: 25599 (mosquitto)
   CGroup: /system.slice/mosquitto.service
           └─25599 /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf

Feb 02 11:52:06 Asterisk systemd[1]: Starting Mosquitto MQTT v3.1/v3.1.1 Broker...
Feb 02 11:52:06 Asterisk mosquitto[25599]: 1549068726: mosquitto version 1.5.5 starting
Feb 02 11:52:06 Asterisk mosquitto[25599]: 1549068726: Config loaded from /etc/mosquitto/mosquitto.conf.
Feb 02 11:52:06 Asterisk mosquitto[25599]: 1549068726: Opening ipv4 listen socket on port 1883.
Feb 02 11:52:06 Asterisk mosquitto[25599]: 1549068726: Opening ipv6 listen socket on port 1883.
Feb 02 11:52:06 Asterisk systemd[1]: Started Mosquitto MQTT v3.1/v3.1.1 Broker.
[root@Asterisk agi-mqtt]# ./mqtt
Traceback (most recent call last):
  File "./mqtt", line 12, in <module>
    import mosquitto
ImportError: No module named mosquitto

No, this is the broker, you don’t want to install the mosquitto broker on asterisk.
You need to import the mosquitto lib
You have to install the lib by using
pip install mosquitto or pip3 install mosquitto

Thanks Udo, why is this so hard!

[root@Asterisk ~]# pip install mosquitto
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Collecting mosquitto
  Could not find a version that satisfies the requirement mosquitto (from versions: )
No matching distribution found for mosquitto
[root@Asterisk ~]#


Seems, there where many changes since. So…

  1. pip install paho-mqtt
  2. pip install configparser
  3. change the script downloaded from slightly:
import mosquitto


import paho.mqtt.client as mqtt

The line

client = mosquitto.Mosquitto('agi')


client = mqtt.Client('agi')

I did not test this yet, but these changes should suffice to bring that up and running.

Please also take a look at commits, seems that Jan-Piet Mens changed the code completely to paho-mqtt…

1 Like

Thank you Udo, its not very newbie friendly. I run through these steps and see if I can get it working!

Still fails. Seems this is the new version:

I edited my mqtt script and replaced the code with whats in the link.

now this:

[root@Asterisk agi-mqtt]# ./mqtt
Traceback (most recent call last):
  File "./mqtt", line 15, in <module>
    conffile, topic = sys.argv[1:3]
ValueError: need more than 0 values to unpack

Yes, this would be the new version. Please take a look at the code:

# Usage:
# AGI(/etc/asterisk/agi/mqtt,/etc/asterisk/agi/mqtt.cfg,calls/missed)
# or, to override the extension:
# AGI(/etc/asterisk/agi/mqtt,/etc/asterisk/agi/mqtt.cfg,calls/missed,+43123456789)

So, to test the script, you have to use

./mqtt ./mqtt.cfg agi_123456:test 

where agi_123456:test is a test string. Not sure if this will work as intended. ./mqtt.cfg is path to and name from configuration file (rename mqtt.cfg.sample to mqtt.cfg and change the content to fit with your mqtt server (server address/ip, port, username/password)

The code may as well be chinese to me Udo :wink:

But I did look and replaced the contents of my script. I did the config file. Let me try the . PS where does it say thats how you test it ?

Not working. All good, Ill junk this, too hard. I love it how this setup says ‘setup was a doodle’ LOL

I have to say, if you’re familiar with asterisk, I can’t believe this part is too hard :wink:

I’m not Udo, I use FreePBX and it works very well/easy using the UI :slight_smile:

I’m no programmer/developer/coder so the script side is foreign to me.

Ah. But FreePBX is almost the same (only thing is, as it uses an UI, you can’t configure all the stuff in one step :japanese_ogre: )


The mqtt script is started with AGI, (Asterisk Gateway Interface).
The call mentioned above (within the comment of the script itself) must be placed in your extension processing, the part where incoming calls get allocated to the phones.

So, my extension is 1001, I want to basically switch an item ON when that has an active call. Thats my intention for this.

So, do I run the below, 1001 being my extension and doorbirdcall being the topic?

./mqtt ./mqtt.cfg agi_1001:doorbirdcall

Here is my extensions_custom.conf

[root@Asterisk asterisk]# cat extensions_custom.conf
exten => _X.,1,AGI(/etc/asterisk/agi/agi-mqtt,/etc/asterisk/agi/agi-mqtt/mqtt.cfg,calls/doorbirdcall)

And my mqtt.cfg

[root@Asterisk agi-mqtt]# cat mqtt.cfg
server =
username = mosquitto
password = password

I must be doing something wrong :frowning:

Shouldn’t this be

[root@Asterisk asterisk]# cat extensions_custom.conf
exten => _X.,1,AGI(/etc/asterisk/agi/agi-mqtt/mqtt,/etc/asterisk/agi/agi-mqtt/mqtt.cfg,calls/doorbirdcall)
#                                            ^^^^^


The topic would be calls/doorbirdcall

Thanks udo.

Am I right in saying that I just run the script and make a call and I should see something on the screen? lol!

I get nothing.