Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic SIP server for doorbells #409

Open
felipecrs opened this issue May 4, 2023 · 21 comments
Open

Basic SIP server for doorbells #409

felipecrs opened this issue May 4, 2023 · 21 comments
Labels
dahua Dahua cameras, VTO, SIP enhancement New feature or request

Comments

@felipecrs
Copy link
Contributor

This project never stops surprising me. It is like the always missing glue for cameras and smart homes. And I have another suggestion.

An embedded and very basic SIP server that doorbells like Dahua VTO or Hikvision can connect to.

go2rtc has 2-way audio support for doorbells, which is awesome. But that's not enough for a fully functional doorbell setup. In other words, a SIP server is still required even though go2rtc can do 2-way audio.

That's because the doorbell still needs to signal and receive signals to react on certain events like:

  • Doorbell is calling
  • Call has been accepted
  • Call has been ended

In my understanding, if go2rtc could expose a basic SIP server in which the doorbell could connect to, no other project like the Asterisk add-on would be required (Asterisk is VERY hard to manage, and overkill for the purpose).

go2rtc as a SIP server would:

  • Allow to receive calls from the doorbell (i.e. it would let the doorbell call it and ring)
    • When the VTO doesn't have a SIP server configured to accept a call from it, it basically doesn't work.
    • Users can then create Home Assistant cards and automations to notify when the doorbell is ringing
  • Send the call accepted signal to the doorbell as soon as some 2-way audio connection is established
  • Send the call ended signal to the doorbell as soon as that 2-way audio connection is dropped

Luckily, there seems to be some good SIP servers written in golang out there:

So, what do you think?

Refs #49

@AlexxIT AlexxIT added the enhancement New feature or request label May 5, 2023
@AlexxIT
Copy link
Owner

AlexxIT commented May 5, 2023

I knows nothing about SIP technologies and didn't have any hardware that using it.

@felipecrs
Copy link
Contributor Author

That's sad, but thank you.

I know very little of Golang, but nevertheless I'll try to build something.

@felipecrs
Copy link
Contributor Author

It does not look very difficult according to the examples of https://github.com/emiago/sipgo. However, my doorbell is in a very inaccessible place which makes it very hard for me to work with it.

But I will try to build something when I get a chance.

@AlexxIT
Copy link
Owner

AlexxIT commented May 10, 2023

Can your doorbell works with this integration?
https://www.home-assistant.io/integrations/voip/

@felipecrs
Copy link
Contributor Author

felipecrs commented May 10, 2023

I don't think so. That does not even look like SIP also.

I think that integration only works with the Grandstream conversor for old analog phones.

I don't think that integration talks to the conversor over SIP either. Maybe I'm wrong.


Off topic, SIP itself could be used as a 2-way audio source provider. In fact, even as a video source.

But what I'm suggesting is way simpler than that, which is to make go2rtc to expose a SIP server on port like 5060.

Then I would configure my doorbell to use go2rtc as the SIP server.

On the go2rtc side, apart from exposing the SIP TCP server on port 5060, it would:

  • Accept the registration of the doorbell (checks the username and password authentication)
  • Allow the doorbell to ring (it should send the "call in progress" signal back to the doorbell)
  • When someone connects to the 2-way audio stream with microphone, send the call accepted signal.
  • Maybe send the hangup signal on some other occasion.

I currently use the Asterisk add-on https://github.com/TECH7Fox/asterisk-hass-addons with the SIP card to be able to call with my doorbell from Home Assistant https://github.com/TECH7Fox/sip-hass-card.

Cc @pergolafabio @nanosonde which are the most experienced people I know about SIP.

(Sorry to ping you both, if you don't care about this please unsubscribe)

Any opinion is appreciated. I don't know if the approach I suggest actually makes sense or is feasible. Maybe I'm just crazy.

@felipecrs
Copy link
Contributor Author

Oh wait! The VoIP integration for Home Assistant seems to be SIP indeed. I'll do some testing with it.

@pergolafabio
Copy link

Yes, the voip is indeed a sip, but be careful, it only works with opus codec, and remember to change port to something else then 5060 if you have asterisk running...

But anyway, I don't see the point for calling to HA to speak to assist anyway :-)

@AlexxIT
Copy link
Owner

AlexxIT commented May 10, 2023

But I can easily read code of voip integration and reproduce it with go2rtc. I saw how they accept connection on 5060 port and answer to it.

You right. They using OPUS/48000/2. I can change it to PCM/16000/1

@felipecrs
Copy link
Contributor Author

As realized in rroller/dahua#359 (comment), the Dahua VTO is useless when NOT CONNECTED to a SIP server. Even the most basic function of button press event will not work when it's not connected to a SIP server.

I detailed my VTO setup on Home Assistant (https://github.com/felipecrs/dahua-vto-on-home-assistant) and I use go2rtc for 2-way audio communication, but I still need to run the full Asterisk add-on just to have a SIP server for my VTO to connect to and therefore allow me to capture the button press event to run automations on.

After these realizations, just to reiterate, if go2rtc could expose a simple SIP server for the doorbell to connect to, I could get rid of Asterisk in my setup which would make things a lot easier.

@felipecrs
Copy link
Contributor Author

Can your doorbell works with this integration? https://www.home-assistant.io/integrations/voip/

By the way, I tried making it work with that integration and I could not. No matter what, the doorbell would not connect to it. I don't have much details though.

@felipecrs
Copy link
Contributor Author

I will try making some tests with:

https://github.com/emiago/sipgo/tree/main/example/register

@felipecrs
Copy link
Contributor Author

OMG! I can't believe, it worked in the first attempt!

~\repos\sipgo\example\register main ❯ go run ./server -u "8001:somepass" -ip 0.0.0.0:5060
May 30 11:53:33.797517 INF Listening on addr=0.0.0.0:5060
May 30 11:53:42.670412 INF New client registered source=192.168.1.40:5060 username=8001
May 30 11:57:34.866194 WRN Server > SIP request handler not found
May 30 11:57:34.888231 WRN Server > SIP request handler not found
May 30 11:57:34.976455 WRN Server > SIP request handler not found

192.168.1.40 is my VTO. It registered in gosip immediatelly with no issue.

image

And everything worked as expected. The button press event is emitted and I don't need SIP for anything else.

@AlexxIT, it would be awesome if you could bundle this in go2rtc. What do you think?

@AlexxIT
Copy link
Owner

AlexxIT commented May 30, 2024

I'll try when have time for my two doorbells

@wiking-at
Copy link

hi, I join in here. I have a Loxone smarthome and use Hikvision DS-K1T342MFWX Door Stations. Using go2rtc I was able to grab the video of the door stations and transcode them to the mjpeg stream loxone needs. I wrote a small udp listener (container with python script parsing the udp sip frame) waiting for the sip call of the door station and trigger the doorbell/loxone app with it. this works fine.

Unfortunately the Door Station is not listening for SIP-Invites - the only possibility to talk to visitors is using ISAPI/Two-Way-Audio. On the other hand, the only possibility for Loxone to connect to Door Stations is doing an outbound SIP-Call.

So if I read this issue right go2rtc might be able to be the missing glue.

Would it somehow be possible to connect to a go2rtc SIP-Listener which connects audio to the two-way audio stream?
Or am I thinking to complicated here and there would be a more easy way?

If someone is interested in the python script I can clean it up a bit and share it.

@pergolafabio
Copy link

im' interested

i also use the two way audio for my hikvisvion device
i have indoor stations , so i use the hikvision addon to first send the callsignal to abort the ringing, then i start two way audio

@wiking-at
Copy link

@pergolafabio
Here you go:
https://gist.github.com/wiking-at/fc30228cee8bff3cefca975b48119b28

@pergolafabio
Copy link

Ty, will have a look after

@pergolafabio
Copy link

That will only work probably without indoor station? Don't think you can call callcenter and indoor center at same time

@wiking-at
Copy link

if you have an indoor station it should be easier afaik - as you can use it to set up sip. - and maybe configure the indoor station to forward the call to the udp listener for the mqtt processing.

I don't have an indoor station and would prefer to just use a tablet with Loxone App (or home assistant app if Loxone doesn't work out).

@pergolafabio
Copy link

Yeah, but I want to avoid SIP, I have an sip script to use a script to register as extension, so I can forward the call from indoor...
Don't think it's possible to call indoor and callcenter at same time, without sip

@wiking-at
Copy link

i see.. as the outdoor station can always only call one ip this is hard. possible solutions - proxy from helper to indoor station or mirror and inspect traffic to indoor station - both solutions not really viable. your current solution seems much better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dahua Dahua cameras, VTO, SIP enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants