rroller / dahua

Dahua Camera and Doorbell Home Assistant Integration
MIT License
369 stars 71 forks source link

Button press sensor only fires if the doorbell is connected to SIP #359

Closed felipecrs closed 1 month ago

felipecrs commented 1 month ago

I have a VTO2202F-P-S2, and I am building a guide to make it work with Home Assistant without the VTH or the Cloud services.

Everything works great, including the button press sensor of this integration.

However, if I disconnect the SIP server, the button press sensor no longer changes/fires. Which is sad for me because this means I need a full-blown Asterisk server just for this.

So, I wonder if there's any alternative.

I will try capturing the event logs later.

felipecrs commented 1 month ago

This is the only event that fires in such case:

--myboundary
Content-Type: text/plain
Content-Length: 74

Code=SIPRegisterResult;action=Pulse;index=0;data={
   "Success" : false
}

--myboundary

At least it appears to be consistent.

felipecrs commented 1 month ago

According to my tests, the same event is not triggered when SIP is connected normally.

I think it's a good idea to also check for this event to consider the doorbell button pressed. @rroller, what do you think?

myhomeiot commented 1 month ago

@felipecrs if you need all events from Dahua VTO including doorbell button press, you can try my integration which is just about events and commands, it's should works without active SIP connection.

felipecrs commented 1 month ago

Hi @myhomeiot, that is really helpful. Thank you.

But I have some automations based on this integration and would prefer not to change it.

I believe this is just a corner case that can be fixed by adding one extra condition here:

https://github.com/rroller/dahua/blob/583165c0dd7cfece5a1a42d09dd6f2291017a0d1/custom_components/dahua/__init__.py#L503-L506

myhomeiot commented 1 month ago

@felipecrs It's already check the BackKeyLight code which generated if someone press the doorbell button, so it's should work. You can check if your VTO sends this event without SIP server setup.

felipecrs commented 1 month ago

You can check if your VTO sends this event without SIP server setup.

Isn't this what I did?

This is the only event that fires in such case:

--myboundary
Content-Type: text/plain
Content-Length: 74

Code=SIPRegisterResult;action=Pulse;index=0;data={
   "Success" : false
}

--myboundary

At least it appears to be consistent.

I was using the following command:

curl -s --digest -u admin:$DAHUA_PASSWORD  "http://192.168.1.203/cgi-bin/eventManager.cgi?action=attach&codes=[All]&heartbeat=5"

Also, if the VTO was sending out the BackKeyLight code event I suppose the button press sensor would be working.

Please let me know if I did something wrong.

myhomeiot commented 1 month ago

I was using the following command:

I check events from my VTO using this command and it's doesn't show any BackKeyLight events at all, I think this is a limitation of eventManager.cgi HTTP. But this integration definitely receives it using DHIP connection. The question is if it's still generated when no active SIP connection.

felipecrs commented 1 month ago

Oh, I see. Do you know of an easy way to subscribe to all events, including these BackKeyLight, so that I can test here?

myhomeiot commented 1 month ago

Oh, I see. Do you know of an easy way to subscribe to all events, including these BackKeyLight, so that I can test here?

I think the simplest way will be installing my integration (it's can work in parallel with this integration) and check all coming dahua_vto events from Developer Tools->Events or by this simple automation Dahua VTO All Events

felipecrs commented 1 month ago

Sounds good. I will report back once I have the data for this test. Thank you!

smol84 commented 1 month ago

I sitll have this issue, anyone else?

felipecrs commented 1 month ago

I sitll have this issue, anyone else?

Also when the doorbell is disconnected from SIP?

felipecrs commented 1 month ago

Ok, @myhomeiot I finished testing events using your integration. The result is:

The SIPRegisterResult is just fired from time to time, I guess it's the VTO attempting to connect to the SIP server.

This means the VTO is useless when not connected to a SIP server and nothing can be done to capture the button press in such case, I think, therefore I am closing this issue.

However, it is not very difficult to run the Asterisk add-on to have a SIP server the doorbell can connect to. That's what I do.

myhomeiot commented 1 month ago

@felipecrs Thanks for the update! Can you try to use VTO local SIP server if you have this option?

image

felipecrs commented 1 month ago

This is what I was trying first. Same results. No event emitted. And immediately after pressing the button the doorbell says "The call was not answered". Which is the same as when the doorbell is not connected to SIP.

felipecrs commented 1 month ago

I think for this option to work, it needs a VTH connected. Or some extension connected to the VTO SIP Server so the VTO can call it.

convicte commented 1 month ago

@felipecrs I am really interested in your efforts to integrate the Dahua VTOs with HA and am already really impressed with your progress.

kudos.

This said I am struggling to understand the issue you are having with capturing the button presses. While I am not using @myhomeiot integration right now (may switch if need be), since it was predated by https://github.com/rroller/dahua which worked as well, there is really no issue in getting the button presses into HA.

It may be that I am missing some important detail here. If you could please explain, maybe we can figure it out.

BTW, my SIP is also set up to be enabled on device and I don't have a Dahua VTH panel, nor any panel for this matter. Just using the VTO as a camera and a dumb doorbell ringer.

Screenshot_20240531_004014_Firefox.jpg

felipecrs commented 1 month ago

@convicte, this is surprising to me. Can you please share some more details?

What did you fill in this page exactly?

What number is the VTO configured to call? Default is 9901 I think.

What does the VTO say (voice prompt) when you press the button? Is it "Calling now"?

And finally, you mean the binary_sensor.button_press is working normally for you when using the built-in SIP Server and no VTH?

Maybe it has something to do with firmware version. I am using latest from Dahua website,

DHI-VTO2202F-P-S2 4.600.0000000.0.R,build:2022-08-13

Or maybe my model behaves differently than yours.