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

[ipcamera] Dahua / Amcrest floodlight cameras could have controls for the floodlight state #15118

Closed
jshatch opened this issue Jun 19, 2023 · 27 comments · Fixed by #16144
Closed
Labels
enhancement An enhancement or new feature for an existing add-on

Comments

@jshatch
Copy link

jshatch commented Jun 19, 2023

Your Environment

  • Version used: openHAB 4.0.0, Build 3469
  • Environment name and version (e.g. Chrome 76, Java 8, Node.js 12.9, ...): Any
  • Operating System and version (desktop or mobile, Windows 10, Raspbian Buster, ...): Ubuntu 22.04

It doesn't appear that there are any channels configurable in the ipcamera binding for controlling the flood lights on the Amcrest ASH26 / Dahua IPC-L26N. The API endpoints are there, I have successfully used them in a script to toggle the light state.

It would be super nice if this was included in the binding so I could control the light state from openhab without resorting to using the http binding. There is a similar channel already that controls the IR light.

@jshatch jshatch added the enhancement An enhancement or new feature for an existing add-on label Jun 19, 2023
@Skinah
Copy link
Contributor

Skinah commented Jun 24, 2023

What API call are you using that works with your camera? Does it match one of these already implemented ones? The channel enableLED can accept a dimmer value or ON and OFF commands.

Some cameras have IR lights, and others have Flood white lights and others will have a RELAY output for turning external lights on and off.

            case CHANNEL_ENABLE_LED:
                ipCameraHandler.setChannelState(CHANNEL_AUTO_LED, OnOffType.OFF);
                if (DecimalType.ZERO.equals(command) || OnOffType.OFF.equals(command)) {
                    ipCameraHandler.sendHttpGET("/cgi-bin/configManager.cgi?action=setConfig&Lighting[0][0].Mode=Off");
                } else if (OnOffType.ON.equals(command)) {
                    ipCameraHandler
                            .sendHttpGET("/cgi-bin/configManager.cgi?action=setConfig&Lighting[0][0].Mode=Manual");
                } else {
                    ipCameraHandler.sendHttpGET(
                            "/cgi-bin/configManager.cgi?action=setConfig&Lighting[0][0].Mode=Manual&Lighting[0][0].MiddleLight[0].Light="
                                    + command.toString());
                }
                return;
            case CHANNEL_AUTO_LED:
                if (OnOffType.ON.equals(command)) {
                    ipCameraHandler.setChannelState(CHANNEL_ENABLE_LED, UnDefType.UNDEF);
                    ipCameraHandler.sendHttpGET("/cgi-bin/configManager.cgi?action=setConfig&Lighting[0][0].Mode=Auto");
                }

@jshatch
Copy link
Author

jshatch commented Jun 24, 2023

My camera has both IR and a flood light, the channel mentioned only controls the IR illuminator light. The dimmer values do increase / decrease the brightness of the IR LED next to the camera lens (verified visually by watching the soft red glow increase / decrease as I moved the slider) but do not affect the larger visible flood light.

The API calls I'm using are the ones found here: tchellomello/python-amcrest#161 (comment)

Looks like you are using the Lighting parameter and I'm using Lighting_V2

@jshatch
Copy link
Author

jshatch commented Aug 23, 2023

Is there any further comment on this request?

@stale
Copy link

stale bot commented Oct 24, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale As soon as a PR is marked stale, it can be removed 6 months later. label Oct 24, 2023
@jshatch
Copy link
Author

jshatch commented Oct 24, 2023

Sorry if this was awaiting my feedback I haven't seen anything since the question about the API endpoint I was using. If there isn't any interest in providing this functionality that's fine. A comment to that point would be helpful in that case.

@stale stale bot removed the stale As soon as a PR is marked stale, it can be removed 6 months later. label Oct 24, 2023
Copy link

stale bot commented Dec 23, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale As soon as a PR is marked stale, it can be removed 6 months later. label Dec 23, 2023
@jshatch
Copy link
Author

jshatch commented Dec 23, 2023

@Skinah I'm assuming at this point that nothing will come of this request? I know it isn't a super exciting request but maybe I should share why I would like it.

I have my floodlight camera on a switch right now, the switch has to always be on for the camera to work so I have to always have the floodlight set to motion enabled. However sometimes (like when I'm cooking on the grill) it would be nice to have the light on always. Right now I have to use the Amcrest app to do that but if I could control it with OpenHAB I could even use a z-wave scene controller to turn it on and off like a regular light while keeping the camera powered always.

If this request isn't worth the time that's fine, I'll make do. But if there is any value found on your side in implementing this I would really appreciate it.

@stale stale bot removed the stale As soon as a PR is marked stale, it can be removed 6 months later. label Dec 23, 2023
@Skinah
Copy link
Contributor

Skinah commented Dec 27, 2023

Try the zipped jar that is here:

http://pcmus.com/openhab/IpCameraBinding/

sourcecode changes are found here:
https://github.com/Skinah/openhab-addons/tree/ipcamera

@jshatch
Copy link
Author

jshatch commented Dec 27, 2023

The binding installs but displays this message:

No thing types can be added with this binding.

Going back to the original version brings back the list of installable things.

@Skinah
Copy link
Contributor

Skinah commented Dec 27, 2023

I just uploaded a new version I have spent the last hour testing here and fixed an issue.

@jshatch
Copy link
Author

jshatch commented Dec 27, 2023

The thing types work now, I was able to configure the camera, and I see the white LED channels you added.

The item type defaults to dimmer, but that does not work as the light doesn't support that. Changing it to switch works
The light only comes on for a second then turns off on its own. The link I out in my first reply to you has the ordering of the API calls that can control the light. Even if I turn off auto white LED using that channel the light won't stay on for more than a second.

@jshatch
Copy link
Author

jshatch commented Dec 27, 2023

If I go into the Amcrest app and disable motion control the switch item works as expected. So the auto white LED item doesn't look like it's doing what it should.

@Skinah
Copy link
Contributor

Skinah commented Dec 27, 2023

I can not test these commands as my camera replies with Bad Request! so I need you to enable TRACE logs which will tell you exactly what the binding is sending and what the camera replies with. Then let me know what needs to change, please do not expect me to read 1,000+ words and guess when you have a camera and can test it exactly.

@jshatch
Copy link
Author

jshatch commented Dec 27, 2023 via email

@Skinah
Copy link
Contributor

Skinah commented Dec 27, 2023

Make a call to this endpoint and note the settings that get reported.
/cgi-bin/configManager.cgi?action=getConfig&name=Lighting_V2

One of the settings that the camera may have is to turn the light back off after x seconds. LightDuration

Also another reason is you may be changing the day profile setting when the camera is in night profile.
profile_mode: 0=day, 1=night, 2=scene

Also this link has a lot of the possible urls listed:
https://github.com/rroller/dahua/blob/main/custom_components/dahua/client.py

/cgi-bin/configManager.cgi?action=setConfig&Lighting_V2[{channel}][{profile_mode}][0].Mode=Manual&Lighting_V2[{channel}][{profile_mode}][0].MiddleLight[0].Light=100

@Skinah
Copy link
Contributor

Skinah commented Dec 27, 2023

"The item type defaults to dimmer, but that does not work as the light doesn't support that. Changing it to switch works"

The binding should still work. Can you test it with a dimmer as a value of 0 or OFF should both turn the light off, this should work right now as both are handled the same way. Then any value should turn the light on if the camera does not support dimming. This may need a change to the URL called and it is possible the camera will not allow two commands to be sent in the one URL arguments which your thread linked did indicate for some cases this happens. Worth trying to achieve it first as older firmware may not have done it, but newer may.

Both of these should be tested on your camera, as it is common for features to work even if your cameras UI is missing the control.
.MiddleLight[0].Light=100
.PercentOfMaxBrightness=100

That is why it is worth checking what your camera with this url:
/cgi-bin/configManager.cgi?action=getConfig&name=Lighting_V2

@jshatch
Copy link
Author

jshatch commented Dec 28, 2023

The binding should still work. Can you test it with a dimmer as a value of 0 or OFF should both turn the light off, this should work right now as both are handled the same way. Then any value should turn the light on if the camera does not support dimming.

When the item type is set to dimmer, no value I assign to it will change the light state from OFF (0). Setting type to switch does toggle the light state.

Both of these should be tested on your camera, as it is common for features to work even if your cameras UI is missing the control.

As for the above commands, Lighting_V2[0][0][1].NearLight[0].Light is the one that controls the white light output. Values are 0-48=off, 49=dim, 50-100=full
.PercentOfMaxBrightness=100 is not accepted by the camera and returns Error.

The output of /cgi-bin/configManager.cgi?action=getConfig&name=Lighting_V2 is:

table.Lighting_V2[0][0][0].Correction=50
table.Lighting_V2[0][0][0].LightSwitchDelay=0
table.Lighting_V2[0][0][0].LightType=InfraredLight
table.Lighting_V2[0][0][0].MiddleLight[0].Angle=50
table.Lighting_V2[0][0][0].MiddleLight[0].Light=50
table.Lighting_V2[0][0][0].Mode=Auto
table.Lighting_V2[0][0][0].Sensitive=3
table.Lighting_V2[0][0][1].Correction=50
table.Lighting_V2[0][0][1].LightSwitchDelay=0
table.Lighting_V2[0][0][1].LightType=WhiteLight
table.Lighting_V2[0][0][1].Mode=Manual
table.Lighting_V2[0][0][1].NearLight[0].Angle=50
table.Lighting_V2[0][0][1].NearLight[0].Light=50
table.Lighting_V2[0][0][1].Sensitive=3
table.Lighting_V2[0][1][0].Correction=50
table.Lighting_V2[0][1][0].LightSwitchDelay=0
table.Lighting_V2[0][1][0].LightType=InfraredLight
table.Lighting_V2[0][1][0].MiddleLight[0].Angle=50
table.Lighting_V2[0][1][0].MiddleLight[0].Light=50
table.Lighting_V2[0][1][0].Mode=Auto
table.Lighting_V2[0][1][0].Sensitive=3
table.Lighting_V2[0][1][1].Correction=50
table.Lighting_V2[0][1][1].LightSwitchDelay=0
table.Lighting_V2[0][1][1].LightType=WhiteLight
table.Lighting_V2[0][1][1].Mode=Off
table.Lighting_V2[0][1][1].NearLight[0].Angle=50
table.Lighting_V2[0][1][1].NearLight[0].Light=50
table.Lighting_V2[0][1][1].Sensitive=3
table.Lighting_V2[0][2][0].Correction=50
table.Lighting_V2[0][2][0].LightSwitchDelay=0
table.Lighting_V2[0][2][0].LightType=InfraredLight
table.Lighting_V2[0][2][0].MiddleLight[0].Angle=50
table.Lighting_V2[0][2][0].MiddleLight[0].Light=50
table.Lighting_V2[0][2][0].Mode=Auto
table.Lighting_V2[0][2][0].Sensitive=3
table.Lighting_V2[0][2][1].Correction=50
table.Lighting_V2[0][2][1].LightSwitchDelay=0
table.Lighting_V2[0][2][1].LightType=WhiteLight
table.Lighting_V2[0][2][1].Mode=Off
table.Lighting_V2[0][2][1].NearLight[0].Angle=50
table.Lighting_V2[0][2][1].NearLight[0].Light=50
table.Lighting_V2[0][2][1].Sensitive=3

Here are the API calls I am currently using to change the light states using curl:

Motion on:

/cgi-bin/configManager.cgi?action=setConfig&AlarmLighting[0][0].Enable=true&Alarm[2].EventHandler.LightingLink.LightDuration=300

Motion off:

/cgi-bin/configManager.cgi?action=setConfig&AlarmLighting[0][0].Enable=false&Alarm[2].EventHandler.LightingLink.LightDuration=0

Light on:

/cgi-bin/configManager.cgi?action=setConfig&Lighting_V2[0][0][0].Mode=Auto&Lighting_V2[0][0][1].Mode=Manual

Light off:

/cgi-bin/configManager.cgi?action=setConfig&Lighting_V2[0][0][1].Mode=Off&Lighting_V2[0][0][0].Mode=Auto

The above calls are performed in the order motionoff && lighton to turn the light on, and lightoff && motionon to turn the light off.

The API calls you added in the code look correct for the light state, I am adding the Mode for the IR LED in my call (I think), but that can be controlled with the other channel so probably doesn't apply here. The call for enabling motion detection should probably be adjusted to use the AlarmLighting endpoint as mentioned above.

@Skinah
Copy link
Contributor

Skinah commented Dec 29, 2023

New build for you to try named ipcamera-4.2.0-2023-12-29.zip same private server as before and I also pushed the source code changes to my git as before.

I put the motion on and off in as you requested for this build, however I am not sure about this as it changes other settings that the user may not intend to change. I am guessing that this command will make the white led auto turn on for a set time when movement is detected? What happens if that call is left off, is there another way?

I also used Lighting_V2[0][0][1].NearLight[0].Light from the dimmer, can you test it works as planned and yes I understand for your camera it may for the values 1-49 give no light. Please test 50 and above to see it turns the light from off to the desired state.

Thanks.

@jshatch
Copy link
Author

jshatch commented Jan 1, 2024

Sorry, just got time to dig into this and check, it works great, thanks!

@jshatch jshatch closed this as completed Jan 1, 2024
@jshatch
Copy link
Author

jshatch commented Jan 1, 2024

Sorry hit the close button mistakenly, I'll let the PR close the issue.

@jshatch jshatch reopened this Jan 1, 2024
@jshatch
Copy link
Author

jshatch commented Jan 2, 2024

I put the motion on and off in as you requested for this build, however I am not sure about this as it changes other settings that the user may not intend to change. I am guessing that this command will make the white led auto turn on for a set time when movement is detected? What happens if that call is left off, is there another way?

Sorry I didn't address this question. The motion call doesn't need to be part of the light on-off call, it can, and probably should be a separate channel. I can use rules to modify the states when I press a button, no need to have the calls concatenated together. The only calls I have together are the ones that disable the IR led when the white light is on, but I don't really know if that's necessary (also can be addressed with rules on my side).

The AlarmLighting calls should probably be in the Auto White LED channel.

@Skinah
Copy link
Contributor

Skinah commented Jan 8, 2024

I do not mind grouping commands if they make sense for 99% of users. For example if the ir needs to be turned off when the white light turns on, then that can be added and then get put back to auto when the white light is turned off.

The issue is if one user likes the white light on motion as it scares criminals away, whilst another does not like that as it triggers a dog to bark and wake the baby. So splitting the control up makes sense.

What would the control get called and what is the description for your motion control? Does it need two controls so that the time the light stays on for can be adjusted?

@jshatch
Copy link
Author

jshatch commented Jan 8, 2024

Is the Auto White LED channel something different from motion activation?

And should the other parameters for motion detection be added as well (sensitivity, duration, zones, etc)?

I don't think those should be in the scope of this request though, the current solution satisfies that. Improvements can be made later.

@jshatch
Copy link
Author

jshatch commented Jan 9, 2024

One thing I just noticed with the way it currently is, turning the light off automatically re-enables motion detection, and I can see reasons why it shouldn't do that. For instance if you need to have motion detection turned off for some reason, or you are using a different method for that. So those API calls should be decoupled.

@Skinah
Copy link
Contributor

Skinah commented Jan 9, 2024

Already done and a newer jar is on my server. I can not test any of this as I don't have a camera with these features so it is great your testing and understand that it needs to be in a way that most people will be happy with.

@jshatch
Copy link
Author

jshatch commented Jan 21, 2024

Sorry, was super busy last week, but I did install the new jar and it's working for the light function. The "Auto White LED" channel isn't doing anything though. I assume that it is supposed to toggle the motion detection on and off, is that correct?

Also, is there a way for the binding to poll the state of the light? The Amcrest app is able to do that, but I'm not sure what method it's using. It wouldn't be ideal if it were constantly hitting it with an api call for that but I don't see any way that the unit is pushing it out either.

@Skinah
Copy link
Contributor

Skinah commented Jan 26, 2024

I have changed the api call for the auto white led channel, I think this will make you happy. We may change the time with another channel later if someone requests it, but lets leave it with the call you requested and have tested to work.

Polling can be added, but I need a break from this and the PR is getting reviewed so would like to stop making changes mid review. Lets make that a new request and not do feature creep in this one.
The way it is done currently is you can choose when you want it updated and send the REFRESH command to the channel. Most of them have been added to send the API call whilst I had it open. What I need is the RETURN back from a working camera so I can finish it off so you can get this from the TRACE log when you send the REFRESH command, then drop that in a github issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or new feature for an existing add-on
Projects
None yet
3 participants