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

v2.1.0 Testers Needed - MQTT support for Motion Detect! #575

Closed
donavanbecker opened this issue Jun 29, 2020 · 31 comments
Closed

v2.1.0 Testers Needed - MQTT support for Motion Detect! #575

donavanbecker opened this issue Jun 29, 2020 · 31 comments

Comments

@donavanbecker
Copy link
Contributor

v2.X.X (2020-XX-XX)

Changes

  • Add MQTT support for Motion Detect (Add MQTT to motion Detect  #572), thanks to fennec622.
  • Just publish to topic, no message, homebridge/motion/Camera_name, You must add _ to your camera if you have space in the name.
{
  "platform": "Camera-ffmpeg",
  "mqtt": "127.0.0.1",
  "topics": "homebridge/motion/#",
  "cameras": [
    {
      "name": "Camera name",
      "motion": true,
      "videoConfig": {
        "source": "-re -i http://10.0.0.1",
        "stillImageSource": "-i http://10.0.0.1",
        "maxStreams": 5,
        "maxWidth": 1280,
        "maxHeight": 720,
        "maxFPS": 15,
        "maxBitrate": 1000
      }
    }
  ]
}
@donavanbecker donavanbecker pinned this issue Jun 29, 2020
@donavanbecker donavanbecker changed the title v2.1.0 v2.1.0 Testers Needed Jun 29, 2020
@donavanbecker donavanbecker changed the title v2.1.0 Testers Needed v2.1.0 Testers Needed - MQTT support for Motion Detect! Jun 29, 2020
@donavanbecker
Copy link
Contributor Author

You can test this by installing latest beta

  • sudo npm install -g --unsafe-perm homebridge-camera-ffmpeg@beta
  • To Revert sudo npm install -g --unsafe-perm homebridge-camera-ffmpeg@latest

@isramos
Copy link
Contributor

isramos commented Jul 1, 2020

I've been testing over the last 24 hours, and seem to be working fine.

Some notes:

  • the installation method above did not work for me. Instead, I went to HOOBS terminal and cd /home/hoobs/.hoobs, where package.json is located. Then ran sudo npm install -g --unsafe-perm homebridge-camera-ffmpeg@beta
  • mqtt topic: I wish there was an option to define the camera topic in cameras[].topic as an alternative to cameras[].name.
  • I wonder why we still need the dummy toggle switch.
  • The configuration entered in the HOOBS pretty UI is not being picked up. I wonder if config.schema.json line 24, should say topics instead of topic, so the UI parameter matches the actual property being picked up by code. I'm just guessing here.

Thanks for the great work!

@donavanbecker
Copy link
Contributor Author

Thanks for the great work!

Thanks for the feedback!

@donavanbecker
Copy link
Contributor Author

@isramos we have added an option to remove the dummy toggle switches and also added stateless doorbell switch for automations. If you could try that out?

@donavanbecker
Copy link
Contributor Author

donavanbecker commented Jul 2, 2020

Please test out latest beta.

sudo npm install -g --unsafe-perm homebridge-camera-ffmpeg@beta

@tom301080
Copy link

Still having the issue with ffmpeg exiting even with beta39

Bildschirmfoto 2020-07-03 um 18 02 59

@california444
Copy link

Hi,

some users mentioned in #554 that they can not restart homebridge due to an issue with multiple services with same UUID, e.g.link

The stacks trace in the referenced link shows that the DoorbellSwitch service in line 123 is the issue.
This service is not removed before like all other accessory services and thus could exist multiple times.

if (cameraConfig.doorbellSwitch) {
cameraAccessory
.addService(hap.Service.StatelessProgrammableSwitch, 'DoorbellSwitch')
.getCharacteristic(hap.Characteristic.ProgrammableSwitchEvent)
.setProps({
maxValue: hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS,
});
}

Could it be required to remove this service as well as all the other doorbell, motion and switch services?

const motion = cameraAccessory.getService(hap.Service.MotionSensor);
const doorbell = cameraAccessory.getService(hap.Service.Doorbell);
const doorbellSwitch = cameraAccessory.getServiceById(hap.Service.Switch, 'DoorbellTrigger');
const motionSwitch = cameraAccessory.getServiceById(hap.Service.Switch, 'MotionTrigger');
if (motion) {
cameraAccessory.removeService(motion);
}
if (doorbell) {
cameraAccessory.removeService(doorbell);
}
if (doorbellSwitch) {
cameraAccessory.removeService(doorbellSwitch);
}
if (motionSwitch) {
cameraAccessory.removeService(motionSwitch);
}

@donavanbecker
Copy link
Contributor Author

@california444 a pull request for this fix would be welcomed.

@isramos
Copy link
Contributor

isramos commented Jul 3, 2020

I just tested the beta tag. Here are my notes:

Whenever motion is detected I send MQTT message:

  • topic: /homebridge/motion/Camera One
  • payload: {"MotionDetected":true}

I see in the logs MQTT state message received: {"MotionDetected":true}. I conclude that we're now looking for the camera name in the payload. Maybe there should be a message in the logs saying that the camera called {"MotionDetected":true} is not found the list of configured cameras: [ 'Camera One', 'Camera Two']. That would make my mistake more obvious.

Once I transmit payload: Camera One I see the motion detection triggering: Switch Motion Detect On : Camera One.

IMPORTANT: However, I don't see it self clearing. It stays triggered forever. Please test it IMPORTANT:

One thing to consider: I suggest decoupling the camera name and use a different property to matching. Let's say I have a portable camera that each day I move to a different room, and each time I give it a different name. It would be a hassle to keep things in sync. On the other hand, if we use, say the serialNumber of the camera (or other prop) that would make it a more robust approach.

                    "model": "TBD",
                    "serialNumber": "0001",
                    "manufacturer": "LUX",
                    "name": "Cam Driveway",

In other words: topic would be: /homebridge/motion/{ serialNumber || name}

@DJBenson
Copy link

DJBenson commented Jul 3, 2020

Still having the issue with ffmpeg exiting even with beta39

Bildschirmfoto 2020-07-03 um 18 02 59

Same here :(

Totally "clean" Homebridge install, latest beta of the plugin, added a camera with a completely different name, no joy.

@ex725
Copy link

ex725 commented Jul 3, 2020

what settings do I need to make in these files to test
image
image

@burnbrigther
Copy link

Also still getting "[FFMPEG] ffmpeg exited with code: 1 and signal: null (error)". This is my last camera in my configuration and the only one having this problem.

[7/3/2020, 3:27:56 PM] [Camera-ffmpeg] Starting FRONT DOOR (Axis) video stream (1280x720, 10 fps, 299 kbps, 1316 mtu)...
[7/3/2020, 3:27:56 PM] [Camera-ffmpeg] [FFMPEG] ffmpeg exited with code: 1 and signal: null (error)
[7/3/2020, 3:27:56 PM] [Camera-ffmpeg] Stopped FRONT DOOR (Axis) video stream!

@steverae68
Copy link

steverae68 commented Jul 4, 2020

OK so call me dumb, but can someone point me in the direction or indeed, explain what the point of this MQTT addition is to this plugin.
At present i have several camera's configured, these are all Hik-Vision POE cams linked to a central NVR.

These cams all have built in motion detection and report to a App with video clips when motion is detected as you would expect.

Now using the v2.0.1 edition of this plugin, i have a Philips motion detector device which detects motion and switches on the camera dummy switch (via a homekit automation) which in turn triggers the motion sensor part of this plugin and generates the notification to Homekit itself.

If the idea that this MQTT will replace the need for the dummy switch and be able to trigger from the camera's own motion sensor (not sure if this is possible).

I'd just like a quick brief explanation please...... what would be good would be a way to capture the notification sent from the the Hik-Connect app (or which ever app is generating the notification) and use that as a trigger

@Sunoo
Copy link
Collaborator

Sunoo commented Jul 5, 2020

Okay, I can't for the life of me figure out how to get this to work.

My camera (a WyzeCam2 running Dafang Hacks) publishes to the topic configured followed by '/motion' with the word 'ON' or 'OFF' depending on whether motion is detected.

The name of my camera in this plugin is "Cat Food Camera" so I've tried configuring the camera to publish to "homebridge/motion/Cat Food Camera" and "homebridge/motion/Cat_Food_Camera" and in both cases I'm able to see messages coming (as described above) through when I subscribe to the topics myself. However, nothing I've tried has been able to get this plugin to show that it's seeing anything, though it does log "[Camera-ffmpeg] MQTT CONNECTED!" when restarting Homebridge, I never see anything else MQTT-related, and the motion sensor never changes states.

@Sunoo
Copy link
Collaborator

Sunoo commented Jul 5, 2020

Just a thought, but as someone else mentioned, perhaps defining the MQTT topic for each camera would be a better approach, and it’d certainly be more clear when configuring.

Some way to specify the messages for motion detected or not (perhaps regex?) might be a useful addition as well, since that likely varies from device to device.

@donavanbecker
Copy link
Contributor Author

donavanbecker commented Jul 5, 2020

@fennec622, see past comments.

@Sunoo
Copy link
Collaborator

Sunoo commented Jul 5, 2020

So I grabbed the code and started poking around, and it works differently than the documentation at the head of the thread claims.

Just publish to topic, no message, homebridge/motion/Camera_name, You must add _ to your camera if you have space in the name.

The way it actually seems to work, is that you need to publish 'Camera name' (without the spaces replaced with underscores) as a message to homebridge/motion.

The code as currently written also only swaps the first underscore with a space. So in my case with the camera named 'Cat Food Camera', if I follow the directions and use 'Cat_Food_Camera', the plugin converts it to 'Cat Food_Camera', which means the string comparison never works. However, ignoring that instruction and publishing the message of 'Cat Food Camera' causes the motion sensor to trip.

@fennec622
Copy link
Contributor

Just publish message name of camera

To topic You choose

More simply to specify one topic for all cameras

And adjust message for specify camera

I see for replace all Space not only the first

@Sunoo
Copy link
Collaborator

Sunoo commented Jul 5, 2020

@fennec622 In Javascript string.replace only works on the first instance of the pattern unless regular expressions are used.

I just created pull request #604 to correct this issue. Though, I don't see the need to do this replacement at all, since spaces are a valid character in MQTT messages?

I'm also still not convinced that relying on a single topic to handle everything is the best way forward, as that basically mandates some kind of shim program in most cases to subscribe to the MQTT topic that the camera actually publishes to, then republish it in the format this plugin now expects.

@Sunoo
Copy link
Collaborator

Sunoo commented Jul 5, 2020

Additionally, I recommend updating the first post to this, to reflect the way this plugin is currently actually working:

v2.X.X (2020-XX-XX)

Changes

  • Add MQTT support for Motion Detect (Add MQTT to motion Detect  #572), thanks to fennec622.
  • Just publish to topic homebridge/motion with the camera name as the message. You may use _ in the camera name instead of a space if you choose.
{
  "platform": "Camera-ffmpeg",
  "mqtt": "127.0.0.1",
  "topics": "homebridge/motion",
  "cameras": [
    {
      "name": "Camera name",
      "motion": true,
      "videoConfig": {
        "source": "-re -i http://10.0.0.1",
        "stillImageSource": "-i http://10.0.0.1",
        "maxStreams": 5,
        "maxWidth": 1280,
        "maxHeight": 720,
        "maxFPS": 15,
        "maxBitrate": 1000
      }
    }
  ]
}

@fennec622
Copy link
Contributor

more simply i make change
just post message with same name of camera
post message

Cat Food Camera

on topic homebridge/motion

@Sunoo
Copy link
Collaborator

Sunoo commented Jul 5, 2020

@fennec622 I agree that this is the less confusing approach. I've updated my pull request to strip out that replacement instead. That would mean the first post should be changed to:

v2.X.X (2020-XX-XX)

Changes

{
  "platform": "Camera-ffmpeg",
  "mqtt": "127.0.0.1",
  "topics": "homebridge/motion",
  "cameras": [
    {
      "name": "Camera name",
      "motion": true,
      "videoConfig": {
        "source": "-re -i http://10.0.0.1",
        "stillImageSource": "-i http://10.0.0.1",
        "maxStreams": 5,
        "maxWidth": 1280,
        "maxHeight": 720,
        "maxFPS": 15,
        "maxBitrate": 1000
      }
    }
  ]
}

Also, I still think it would be nice if, at minimum, there was a way to have two different messages to trigger or clear the motion sensor. It could be set up so that if there is no 'clear' message defined (maybe if motion sensor timeout value is set to '0' in the config or similar?) then the timeout fires and clears the the sensor automatically.

@fennec622
Copy link
Contributor

fennec622 commented Jul 5, 2020

For the moment reset motion is timeout to 1s

But it's possible to add config timer to reset motion for all cameras

"motionreset": 1;

But why increase time of motion reset ?

@Sunoo
Copy link
Collaborator

Sunoo commented Jul 5, 2020

@fennec622 No reason to increase time, but I thought that making it configurable gives an easy spot to disable the reset.

The reason for that is that my camera sends messages for both when it sees motion and when it stops seeing motion. It would be nice to have a way to support both of those instead of blinding resetting things, so that the motion sensor in HomeKit matches the motion detected state of the camera.

This would make the motion sensor useful beyond just having tripping send a push, I could look at the sensor in Home and see whether motion is currently being detected or not.

Perhaps sending a message with the camera name to homebridge/motion/off with the camera name while motionreset is configured to 0 would be the way to handle that?

I still think it would be nice to be able to configure the MQTT topic (or maybe just the motionreset value?) per camera though, especially since some cameras might not support sending a 'motion cleared' message and would require the timeout.

@fennec622
Copy link
Contributor

Ok
I see that for add reset motion by mqtt

@Sunoo
Copy link
Collaborator

Sunoo commented Jul 5, 2020

Yes, that's exactly what I was getting at.

@Sunoo
Copy link
Collaborator

Sunoo commented Jul 5, 2020

Okay, so I figured out a fairly clean way of supporting the way my camera publishes to MQTT. I made another Homebridge plugin (https://github.com/Sunoo/homebridge-dafang-mqtt-republish) that just subscribes to what my camera sends and republishes it in the way this plugin expects. And it works quite well.

It would still be very nice to be able to have an MQTT message that resets the motion sensor instead of using the timeout though. I could very easily update my plugin to support that, if some method to do so is added to this plugin.

Thanks.

@donavanbecker
Copy link
Contributor Author

donavanbecker commented Jul 6, 2020

closing, due to v2.1.0 being release.

@donavanbecker donavanbecker unpinned this issue Jul 6, 2020
@california444
Copy link

@donavanbecker v2.1.0 works like a charm here, thanks a lot!!

@donavanbecker
Copy link
Contributor Author

@california444 thanks for your input!!!

@steverae68
Copy link

OK so call me dumb, but can someone point me in the direction or indeed, explain what the point of this MQTT addition is to this plugin.
At present i have several camera's configured, these are all Hik-Vision POE cams linked to a central NVR.

These cams all have built in motion detection and report to a App with video clips when motion is detected as you would expect.

Now using the v2.0.1 edition of this plugin, i have a Philips motion detector device which detects motion and switches on the camera dummy switch (via a homekit automation) which in turn triggers the motion sensor part of this plugin and generates the notification to Homekit itself.

If the idea that this MQTT will replace the need for the dummy switch and be able to trigger from the camera's own motion sensor (not sure if this is possible).

I'd just like a quick brief explanation please...... what would be good would be a way to capture the notification sent from the the Hik-Connect app (or which ever app is generating the notification) and use that as a trigger

Can anyone provide a step by step guide to set this up? ive installed the plugin homebridge-mqttthing but im now at a loss

If it is not too much to ask - my email is [email protected]

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants