IP Webcam binary sensor

I have the IP Webcam working pretty well on a couple old phones, streams on startup, the only thing I am having trouble with is the motion activation. On the phone it works perfect, if I tell it to record on any motion then stop after 30 secs of no motion.
But through HA it seems to need about 30 secs. of motion before it records, and it needs a lot of motion to stay recording, so basically stops recording after 30 seconds every time, this is due to the binary sensor state.
I have this as a binary sensor, based on this page https://home-assistant.io/components/binary_sensor.android_ip_webcam/

platform: rest
name: Motion
sensor_class: motion
resource: http://192.168.1.70:8080/sensors.json?sense=motion_active
value_template: '{{ value_json.motion_active.data[0][1][0] | round(0) }}'

Basically, it takes about 30 secs of motion for the state to change to ‘1’, then unless there is constant motion it goes back to ‘0’. So, what I end up with is a bunch of 30 sec. recordings, which never start when the motion begins.

FYI, when there no motion, http://192.168.1.70:8080/sensors.json?sense=motion_active
returns something like this;
{“motion_active”:{“unit”:"",“data”:[[1512062666847,[0.0]]]}}
and when there is motion it returns something like this;
{“motion_active”:{“unit”:"",“data”:[[1485567814861,[1.0]],[1485568044149,[0.0]]]}}

rest sensors are polling and the default interval is 30 seconds. If you want to detect motion then the state should be pushed to Home Assistant.

Ok, that make sense why I am seeing the delay then.
Can you explain how to ‘push’ the state to HA? Do you mean from the Camera?
Is there another way to get real time motion from the IP Camera?

I don’t use Tasker but can’t that tell HA that the phone is detecting motion?

Motion detection with sound trigger, Tasker integration.

I’ve never used tasker either, but I am trying to avoid it, these are running on old phones always plugged in, so the less things running on android the better, generates less heat.
I can detect the motion immediately over http, so there has to be a way using HA. I can monitor the motion using curl on the command line without the delay, so I just have to figure out how to configure a binary sensor using command line maybe, not really sure how this all works. Bit of a newb, was hoping someone had done this before. Not recording until 30s after initial motion is no good.

How do you detect motion over http? I see the cloud notification might be able to notify HA.

Cloud push notifications on motion and sound, cloud recording for motion-triggered records, online video broadcasting powered by Ivideon.

Also, below talked about a motion sensor (not binary sensor) showing number representing motion

On a command line I can do the following and watch the sensor change

watch -d -n1 curl http://192.168.1.70:8080/sensors.json?sense=motion_event ; echo

`

It kinda make me think if you don’t round the number and look for a 0.2 value instead of 0.6 rounded to 1.0, it might be quicker response.

try this to see if it give you decimal.

value_template: ‘{{ value_json.motion_active.data[0][1][0] | round(2) }}’

How do I check that? In my binary sensor it’s either on or off.

Use template sensor

sensor:
  - platform: template
    sensors:
      Motion_value:
        value_template: '{{ value_json.motion_active.data[0][1][0] | round(2) }}

you can just try this in the template page to see if it give you a 2 decimal number, just cut and paste

{{ value_json.motion_active.data[0][1][0] | round(2) }}

edit: ignore this . - the Restful sensor was the correct choice. I don’t know now to change it from a binary sensor if that is how it is reported.

  - platform: rest
    resource: http://192.168.1.70:8080/sensors.json?sense=motion_active
    name: Motion_test
    value_template: '{{ value_json.motion_active.data[0][1][0] | round(2) }}'

That worked, of course I’m not at home, so can’t test.
Will test tonight.

This returns a value of 0 or 1.0, and turns to 1 at the same time the binary sensor, but for some reason stays 1 a little longer. Not sure what that tells me, but it is still not a good way to detect motion sensing triggers, too delayed.
I think I am going to look at the FFMPEG binary sensor.

You could speed up how fast Home Assistant is aware of motion being detected by specifying a different scan_interval (in seconds) for your rest binary sensor. So e.g. scan_interval: 5 would have the sensor poll the camera every 5 seconds instead of the default 30 seconds. YMMV cause this will of course depend on how quicky the IP Webcam can respond to the requests.

Having an IP camera push its state to Home Assistant is always the preferred method for a fast response, but isn’t always available depending on the camera. If polling is the only option, then lowering the scan_interval can help.

That is what I ended up doing, it’s not great but it’s better.
Seems to have a sweet spot of about 8-10 secs. to detect motion, no matter how low I lower the scan_interval.

Any idea why http://192.168.1.70:8080/sensors.json returns an empty body?

When I hit http://192.168.1.70:8080/sensors.json it returns {}.

Did you guys do anything to enable motion to work? I’ve tried 4 android phones, including a Note 8.

Did you enable data logging in the android app :grinning: ?

1 Like

Found it, I’ll try now, ty

I love you right now.

thanks JTPublic!

I wasted so much time, lol.

But hey, at least I bought the pro…lol

@JTPublic, have you seen this error before?

2018-02-24 16:40:45 WARNING (SyncWorker_4) [urllib3.connectionpool] Failed to parse headers (url=http://192.168.x.x:8080/video): [StartBoundaryNotFoundDefect(), MultipartInvariantViolationDefect()], unparsed data: ‘’
Traceback (most recent call last):
File “/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py”, line 399, in _make_request
assert_header_parsing(httplib_response.msg)
File “/usr/local/lib/python3.6/site-packages/urllib3/util/response.py”, line 66, in assert_header_parsing
raise HeaderParsingError(defects=defects, unparsed_data=unparsed_data)
urllib3.exceptions.HeaderParsingError: [StartBoundaryNotFoundDefect(), MultipartInvariantViolationDefect()], unparsed data: ‘’

Can’t say I remember seeing those, I did not play much attention to the log if things are working LOL.
How did you get the sensors in HA? The IP Webcam module?
Is the video coming through with those warnings?
I would check to make sure your android has the sensor(s) you selected, my phone did not have light sensor for example.
I do set up a separate card to display all the sensor values so I know they are working and have switch to reboot the android phone if any is non-responsive.

I know we are talking about the sensors here which is easier with the IP Webcam module along with the video. But if you ever have issue with the video, i.e. the default http (/video), you can always try the ffmpeg camera with rtsp (/h264_ulaw.sdp or _pcm.sdp).