duanemck / ezviz.net

Experimental .net library for interacting with the Ezviz API. Based on the excellent work in https://github.com/BaQs/pyEzviz
MIT License
4 stars 0 forks source link

MQTT Auto Discovery #7

Closed rezzalex closed 9 months ago

rezzalex commented 1 year ago

Hello.

Would it be possible to able auto discovery topics, so that devices would be automatically created by Domoticz MQTT auto discovery feature ?

duanemck commented 1 year ago

I had started looking at auto discovery for Home Assistant but I hit some blockers in the architecture of the app so I put it on pause. It was a while ago so I'll need to remind myself what the issue was and tackle it again.

The most recent commits to main to have some of that code, it's just commented out for now.

duanemck commented 1 year ago

Does Domoticz use the same Auto Discovery protocol as HA?

rezzalex commented 1 year ago

I am pretty sure that the answer is yes : https://www.domoticz.com/wiki/MQTT#MQTT_Autodiscovery_Setup

rezzalex commented 11 months ago

Hello @duanemck ,

Any news on this MQTT autodiscovery feature ?

duanemck commented 11 months ago

Hi @rezzalex , I made some good progress on this back in May but then hit a snag where I couldn't figure out how to set the RTSP url in the auto-discovery message. Life then got in the way and I got distracted.

I'll see if I can pick it up again this weekend, I might be able to release a BETA version for you to try out based on where I am at the moment.

rezzalex commented 11 months ago

Thanks a lot !!! That would be wonderful!

Don't bother too much regarding RTSP URL, in my case, Domoticz can only visualise MJPEG streams, not RTSP !

duanemck commented 10 months ago

I've pushed a preview version of the Docker image to duanemck/ezviz-mqtt:preview-auto-discover or duanemck/ezviz-mqtt-arm:preview-auto-discover if you're using ARM

rezzalex commented 10 months ago

Thanks a lot,

I will test that ASAP:

How/where can I specify the auto-discovery prefix ?

is it "serviceLwtTopic" ?

duanemck commented 10 months ago

Hmm, I think that was a bit of an oversight on my part. It's currently hardcoded as homeassistant/{device_class}/{node_id}/{unique_id}/config I see that Domoticz uses homeassistant by default but that it can be changed, I'll quickly add a config option.

serviceLwtTopic is the LWT topic for the whole ezvizmqtt app, so you can determine if it has crashed and is no longer monitoring the camera.

rezzalex commented 10 months ago

I think It would be great to have it as a modifiable option because I am already using the "homeassistant" prefix for ZwaveJsUI, and I think I will create a new and specific "MQTT auto discovrey hardware" in DZ, just for having a specific prefix as recommended here :

image

duanemck commented 10 months ago

OK, pushed a new version to the same tag. Under mqtt, there is a new property called autodiscoverPrefix, it will default to homeassistant but you can update it to match your config.

rezzalex commented 10 months ago

I have experienced an error 500 while updating the container with the new image and this while using docker-compose : image

rezzalex commented 10 months ago

I have change the 2 port on host system, like this :

ports:

  • "8086:8081/tcp"
  • "8087:8082/tcp"

then I had tis error :

image

rezzalex commented 10 months ago

OK, I don't know why, it worls now, but... here si the Domoticz error messages :

Error: Value is not convertible to bool.! (topic: homeassistant/select/ezvizmqttnet_fd3d7c9dd41741f0bb99405af57725a2/ezviz_fd3d7c9dd41741f0bb99405af57725a2_defencemode/config, message: {"command_topic":"ezviz/cmnd/global/defenceMode","state_topic":"ezviz/stat/global/defenceMode","options":["Home","Away"],"availability":[{"topic":"ezviz/lwt","payload_available":"ON","payload_not_available":"OFF"}],"availability_mode":"latest","device":{"connections":[],"identifiers":["ezvizmqttnet_fd3d7c9dd41741f0bb99405af57725a2"],"manufacturer":"duanemck","model":"","name":"EzvizMQTT.NET"},"enabled_by_default":"ON","encoding":"utf-8","entity_category":"config","name":"Ezviz Defence Mode","unique_id":"ezviz_fd3d7c9dd41741f0bb99405af57725a2_defencemode"} 2023-08-07 15:45:57.790 Error: Zwave: MQTT_Discovery (on_auto_discovery_message): Error: Value is not convertible to bool.! (topic: homeassistant/select/ezviz_C67332781/ezviz_C67332781_alarmsound/config, message: {"command_topic":"ezviz/status/C67332781/alarmsound/set","state_topic":"ezviz/status/C67332781/alarmsound","options":["Normal","Intensive","Disabled","Unknown"],"availability":[{"topic":"ezviz/lwt/C67332781","payload_available":"ON","payload_not_available":"OFF"}],"availability_mode":"latest","device":{"connections":[["MAC","d0c5d3b43dcf"]],"identifiers":["ezviz_C67332781"],"manufacturer":"Ezviz","model":"BatteryCamera C3A","name":"Est","sw_version":"V5.2.4 build 211115"},"enabled_by_default":"ON","encoding":"utf-8","entity_category":"config","name":"Est AlarmSound","unique_id":"ezviz_C67332781_alarmsound"} 2023-08-07 15:45:57.893 Error: Zwave: MQTT_Discovery (on_auto_discovery_message): Error: Value is not convertible to bool.! (topic:

duanemck commented 10 months ago

Hmm, the only thing I suspect is that I'm sending a boolean value as ON/OFF as HomeAssistant supports that, maybe Domoticz doesn't. Luckily this is configurable: Under json there is a setting called serializeBooleans, it's set to 1 by default which means serialize to string. Change it to 0 which will cause it to just write true/false.

The other error about ports is related to a health check plugin that I haven't managed to get working in Docker. You can ignore the error for now but I will update it so it can be switched off in future.

duanemck commented 10 months ago

The other issue about "Not a directory" is caused by something going wrong when consuming the ezviz API, usually it's a response message with a property missing or something unexpected.

The app tries to log the response for further debugging, the location is configurable in polling -> requestLogLocation, normally /dev/null on Linux just writes the file nowhere, perhaps on the container this doesn't work.

This error shouldn't stop the app from running, on the next API poll it will hopefully get a valid message back.

rezzalex commented 10 months ago

It works !! 25 devices created for each C3A Cam ! arming is working just fine, I need to play around with all the rest

Thanks a lot ! you should probably communicate a bit that this is now working with Domoticz !

duanemck commented 10 months ago

That is awesome to hear! I'm going to run it for a bit on my local system and then I'll release it to the main tag. I'll also update the docs to reflect the Domoticz compatibility.

rezzalex commented 10 months ago

If you need help screen captures, feel free to ask

rezzalex commented 10 months ago

Hello,

Some feedback :

Regarding the alarm :

As it occured only when there is a real alarm, autodiscovery does not seems to work for alarm topic :

I have explicitly set this in the conf file :

"topics": { "alarm": "ezviz/alarm/XXX",

It was working in the MQTT message, but nothing in Domoticz, when provoking a motion detection when cam was armed....

to help, here is my alarm MQTT message for my C3A :

{"alarmId":"LL2DZ9CZ7PS_1H7FEIG0C_D67745001_1","deviceSerial":"_XXXXX_","channelNo":1,"channelType":1,"alarmName":"Sud","alarmType":10000,"alarmStartTime":1691504287523,"alarmStartTimeParsed":"2023-08-08T14:18:07","alarmStartTimeStr":"2023-08-08 14:18:07","isCheck":0,"isVideo":0,"isEncrypt":0,"isCloud":0,"picUrl":"_xxxxxx_","recUrl":"","recState":4,"picUrlGroup":"_xxxxxxxxx_","sampleName":"PIR Event","preTime":5,"delayTime":25,"withTinyVideo":0,"alarmMessage":"Sud PIR Event","crypt":0,"analysisType":0,"hasValueAddedService":false,"downloadedPicture":"/xxxx

Please find below some possible fix /enhancements :

Globally, as it is about autoDiscovery, what is really needed inside the conf file, if everything is auto discovered ?

rezzalex commented 10 months ago

Hello @duanemck ;

did you have time to review my last comments?

rezzalex commented 10 months ago

Also, When arming my cam from another source that ezviz mqtt, Domoticz seems to believe it has sent an (MQTT) command to all EzViz devices, even if this device is not supposed to be actionable, generating errors.

duanemck commented 10 months ago

Thanks very much for the feedback, I haven't had a chance to dig into the detail just yet.

rezzalex commented 10 months ago

Hello @duanemck ,

I saw you have created all the tickets and also release the MQTT auto discovery in stable version. Thank you for that. Is there any change regarding the version I have already tested ?

duanemck commented 10 months ago

Hi, it's been a very busy few weeks with kids birthdays. Hoping I'll have some time soon to look into the issues your reported.