Repository navigation
feat(action): add motion event trigger and detection toggle buttons - #3468
Conversation
6fdb84e to
0c478dd
Compare
|
I played a bit around:
So overall, I see no simple way to implement a true manual recording API + buttons. But instead, we can implement a manual motion event toggle API and button. And while on it, the same for pausing/resuming motion detection. Both as new default-off toggles in the motion detection section. |
|
|
b2d6254 to
3518764
Compare
09ea92e to
c6b84dc
Compare
|
Good point. That was the same before, the action API never checked that, but makes sense to do so. I'm adding this to the tests as well. |
16bb1e9 to
3fc3de0
Compare
|
Ah, I btw want to change the SVGs as well, once everything else is sane. Need to think about a good simple symbol to represent a motion event, and motion detection respectively. On/off could be visualized with inverted colors, like some other buttons do, and/or a cross to be unambiguous. |
Marijn0
left a comment
There was a problem hiding this comment.
Looks good to me, quite nice additions, I like them a lot!
|
I tried 4b505e5 in Docker (motion 4.5.1). Tests pass, and the buttons work as described. Two questions and two small things:
|
|
Regarding wsswitch: Hmm, it would need to differentiate between a manual state change done via button/API, and the intended state change based on motion detection setting and working schedule times, somehow. Not sure how to implement this, since wsswitch uses the same
The best I can think of is a wsswitch cache:
That would also significantly reduce processing of the loop. We could further start the loop only if working schedule is actually enabled in any active camera config, turn it into a cached But I'd do all that in 1-2 separate PR. For now, I am fine with letting wsswitch override the state every 10 seconds, the way it always did. Regarding normal user permissions: The action API itself does and did not restrict it, e.g. for snapshots neither. It is and was the admin which decides which buttons to enable, and which action scripts to create, and the normal user can and could use them. I wouldn't change that for now, as it would introduce some inconsistency. But we can re-evaluate in a dedicated issue/PR whether all or some action buttons require stricter permissions, or maybe an admin-only flag per action button 🙈. Regarding the Good catch about the issue not clearing the cache on motion start. Makes sense, makes it more robust, and costs nothing. Done in 8d6ad46. |
This also merges the snapshot action method into the generic action method in the handler and backend. However, this commit is meant as an intermediate state: I actually aim to implement a button for the motion event start/stop action. And this can toggle recordings, too. Other than `emulate_motion`, the actions stop a recording immediately, but they also trigger motion notifications, which might not be always wanted. `emulate_motion` is tied with the picture capture mode, too, if enabled, causing all frames to be stored. So depending on which features are enabled, things are tied with each other differently, and we might end up with separate start/stop recording (of pictures and/or movies), and start/stop motion buttons, labelled differently, depending on which features are enabled. Similar to the snapshot button, the visibility of recording/motion toggle buttons would depend on the selected movie recording mode, a separate toggle. The visibility of the motion toggle button, if both really make sense separately, could be a separate toggle in motion detection settings, and a `@manual_motion` config. Leaving this for further testing/clarification and other opinions. Signed-off-by: MichaIng <micha@dietpi.com>
Signed-off-by: MichaIng <micha@dietpi.com> Co-Authored-By: MichaIng <micha@dietpi.com>
Signed-off-by: MichaIng <micha@dietpi.com> Co-Authored-By: MichaIng <micha@dietpi.com>
Signed-off-by: MichaIng <micha@dietpi.com> Co-Authored-By: MichaIng <micha@dietpi.com>
motion otherwise crashes. Return meaningful error from our API instead. Signed-off-by: MichaIng <micha@dietpi.com> Co-Authored-By: MichaIng <micha@dietpi.com>
Signed-off-by: MichaIng <micha@dietpi.com> Co-Authored-By: MichaIng <micha@dietpi.com>
Fix button state on hubs for remotes, by skipping the check for the non-existing `@motion_detection_button` on the local config stub. The remote does not send the cookie if the button is disabled in its config, hence checking for the cookie covers older remotes as well as those which have the button disabled reliably. Co-authored-by: Marijn <168113859+Marijn0@users.noreply.github.com>
4b505e5 to
244f06c
Compare
It is cleared on stop only so far. But the _motion_checker loop starts it without explicitly stopping it, in case of a crash. Signed-off-by: MichaIng <micha@dietpi.com>
244f06c to
8d6ad46
Compare
JamBalaya56562
left a comment
There was a problem hiding this comment.
Re-tested 8d6ad46: after a motion crash and restart by the checker, the detection button now follows the real state, and the tests pass. Fine with the working schedule and permissions in separate PRs; the ConnectionRefusedError catch can go here or in a follow-up, as you prefer.
|
Did let Copilot create some example icons for the two buttons and each state, following the simple SVG design of the other buttons. Which ones do you prefer? #3498 I'd probably go with:
But I would be happier with more specific motion event start/stop icons, instead of these generic start/stop anything. Maybe the pedestrian traffic light walking/standing human icons, used in some countries. EDIT2: Better, but I'm letting Claude try its best for another refined version: One side note: The action button icons represent what pressing the button does, not what the current state is. That can be actually confusing, but it is how the other buttons are designed, and their classes named, and how the recording button was intended to work. I am thinking now that the title text (hover text) needs to be adjusted, to say what pressing the button does, instead of "toggle ...". I'll change that later. Not bad:
Top is rendered at 40x40 pixels, i.e. their size in the UI. The 2nd column interestingly matches the Copilot result exactly, when I gave both the same sample to compare against. The 3rd column is what I'd take, since the red/green color could cause some unintended implicit associations: We do not want to give anyone an alarm signal with a red colored icon. EDIT: Ah, the 4th column is just a blend of sample and SVG, to see how well it matches. |
|
I added them here, i.e. open/closed eye for motion detection button, walking/standing figure for starting/ending motion event. But still open for suggestions, if you prefer any other variant from #3498, or another idea, or some refinement is needed. Whether the the SVGs are a KiB larger or smaller really does not matter either. EDIT: Ah I see you agreed already. Great, also the changing hover text is in now. Doing a last test of that before merge. |
Signed-off-by: MichaIng <micha@dietpi.com>
It already is a bit ambiguous about whether a button shows the current state, or the state it will set (the latter is true). Make the title (hover text) show the unambiguous action it triggers. Signed-off-by: MichaIng <micha@dietpi.com>
3aaad85 to
f9c34fb
Compare
There was a problem hiding this comment.
Tested again and everything works great!
One thing I noticed: I think we can improve how these buttons are arranged, but that's something for a separate PR. With 2 or more action buttons they only line up correctly after I open the settings menu, which seems to trigger the recalculation of how many rows are needed to display them. I think you're seeing the same thing, right? 😅


recordstart/stop action was never implemented, just stray dead code. There is no easy way to implement it, since motion has no recording-only action/API, but still locks the camera devices, so that a manual FFmpeg invocation runs into a "Device or resource busy" error.eventstart/eventendactions. This comes as close to a recording button as it gets, triggers the whole motion event notification pipeline, but at least stops recordings immediately, withoutpost_capture.snapshotaction path and function has been merged with the other two, since they do identical API calls. The API also returns a 400 now, ifsnapshot_filenameis not set, since otherwise motion crashes.motionctlfunction existed already, as the same API was used to disable motion detection prior to motion v4.4, and by the working schedule feature. Its argument has been adjusted to reflect, that it is makes use of motion'sdetection/pauseanddetection/startAPI, for temporarily switching the state, instead of being a persistent setting, like the motion >=4.4pauseconfig key, and our related@motion_detection. The state is cached, since it is obtained by everypicture/currentcall of the frontend to refresh the camera frames, like the motion event state. This means, that manually calling the motion API to pause/start motion detection, can cause a wrong state across motionEye. But I guess this is an acceptable regression.motionctlfunctions have been aligned to handleAsyncHTTPClient().fetch()errors correctly. They all threw an exception in any case of error.raise_error=Falseis used to setresp.errorinstead for actual HTTP response errors, a body check for motion "Bad Request" (HTTP 200) responses, and atry-exceptfor other kind of connection errors, to properly log and return them to the client, instead of throwing exceptions.