arnonym/ha-plugins
关于
Home-Assistant SIP Gateway
效率与自动化实测星标增长
- 24小时
- 0
- 7天
- +1
- 15天
- +5
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文
ha-sip
This repository contains two versions of the ha-sip app:
ha-sip-ng— the next generation of ha-sip, documented here. It is a from-scratch Kotlin/JVM reimplementation that runs on the JVM against PJSIP's Java SWIG bindings, which also removes the single-thread limitations of the Python version (e.g. with recordings). It already has features the Python version lacks: limiting the offered codecs (--codecs), RTP port ranges (--rtp-port,--rtp-port-range),m=textmedia (--text-media) and resampling of audio (--audio-sample-rate).ha-sip— the original Python version, documented in README-PYTHON.md.
The Kotlin version is expected to be compatible with the python version.
Home Assistant SIP/VoIP Gateway is a Home Assistant app which
- allows the dialing and hanging up of phone numbers through a SIP end-point
- triggering of services through dial tones (DTMF) after the call was established.
- listens for incoming calls and can trigger actions through a web-hook (the call is not picked up)
- accepting calls (optionally filtered by number)
- handle PIN input before triggering actions
- send DTMF digits to an established call (incoming or outgoing)
- record calls into .wav files
- speak to Home Assistant Voice Assist without special hardware
Installation
This app is for the Home Assistant OS or supervised installation methods mentioned in
https://www.home-assistant.io/installation/. With that in place you can install this third-party plug-in like described in
https://www.home-assistant.io/common-tasks/os#installing-a-third-party-app-repository. The repository URL is
https://github.com/arnonym/ha-plugins.
Note: This add-on's slug is
ha-sip-ng(distinct from the productionha-sipadd-on), so it can be installed side by side with the Python version for comparison. If you enable both at once, make sure they don't share the same SIP account/port. See Testing this Kotlin port in Home Assistant.
Note: Alternatively you can run ha-sip in a stand-alone mode (for Home Assistant Container installations). In that mode the communication to ha-sip will be handled by MQTT. You can find the installation steps at the end of this document.
After that you need to configure your SIP account(s), TTS parameters and webhook ID. The default configuration looks like this:
sip_global:
port: 5060
log_level: 5 # log level of pjsip library
name_server: '' # comma separated list of name servers, must be set if sip server must be resolved via SRV record
cache_dir: '/config/audio_cache' # directory to cache TTS messages or converted audio files. Must be inside /config or /media and existing
global_options: ''
sip: # list of SIP accounts, as many as you need
- enabled: true # account 1
registrar_uri: sip:fritz.box
id_uri: sip:[email protected]
realm: '*'
user_name: homeassistant
password: secure
answer_mode: listen # "listen", "accept", or "reject". see below
settle_time: 1 # time to wait for playing the message/actions/etc. after call was established
incoming_call_file: "" # config and menu definition file for incoming calls, see below
options: ''
- enabled: false # account 2
registrar_uri: sip:fritz.box
id_uri: sip:[email protected]
realm: '*'
user_name: anotheruser
password: secret
answer_mode: listen
settle_time: 1
incoming_call_file: ""
options: ''
tts:
engine_id: tts.google_translate_de_com # entity id of the TTS engine
platform: google_translate # deprecated, must not be set if engine_id is set
language: en # might also be in en-US format, depending on the platform
debug_print: false # set to true, to output known engines and languages to the log at startup
voice: zephyr # voice if engine supports it
webhook:
id: sip_call_webhook_id
Note:
sipis a list, so you can configure any number of SIP accounts. An account's number — used assip_accountin commands and web-hooks, and in the sensor entity IDs — is its position in the list: the first entry is account 1, the second account 2, and so on. To switch an account off without renumbering the ones after it, setenabled: falseinstead of removing it.In stand-alone mode, accounts are configured through the
SIP<n>_*variables in.env(SIP1_ENABLED,SIP1_ID_URI, ...), likewise with as many accounts as you need.
Note: When your
user_nameorpasswordstarts with a number, you need to put it in quotes like"1234".
Note For TTS you need to install one of the TTS integrations. If you're unsure about the entity id used for
engine_id, setdebug_printtotrueand restart the app. The app will output a list of all available engines and languages into the log. If the configured engine and language is valid, it will also log the available voices (if the engine supports it).
Note You are able to access the /config and /media directory inside the app for config files, audio files, cache and recordings.
For global_options you can specify the following options
--stun-server STUN_SERVER
STUN server to use for NAT traversal (default: None)
--udp {enabled,enable,true,yes,on,1,disabled,disable,false,no,off,0}
Enable or disable UDP transport (default: enabled)
--tcp {enabled,enable,true,yes,on,1,disabled,disable,false,no,off,0}
Enable or disable TCP transport (default: enabled)
--tls {enabled,enable,true,yes,on,1,disabled,disable,false,no,off,0}
Enable or disable TLS transport (default: disabled)
--tls-port TLS_PORT Port to use for TLS transport (default: 5061)
--rtp-port RTP_PORT First port used for RTP/RTCP media sockets (default: 4000)
--rtp-port-range RTP_PORT_RANGE
Number of additional ports usable for RTP/RTCP media sockets,
starting at --rtp-port, e.g. a range of 100 with the default
--rtp-port allows 4000-4100 (default: 0, i.e. only --rtp-port
itself is used).
--debug-headers {enabled,enable,true,yes,on,1,disabled,disable,false,no,off,0}
Enable debug printing of all available SIP headers (default: disabled)
--codecs CODECS Comma-separated list of audio codecs to offer, highest priority
first, e.g. "PCMU,PCMA".
(default: offer everything pjsip supports)
--text-media {enabled,enable,true,yes,on,1,disabled,disable,false,no,off,0}
Enable or disable the "m=text" (RFC 4103) line in the SDP.
(default: disabled)
--audio-sample-rate AUDIO_SAMPLE_RATE
Resample every message and audio file to this rate, in Hz, e.g.
"8000". Only needed where pjsip's own resampling misbehaves;
leaving it unset keeps each file at its original rate.
(default: unset)
--enable-mqtt Enable MQTT as a command source (default: disabled)
--mqtt-address MQTT_ADDRESS
MQTT broker address (default: empty)
--mqtt-port MQTT_PORT
MQTT broker port (default: 1883)
--mqtt-username MQTT_USERNAME
MQTT broker username (default: empty)
--mqtt-password MQTT_PASSWORD
MQTT broker password (default: empty)
--mqtt-topic MQTT_TOPIC
MQTT topic to subscribe to for incoming commands (default: hasip/execute)
--mqtt-state-topic MQTT_STATE_TOPIC
MQTT topic to publish call state events to (default: hasip/state)
For options on each SIP account there are
--proxy PROXY Proxy server to use for SIP (default: None)
--ice {enabled,enable,true,yes,on,1,disabled,disable,false,no,off,0}
Enable or disable ICE (default: true)
--use-stun-for-sip {enabled,enable,true,yes,on,1,disabled,disable,false,no,off,0}
Enable or disable STUN for sip (default: true)
--use-stun-for-media {enabled,enable,true,yes,on,1,disabled,disable,false,no,off,0}
Enable or disable STUN for media (default: true)
--use-contact-rewrite {enabled,enable,true,yes,on,1,disabled,disable,false,no,off,0}
Enable or disable contact rewrite for SIP (default: true)
--use-via-rewrite {enabled,enable,true,yes,on,1,disabled,disable,false,no,off,0}
Enable or disable via rewrite for SIP (default: true)
--use-sdp-nat-rewrite {enabled,enable,true,yes,on,1,disabled,disable,false,no,off,0}
Enable or disable SDP NAT rewrite for SIP (default: true)
--use-sip-outbound {enabled,enable,true,yes,on,1,disabled,disable,false,no,off,0}
Enable or disable SIP outbound (default: true)
--turn-server TURN_SERVER
Set the TURN server to use for SIP (default: None)
--turn-connection-type {tcp,udp,tls}
Set the TURN server connection protocol (default: udp)
--turn-user TURN_USER
Set the TURN user (default: None)
--turn-password TURN_PASSWORD
Set the TURN password (default: None)
--extract-headers EXTRACT_HEADERS
Comma-separated list of SIP headers to extract and include in webhooks (default: None)
--reject-sip-code REJECT_SIP_CODE
SIP response code used when rejecting incoming calls in reject mode (default: 603)
Usage
Note: All examples below use
c7744bff_ha-sip-ngas a placeholder for theaddon:field. Look up the real value in Home Assistant under Settings → Add-ons → ha-sip (Kotlin) → Info, or Developer Tools → Actions (search forhassio.addon_stdinand check theaddonfield's autocomplete) — it's a<repository_hash>_ha-sip-ngstyle id assigned by Supervisor when it adds this repository, and can't be predicted ahead of time.
Outgoing calls
Outgoing calls are made via the hassio.addon_stdin service in the action part of an automation.
To be able to enter the full command, you must switch to YAML mode by clicking on the menu with the triple dot and
selecting Edit in YAML.
You can use dial and hangup with the hassio.addon_stdin service to control outgoing calls in an action in
your automation:
service: hassio.addon_stdin
data:
addon: c7744bff_ha-sip-ng
input:
command: dial
number: sip:**[email protected] # number to call. Format depends on your SIP provider,
# but might look like 'sip:[email protected]' for external calls
webhook_to_call: # web-hook IDs which you can listen on in your actions (additional to the global web-hook)
ring_timeout: another_webhook_id # can be all the same, or different
call_established: another_webhook_id
entered_menu: another_webhook_id
timeout: another_webhook_id # is called after the given time-out on a menu is reached
dtmf_digit: another_webhook_id # is called when the calling party sends a DTMF tone
call_disconnected: another_webhook_id
playback_done: another_webhook_id # is called after playback of message or audio file is done
ring_timeout: 15 # time to ring in seconds (optional, defaults to 300)
sip_account: 1 # number of the sip account, i.e. its position in the `sip` list (1 is the first)
# (optional, defaults to first enabled sip account)
menu:
message: There's a burglar in da house.
If there is already an outgoing call to the same number active, the request will be ignored.
To hang up the call again:
service: hassio.addon_stdin
data:
addon: c7744bff_ha-sip-ng
input:
command: hangup
number: sip:**[email protected]
sip_code: 486 # optional SIP status code (e.g. 486 "Busy Here", 603 "Decline")
# only applied when the call has not been answered yet;
# ignored for already active calls
To send DTMF digits to an established call:
service: hassio.addon_stdin
data:
addon: c7744bff_ha-sip-ng
input:
command: send_dtmf
number: sip:**[email protected]
digits: "123#"
method: in_band # method can be "in_band" (default), "rfc2833" or "sip_info"
Note: When using a
#digit, you need to put the whole sequence in quotes, eg."#5".
Warning You can't use the
post_actionwithsend_dtmfbecause there's no way to know when PJSIP is done sending the tones.
To transfer a call to a different SIP URI:
service: hassio.addon_stdin
data:
addon: c7744bff_ha-sip-ng
input:
command: transfer
number: sip:**[email protected]
transfer_to: sip:**[email protected]
To bridge the audio streams of two active calls:
service: hassio.addon_stdin
data:
addon: c7744bff_ha-sip-ng
input:
command: bridge_audio
number: sip:**[email protected]
bridge_to: sip:**[email protected]
To play a message through TTS
service: hassio.addon_stdin
data:
addon: c7744bff_ha-sip-ng
input:
command: play_message
number: sip:**[email protected]
message: hello!
tts_language: en
cache_audio: true # If message should be cached in `cache_dir`.
# Defaults to false. `cache_dir` must be configured in ha-sip config.
# Don't enable this for dynamic messages, you'll just fill your storage.
wait_for_audio_to_finish: true # Do not accept DTMF tones until the message has been played
post_action: hangup # hang up the call after the message has been played, only "noop" (default)
# and "hangup" are supported in this context
To play an audio file
service: hassio.addon_stdin
data:
addon: c7744bff_ha-sip-ng
input:
command: play_audio_file
number: sip:**[email protected]
audio_file: '/config/audio/welcome.mp3'
cache_audio: true # If converted file should be cached in `cache_dir`.
# Defaults to false. `cache_dir` must be configured in ha-sip config
wait_for_audio_to_finish: true # Do not accept DTMF tones until the audio file has been played
post_action: hangup # hang up the call after the message has been played, only "noop" (default)
# and "hangup" are supported in this context
To stop audio playback (both audio file and message):
service: hassio.addon_stdin
data:
addon: c7744bff_ha-sip-ng
input:
command: stop_playback
number: sip:**[email protected]
To start a call recording
service: hassio.addon_stdin
data:
addon: c7744bff_ha-sip-ng
input:
command: start_recording
number: sip:**[email protected]
recording_file: "/config/www/call_12345.wav" # must be an absolute path
Note: The recording is stopped when the call ends.
To stop a call recording
service: hassio.addon_stdin
data:
addon: c7744bff_ha-sip-ng
input:
command: stop_recording
number: sip:**[email protected]
Incoming calls
Listen mode
In listen mode no call will be answered (picked up) but you can trigger an automation through a Webhook trigger for every incoming call.
The webhook ID must match the ID set in the configuration.
You can get the remote from {{trigger.json.remote_uri}} or {{trigger.json.parsed_remote_uri}} for usage in e.g. the action of your automation.
If you want to react on a webhook message with another command you should use {{ trigger.json.internal_id }} as the number.
If you also use the menu ID webhook you need to check for {{ trigger.json.event == "incoming_call" }} e.g. in a "Choose" action type.
Example of "incoming call" webhook message:
{
"event": "incoming_call",
"call_direction": "incoming",
"remote_uri": "<sip:[email protected]>",
"parsed_remote_uri": "5551234456",
"sip_account": 1,
"internal_id": "something-unique"
}
You can also answer an incoming call from home assistant by using the hassio.addon_stdin service:
service: hassio.addon_stdin
data:
addon: c7744bff_ha-sip-ng
input:
command: answer
number: "{{ trigger.json.internal_id }}" # if this is unclear, you can look that up in the logs ("Registering call with id <number>")
webhook_to_call: # optional web-hook IDs which you can listen on in your actions (additional to the global web-hook)
call_established: another_webhook_id
entered_menu: another_webhook_id
timeout: another_webhook_id # is called after the given time-out on a menu is reached
dtmf_digit: another_webhook_id # is called when the calling party sends a DTMF tone
call_disconnected: another_webhook_id
playback_done: another_webhook_id # is called after playback of message or audio file is done
menu:
message: Bye
post_action: hangup
If you don't provide a menu the menu from incoming_call_file will be used.
Accept mode
In accept mode you can additionally make ha-sip to accept the call. For this you can define a menu per SIP account. Put a config file
into your /config directory of your home-assistant installation (e.g. use the samba app to access that directory).
Example content of /config/sip-1-incoming.yaml:
allowed_numbers: # list of numbers which will be answered. If removed all numbers will be accepted
- "5551234456"
- "5559876543"
- "555{*}" # matches every number starting with 555
- "555{?}" # matches every number starting with 555 which is 4 digits long
# blocked_numbers: # alternatively you can specify the numbers not to be answered. You can't have both.
# - "5551234456"
# - "5559876543"
answer_after: 0 # time in seconds after the call is answered (optional, defaults to 0)
webhook_to_call: # web-hook IDs which you can listen on in your actions (additional to the global web-hook)
call_established: another_webhook_id # can be all the same, or different
entered_menu: another_webhook_id
dtmf_digit: another_webhook_id
call_disconnected: another_webhook_id
menu:
message: Please enter your access code
choices_are_pin: true
choices:
'1234':
id: owner
message: Welcome beautiful.
post_action: hangup
'5432':
id: maintenance
message: Your entrance has been logged.
post_action: hangup
'default':
id: wrong_code
message: Wrong code, please try again
post_action: return
After that you set incoming_call_file in the app configuration to /config/sip-1-incoming.yaml.
Reject mode
In reject mode every incoming call is automatically rejected. No audio is played and the call is never
answered. A webhook is still triggered for each rejected call, so you can still react to incoming calls
in your automations (e.g. for logging or notifications).
The SIP response code sent to the caller defaults to 603 Decline and can be changed via the
--reject-sip-code option on the SIP account (e.g. --reject-sip-code 486 for "Busy Here").
Call menu definition
used for incoming and outgoing calls.
menu:
id: main # If "id" is present, a message will be sent via webhook (entered_menu), see below (optional)
message: Please enter your access code # the message to be played via TTS (optional, defaults to empty)
language: en # TTS language (optional, defaults to the global language from app config)
choices_are_pin: true # If the choices should be handled like PINs (optional, defaults to false)
timeout: 10 # time in seconds before "timeout" choice is triggered (optional, defaults to 300)
post_action: noop # this action will be triggered after the message was played. Can be
# "noop" (do nothing),
# "return <level>" (makes only sense in a sub-menu, returns <level> levels, defaults to 1),
# "hangup" (hang-up the call) and
# "repeat_message" (repeat the message until the time-out is reached)
# "jump <menu-id>" (jumps to menu with id <menu-id>)
# (optional, defaults to noop)
action: # action to run when menu was entered (before playing the message) (optional)
# For details visit https://developers.home-assistant.io/docs/api/rest/, POST on /api/services/<domain>/<service>
domain: switch # home-assistant domain
service: turn_on # home-assistant service
entity_id: switch.open_front_door # home assistant entity (optional)
choices: # the list of actions available through DTMF (optional)
'1234': # DTMF sequence, and definition of a sub-menu
id: owner # same as above, also any other option from above can be used in this sub-menu
handle_as_template: true # if true, the message will be rendered as a template and dynamic content can be
# used. Useful for messages in incoming_call_file or from MQTT.
# (optional, defaults to false)
message: >
Welcome beautiful.
{% set temp = state_attr("climate.my_room", "current_temperature")|round(1) %}
There are {{ states.zone.home.state }} people home.
Current temperature is {{ temp }} degrees.
{% if temp >= 20 %}Come in, it's cozy!{% endif %}
cache_audio: true # If message should be cached in `cache_dir`.
# Defaults to false. `cache_dir` must be configured in ha-sip config.
# Don't enable this for dynamic messages, you'll just fill your storage.
wait_for_audio_to_finish: true # Do not accept DTMF tones until the message/audio file has been played
post_action: hangup
'5432':
id: maintenance
message: Your entrance has been logged.
post_action: hangup
'7777':
audio_file: '/media/audio/welcome.mp3' # audio file to be played (.wav or .mp3).
post_action: jump owner # jump to menu id 'owner'
'default': # this will be triggered if the input does not match any specified choice
id: wrong_code
message: Wrong code, please try again
post_action: return
'timeout': # this will be triggered when there is no input
id: timeout
message: Bye.
post_action: hangup
Note: The audio files need to reside in your home-assistant
configormediadirectory, as these are the only directory accessible inside the app.
Web-hooks
For most events in ha-sip there's a web-hook triggered. The property internal_id is the number you can use
to identify the call in your automations.
These are the common fields available in all webhook events:
{
"internal_id": "something-unique",
"call_direction": "incoming",
"local_uri": "<sip:[email protected]>",
"remote_uri": "<sip:[email protected]>",
"parsed_local_uri": "sip-user",
"parsed_remote_uri": "5551234456",
"sip_account": 1,
"call_id": "[email protected]",
"headers": {}
}
call_direction is either "incoming" or "outgoing".
Note: The
headersfield contains extracted SIP headers if--extract-headersis configured on the SIP account, otherwise it's an empty object. See SIP Header Extraction for more details.
Additionally, the event name and event specific fields are available:
incoming_call
{
"event": "incoming_call"
}
call_established
{
"event": "call_established"
}
entered_menu
{
"event": "entered_menu",
"menu_id": "owner"
}
dtmf_digit
{
"event": "dtmf_digit",
"digit": "1"
}
call_disconnected
{
"event": "call_disconnected"
}
playback_done for message (TTS)
{
"event": "playback_done",
"type": "message",
"message": "message that has been played"
}
playback_done for audio file
{
"event": "playback_done",
"type": "audio_file",
"audio_file": "/media/audio/welcome.mp3"
}
ring_timeout
{
"event": "ring_timeout"
}
timeout
{
"event": "timeout",
"menu_id": "main"
}
recording_started
{
"event": "recording_started",
"recording_file": "/media/www/call_12345.wav"
}
recording_stopped
{
"event": "recording_stopped",
"recording_file": "/config/www/call_12345.wav"
}
outgoing_call_initiated
{
"event": "outgoing_call_initiated"
}
Sensors
ha-sip can expose sensor entities to Home Assistant for monitoring SIP account status and call activity. These only show information regarding ha-sip itself, not the SIP provider (you cannot see calls that are answered on other SIP devices, as this is not supported by the SIP protocol).
To enable sensors, add the following to your app configuration:
sensors:
enabled: true
entity_prefix: ha_sip # optional, defaults to "ha_sip"
Call Activity Sensor
Tracks whether a call is currently active on each SIP account.
| Entity ID | State | Description |
|---|---|---|
sensor.{prefix}_account_{n} |
true / false |
Whether a call is active |
Attributes when active:
remote_uri: Full remote party URIlocal_uri: Full local SIP account URIparsed_remote_uri: Extracted remote party numberparsed_local_uri: Extracted local SIP account numbersip_account: Account numbercall_id: SIP call IDheaders: Extracted SIP headers (if configured)
Registration Status Sensor
Monitors the SIP registration state for each account. Useful for alerting when your SIP connection drops.
| Entity ID | State | Description |
|---|---|---|
sensor.{prefix}_registration_{n} |
registered / unregistered / failed / unknown |
Registration state |
Attributes:
status_code: SIP status code (200 = registered)reason: Status reason textlast_change: ISO timestamp of last state change
Icons:
mdi:phone-check- Registeredmdi:phone-off- Unregisteredmdi:phone-alert- Failedmdi:phone-clock- Unknown (initial state)
Last Call Sensor
Tracks information about the most recent call on each account.
| Entity ID | State | Description |
|---|---|---|
sensor.{prefix}_last_call_{n} |
incoming / outgoing / none |
Direction of last call |
Attributes:
remote_uri: Full remote party URIlocal_uri: Full local SIP account URIparsed_remote_uri: Extracted remote party numberparsed_local_uri: Extracted local SIP account numbercall_id: SIP call IDtimestamp: ISO timestamp when call ended
Icons:
mdi:phone-incoming- Incoming callmdi:phone-outgoing- Outgoing callmdi:phone- No calls yet
Example Automations
Alert when SIP registration fails:
automation:
- alias: "SIP Registration Alert"
trigger:
- platform: state
entity_id: sensor.ha_sip_registration_1
to: "failed"
action:
- service: notify.mobile_app
data:
message: "SIP account 1 registration failed!"
Log last call:
automation:
- alias: "Log Incoming Calls"
trigger:
- platform: state
entity_id: sensor.ha_sip_last_call_1
to: "incoming"
action:
- service: logbook.log
data:
name: "Incoming Call"
message: "Call from {{ state_attr('sensor.ha_sip_last_call_1', 'parsed_remote_uri') }}"
SIP Header Extraction
You can extract specific SIP headers from incoming and outgoing calls and include them in all webhook events. This is useful for accessing custom headers like X-Caller-ID, P-Asserted-Identity, or any other SIP header your provider sends.
To configure header extraction, add the --extract-headers option to your SIP account:
sip:
enabled: true
registrar_uri: sip:provider.com
# ... other settings ...
options: '--extract-headers X-Caller-ID,P-Asserted-Identity'
The extracted headers will be included in all webhook events for calls on that account:
{
"event": "incoming_call",
"call_direction": "incoming",
"remote_uri": "<sip:[email protected]>",
"parsed_remote_uri": "5551234456",
"sip_account": 1,
"headers": {
"X-Caller-ID": "John Doe",
"P-Asserted-Identity": "<sip:[email protected]>"
}
}
Headers that are not present in the SIP message will have a null value. Header name matching is case-insensitive.
To discover which headers are available, enable --debug-headers in global_options:
sip_global:
global_options: '--debug-headers enabled'
This will log all SIP headers for each incoming and outgoing call to help you identify which headers to extract.
Examples
Trigger services through DTMF on an outgoing call
service: hassio.addon_stdin
data:
addon: c7744bff_ha-sip-ng
input:
command: dial
number: sip:**[email protected]
menu:
message: Press one to open the door, two to turn on light outside, three to play music
choices:
'1':
message: Door has been opened
action:
domain: switch
service: turn_on
entity_id: switch.open_front_door
'2':
message: Light outside has been switched on
action:
domain: light
service: turn_on
entity_id: light.outside
'3':
message: Play music
action:
domain: script
service: turn_on
entity_id: script.play_music_please
service_data:
variables:
song: 'Never gonna give you up'
Play a message without DTMF interaction on sip account 1
service: hassio.addon_stdin
data:
addon: c7744bff_ha-sip-ng
input:
command: dial
number: sip:**[email protected]
ring_timeout: 15
sip_account: 1
menu:
message: There's a burglar in da house.
Use PIN protection on outgoing call
service: hassio.addon_stdin
data:
addon: c7744bff_ha-sip-ng
input:
command: dial
number: sip:**[email protected]
menu:
message: Please enter your access code
choices_are_pin: true
timeout: 10
choices:
'1234':
id: owner
message: Welcome beautiful.
post_action: hangup
'5432':
id: maintenance
message: Your entrance has been logged.
post_action: hangup
'default':
id: wrong_code
message: Wrong code, please try again
post_action: return
'timeout':
id: timeout
message: Bye.
post_action: hangup
All the examples are working also for incoming calls when you copy the menu part into your incoming configuration yaml.
Troubleshooting
The first place to look is the log of the ha-sip app. There you can see individual SIP messages and the logs of ha-sip itself (prefixed with "|").
Stand-alone mode
The stand-alone mode can be used if you run home assistant in a docker environment and you don't have access to the hassio.addon_stdin service. Instead of stdin - MQTT will be used for communication.
docker-compose.yamlalready includes amosquittobroker (config inmosquitto/mosquitto.conf), published to127.0.0.1:1883on the Docker host and reachable fromha-sipthere too (it runs withnetwork_mode: host). Point Home Assistant's MQTT integration at that same broker/port so it can publish to and read from the topics below. If you'd rather use your own broker instead, remove themosquittoservice fromdocker-compose.yamland point step 3 below at it instead.Copy
.env.exampleto.envand replace the variable place-holders with your real configuration.In your
.envfile, enable MQTT throughGLOBAL_OPTIONSand point it at your broker, for example:GLOBAL_OPTIONS="--enable-mqtt --mqtt-address 127.0.0.1 --mqtt-port 1883 --mqtt-topic hasip/execute --mqtt-state-topic hasip/state"(add
--mqtt-username/--mqtt-passwordif your broker requires authentication -- the bundledmosquittoservice allows anonymous connections since it's only published to localhost)Install docker compose plugin
Run
docker compose --profile ng up -din the main folder of the repository to run the Kotlin ha-sip service together with themosquittobroker (a baredocker compose upstarts the Python app instead)Now you can use the
mqtt.publishservice in home assistant to send commands as json to the topic configured in--mqtt-topic(defaults tohasip/execute) from your automationsExample:
service: mqtt.publish data: payload: >- { "command": "dial", "number": "sip:**[email protected]", "menu": { "message": "Hello from ha-sip.", "language": "en" } } topic: hasip/executeYou can listen to call state events on the topic configured in
--mqtt-state-topic(defaults tohasip/state).
Testing this Kotlin port in Home Assistant
There are two ways to get this build running against a real Home Assistant instance:
Option A — install via the add-on store (uses a pre-built image)
- Add
https://github.com/arnonym/ha-pluginsas a custom add-on repository (badge above), then install "ha-sip-ng" from the store. - Home Assistant Supervisor reads
ha-sip-ng/config.json'simagefield (ghcr.io/arnonym/ha-plugins/{arch}-ha-sip-ng) and pulls that pre-built image from the GitHub Container Registry instead of building from source — this is standard Supervisor behavior for any add-on that declares animage. That means the image must already have been built and pushed by.github/workflows/build-ha-sip-ng.ymlfor the tag matchingconfig.json'sversionbefore installing this way. That workflow authenticates toghcr.iowith the built-inGITHUB_TOKEN(via the job'spackages: writepermission), so no registry secret has to be configured. Like the Python app's workflow, it runs the tests onmainandnextand builds and pushes the images (amd64 and aarch64) only fromnext— so bump theversiononnext, let the images build, then merge intomainto release. The image name is read fromconfig.json'simagefield rather than hard-coded, which is what lets the beta mirror reuse the same workflow file. - These test images live under
ghcr.io/arnonym/ha-plugins/{arch}-ha-sip-ng— completely separate from the productionagellhaus/{arch}-ha-sipDocker Hub images used by the Python add-on, so testing this port can never overwrite what existing users are running. Theha-plugins/part of the name gives this repository packages of its own: a GHCR package belongs to the repository whose workflow pushed it first, and only that repository'sGITHUB_TOKENmay push to it afterwards.
Note: A GHCR package is private when it is first created, and Supervisor pulls anonymously. After the very first successful push of a new image name, open the package under https://github.com/users/arnonym/packages, then Package settings → Change visibility → Public (once per package, i.e. per architecture and per channel). Installing while the package is private fails with a manifest/authentication error.
Option B — local add-on (Supervisor builds from source on your machine)
If you'd rather Supervisor build the image itself from this checkout (no registry push required, and you always get exactly what's in your working tree):
- Copy (or symlink) the
ha-sip-ng/directory into Home Assistant's/addons/local/folder (e.g. via the Samba or SSH/Terminal add-on) — as/addons/local/ha-sip-ng. - Remove the
"image": "ghcr.io/arnonym/ha-plugins/{arch}-ha-sip-ng",line from the copy'sconfig.json. As long asimageis set, Supervisor always pulls from the registry instead of building — removing it is what makes Supervisor build locally from theDockerfilein that folder instead. - In the Supervisor add-on store, find "ha-sip-ng" under "Local add-ons" and install it — this triggers an on-device build (multi-stage: pjproject + Java SWIG bindings, then the Kotlin app, then the runtime image), which will take a while the first time.
Either way, once installed you configure it exactly like described above in Installation — same options schema as the Python add-on.
Beta channel (the next repository)
The beta repository https://github.com/arnonym/ha-plugins-next
carries this app too, as ha-sip-ng-next with the images ghcr.io/arnonym/ha-plugins-next/{arch}-ha-sip-ng-next,
so testers can install it alongside the regular one — just don't run both against the
same SIP account/port at once.
For testers: add that repository URL in Home Assistant exactly like in Installation and install "ha-sip-ng-next".
For releasing a beta: push next, then run from the repository root:
mise run update-next-repo # keep both apps' versions
mise run update-next-repo 5.7-beta1 --ng-version 10.0-beta1 # or override them
Besides the Python app, it rewrites ha-sip-ng/config.json (name, slug, URL,
description, image, optionally version) and the repo/slug names in
README.md, then force-pushes the result to the beta repository's next
branch. Anything committed there directly is overwritten on the next run.
The build-ha-sip-ng.yml workflow is copied along and runs in the beta repository too.
It publishes images from next in both repositories, taking the image name from
config.json's image — which is why no separate workflow file is needed for the beta.
Because they push to ghcr.io with the built-in GITHUB_TOKEN, the beta repository needs
no secrets of its own; its first build does need the two new -ha-sip-ng-next packages
switched to public,
though.
Support
If you find this project helpful, please consider giving it a star ⭐ on GitHub! Your support helps others discover the project and keeps me motivated.
Development
This is a Gradle (Kotlin DSL) multi-module project — :core (pure Kotlin, no pjsip
dependency, host-testable) and :app (depends on :core plus the PJSIP Java SWIG
bindings).
Get pjsip's Java SWIG bindings (
pjsua2.jar+libpjsua2.so), either:mise run ha-sip-ng:setup:docker(or./gradlew :app:extractPjsua2Bindings) — builds thepjsip-bindingsstage ofha-sip-ng/Dockerfilein a container and copies the artifacts out (needs Docker/Podman), ormise run ha-sip-ng:setup(scripts/build-pjsua2-bindings-native.sh) — builds pjproject + the Java SWIG module directly on the host into an isolateddeps/ng/prefix (needsgcc/swig/libssl-dev/libopus-devinstalled locally, no Docker/Podman involved).
mise install— installs the pinned JDK (Temurin 25, matching the shipped runtime, seemise.toml).Copy
.env.exampleto.envand replace the placeholders with your real configuration (HA_BASE_URLis something likehttp://homeassistant.local:8123/api; the access token is created fromhttp://homeassistant.local:8123/profile).mise run ha-sip-ng:test(or./gradlew :core:testfromha-sip-ng/) — runs the:coretest suite, no Docker/pjsip involvement at all.mise run ha-sip-ng:build(or./gradlew buildfromha-sip-ng/) — full build including:app.mise run ha-sip-ng:run— runs the built jar locally with the correctLD_LIBRARY_PATH/-Djava.library.pathset automatically.Paste commands as JSON (without line-breaks) into stdin of the running app:
Example:
{ "command": "dial", "number": "sip:**[email protected]", "menu": { "message": "Hello from ha-sip.", "language": "en" } }
探索相关项目
加载中…