Thanks. Just looked into the code and tested by modifing protectnvr.py: doing the same check for camera[‘upsince’] what you already do for camera[‘lastMotion’] fixes my issue. Was about to create a git pull request for the same, but looks like you are already on top of it, so I leave it in your capable hands
(btw in init_.py the version number seems to be lagging behind - not a biggie, just thought about mentioning it)
Error should be fixed now, and I have made a new release V0.0.7. So if you installed via HACS it will show up soon, or you can just click the Integration and it will update.
Thanks for pointing out the error - funny how one always think that all possible scenarios have been tested, but there is always something you did not think about - Camera Offline was one of them.
Thanks, was able to upgrade and can confirm it is working fine.
A follow up question if I may - what would be the most convinient way to capture whether a camera is offline? In protectnvr.py I see that the online status is captured, but I don’t see that exposed as a state or attribute anywhere (I could be just overlooking something). The state of the camera entity is ‘recording’ even though it is offline. Maybe that also could be captured?
Edit: also, in camera.py could it be that an include for the ‘nvr’ namespace is missing? The second part of the my initial error message was related to that: NameError: name ‘nvr’ is not defined
Edit2:
File "/config/custom_components/unifiprotect/protectnvr.py", line 310, in get_snapshot_image
print("Error Code: " + response.status_code + " - Error Status: " + response.reason)
TypeError: can only concatenate str (not "int") to str
In protectnvr.py, you might want to convert the response.status_code to string in line 273, 294 and 310 as well.
Thanks
Version 0.0.8
A new release is now posted to Github. See changes below - and thank you for all the great feedback and for reporting the errors.
-
camera
:- Attributes update more frequently, to show recording mode and online status. Let me know if this causes any issues, as I achieve this by asking the Cameras to poll status every 30 seconds, and that is usually the case for a camera entity. In my own tests I have not seen any problems.
- Fixed missing import of core component
- Added Attribute online - Is true when the camera is Online else shows false. This attribute can be used to check if the camera is available before performing automations.
- Added Attribute up_since - showing time when camera went Online, or Offline if Camera is not connected
- Added Attribute last_motion - showing time within the last 24 hours, when motion was detected, if any.
- If the camera is not online, the recording state will now correctly be idle
-
core
:- Fixed missing string conversion of error code
- Fixed bug in error reporting, when Authentication Failed
Can some one please post a link for instructions to upgrade Protect to the correct code versions. I haven’t played with my protect code versions in several months and have lost the upgrade information. the current GA version does not work with this custom component.
You can find the instructions here: https://community.ui.com/questions/How-to-get-on-the-beta-release-channel/c26acdf8-321c-49b6-8f0d-9d7d99bf6aee
You need to be logged in to see the page.
Thanks, That was straight forward enough but still no joy. When I look at the local user in Protect I see that it never authenticates. I have added the entries into my configuration.yaml. Is there logging I can look at to see if the component is trying to authenticate?
unifiprotect:
host: 192.168.1.xxx
username: <my username>
password: <my password>
Just chiming in with my thanks to @briis for this.
I’ve been watching the repo in github and been really impressed with the turnaround time on fixes and enhancements. Looking forward to replacing my hacky Protect > MotionEye > HA integration with the custom component at the weekend.
Hi,
If it is Authentication that fails you will get the following error in the Home Assistant Log:
Log Details (ERROR)
Mon Jan 06 2020 15:31:19 GMT+0100 (Central European Standard Time)
Authorization failure while connecting to NVR
if your Log Level is set to error
or higher.
Also try and connect to Unifi Protect on the Local IP Address, and login with the local user you created, just to check if it works.
I am not seeing anything…
~ $ hassio homeassistant logs | grep unifiprotect
2020-01-06 12:28:44 INFO (SyncWorker_7) [homeassistant.loader] Loaded unifiprotect from custom_components.unifiprotect
2020-01-06 12:28:44 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for unifiprotect which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.
I was able to verify the user and the custom component is loading. and I can now see the services but no devices. I am at a loss.
@cdrom1028. Just to make sure. Beside adding the platform unifiprotect
to your configuration.yaml, you did also add:
camera:
- platform: unifiprotect
and
sensor:
- platform: unifiprotect
and
binary_sensor:
- platform: unifiprotect
Without any of these, nothing will show up in your device list.
If that is the case, let me put in a few more debug messages in the files, so that we can check if anything gets loaded.
oh SNAP! that was it…
thanks for the help!
You are welcome
Version 0.0.9
Yet another release. Should be available on HACS in few minutes.
-
camera
:-
BREAKING CHANGE The service
camera.unifiprotect_save_thumbnail
has been removed, and has been replaced by a new Service you can read more about below. The implementation was not done according to Home Assistant standards, so I decided to rewrite it. If you use this Service in any automation, please replace it with the new Service. - A new Service with the name of
unifiprotect.save_thumbnail_image
has been created. This Service does exactly the same as the old service, but now it conforms to Home Assistant standards, and when you select it in the Services area under Developer Tools you will now see a proper Service Description. A new optional parameter has been added calledimage_width
. Here you can specify the width of the image in pixels, and the height will then be scaled propotionally.
-
BREAKING CHANGE The service
-
core
:- The function
set_camera_recording
was not using the request.session, resulting in occasional authentication errors.
- The function
Hi Briis,
First of all - thank you for this nice integration! Much appreciated.
A fellow dane by the way ;).
A quick question, do you experience any large difference when using the “medium” RTSP stream rather that the low option? Does it takes longer to load in Home Assistant etc.?
I just did a test on a few cameras and I did not notice any significant load time, betweem a G3 Flex Camera with Low resolution and a G4 Pro with High Resolution. Even though the latter streams with a lot higher FPS.
Are you asking because you see longer load times?
P.S. Godt nytår (Danish)
Godt nytår .
Actually it looks like I got some speed improvement when I open up the Lovelace view where I have my 4 G3 cams. Maybe it is a coincidence, but that’s just what I noticed. I am still running on low, but maybe I would try to set up the quality, I just don’t want to wait too long and I don’t want to use a lot of bandwidth on my Lan. Low stream does still do an OK job.
Now I just need to adjust my Deepstack to only get Triggered when both my cameras report the ‘motion detected’ and my Motion Detector sensors gets Triggered. Then I should be eliminating some of all the false positives.
Maybe I should also try the thumbnail thing you can get from the camera now. I guess that is the picture it takes from when the Motion occurs and then it fetches or at leat tries to, when the object was in front of the camera.
We will see
The binary_sensor for the motion detection (the actual movement detection), for how long will the motion sensors state be “on”. As loong as there is any movement or only for xx amount of time?
Hi Yoinkz,
The binary_sensor is triggered by scanning the Event Log. In that log there are Start and End fields. The End field is empty as long as motion is detected. So I check the End field for a value, and as soon as there is a value, the sensor will switch to off. As the log is only pulled every 3 seconds there can be a delay for this amount of time until the sensor is off.
Thanks! Makes sense!