Since the foscam integration doesn’t create those sensors (as far as I know…) the only way I know to do it is to use the CGI commands for the various cameras to get the data.
here is what I use to get the motion detection status of one of my Foscam cameras:
sensor:
- platform: command_line
command: curl -k --silent "http://192.168.1.58:88/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=<my_cam_user>&pwd=<my_cam_password>"
name: "Kitchen Camera Motion Cam"
value_template: >
{% set status = value | regex_findall_index('Alarm>(\d+)</motion') %}
{% set values = {'0':'Disabled', '1':'None', '2':'Detected'} %}
{{ values[status] if status in values.keys() else 'Not Determined'}}
scan_interval: 5
you can also get the motion detection status using the above for a switch you can use in the frontend to turn on or off the motion detection I use this for another camera that had a bad habit of turning it’s motion detection off periodically:
First. as an FYI, if you don’t either tag me directly (by using @finity) or by clicking the reply button in my post then I don’t get notified that you have replied to me and then I have to notice that there are new posts in the thread. it’s easier for me to notice and reply faster the former way.
And it’s better to post actual code blocks instead of pictures of your code. it’s easier for us to edit your text than to rewrite it all by hand if there are changes needed.
but on to the issue…
you are trying to create a command line sensor as a template sensor. that won’t work.
you have to configure it as a simple “sensor:” with a platform of “command_line” not as a “template:” sensor.
just put the code I gave you (without the opening “sensor:” line and modified for your details) under your “sensor:” section in your configuration.yaml or wherever your sensors are if you have split your config.
How can I integrate my !secret camera_living_login and !secret camera_living_psw in the URL ?
There seems a problem in the state of the switches for my 2 last camera’s :
Also switching on/off works for the first 2 camera’s, but when I toggle the switch of the last 2 camera’s the switch comes back to off. Maybe the type : first two are FI9826P and the last two are FI9900EP ?
On all the camera’s I removed the stuff of schedules in your code. I see on the app of foscam that my last 2 camera’s has “Full-time modus” as scheme and the first 2 camera’s have “Close”…even if I don’t want schemes…
the only way that is possible is to make the entire URL command with that info in plain text as a secret and then use that secret in the “command:” line:
command: !secret some_cammand_secret
I’m not sure why you would be getting those errors. it looks fine to me and is the way I split up my config.
maybe it’s the VSCode editor that is confused?
TBH, I’m not sure what the different CGI commands for the different cameras are.
I usually just download a CGI reference manual from Foscam for my camera of interest. Most cameras use the same set of CGI commands but yours may be different.
I’ll start by telling you something pretty funny actually.
the camera I set that switch up for originally had started acting a bit flaky and I realized that the motion detection got disabled somehow. So I set that switch to be able to re-enable it easily from HA.
Then after a while I noticed that even tho the motion detection was enabled and the schedule was set correctly it still wasn’t triggering the motion detection events. I just chalked it up to being an old camera that was starting to fail. And since I use Blue Iris as an NVR and it has built-in motion detection I never dug into it any further.
But…
based on your post above I now realized that the camera wasn’t detecting events because the "area0’ thru “area9” settings were all set to 0 because I never set those back to the proper values when I turned motion detection back on.
TBH, I never even realized those needed set since they are buried another layer down in the camera settings.
It does seem like a poor design that all of the settings get wiped out completely when you just disable motion detection and then you have to set everything back up from scratch after you re-enable it. But it is what it is.
So, now that I got those set correctly my camera is now again sending motion events! Yay! Thanks for giving me that bit of data!
But now on to your question…
Here is my latest (very very long) command line switch to turn everything back on and reconfigure it properly:
I don’t see anything obviously wrong in yours tho but the above might help.
And I copied your last CGI command from above and pasted it directly into my browser (after changing to my details and adding back in all of the areaX info from above) and it worked fine for me.
So try adding in the area stuff and see how that goes.
I also found that with my first password that contained a special character (a # symbol in it) I couldn’t get it to work either. there are ways to escape those characters but it was just easier at the time to change it so it contained no special characters.
I think it is something about all of the single and double quotes and special characters in the HA command-line that prevented it from working from the there but worked fine without the quotes in the chrome browser.
If you have any special characters even in the middle of the password try to remove those as well to see if it helps
For the second type of camera I have to use setMotionDetectConfig1 and getMotionDetectConfig1
But…if I may, I suggest you should use the same URL for switching on & off (except isEnable=0 or 1).
Why ? If you switch off the motion detection of your camera with your switch in HA and you then go to the app of Foscam to set it back on, all the settings are wiped out.
Based on the sensor I send myself an e-mail so I know when the camera is set on/off or is triggered. But it doesn’t work every time ? Do you know why ?
alias: Camera garage ingeschakeld
description: ''
trigger:
- platform: state
entity_id: sensor.motion_camera_garage
from: Disabled
condition: []
action:
- service: script.cb_e_mail
data:
message: Camera garage ingeschakeld
title: Camera garage ingeschakeld
mode: single
alias: 'CB : E-Mail'
sequence:
- service: notify.GMail
data:
message: '{{ message }}'
title: '{{ title }}'
description: Send persistent notification
fields:
message:
description: De boodschap van de notificatie
default: Boodschap
example: Er is brand in de keuken
title:
description: De titel van de notificatie
default: Titel
example: Alarm, er is brand !
mode: single
I’ve got a Foscam too and trying to get this working. I have two zones active. But I don’t seem to understand what I need to do. So to validate my question.
When I set my preferred settings the getMotionDetectConfig1 shows the following config:
and unfortunately it doesn’t seem to support motion alarms
I have made it into a rest sensor, slightly less hacky I think:
- platform: rest
name: Motion Indgang
resource: 'http://192.168.0.10:88/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=<username>&pwd=<password>'
scan_interval: 5
value_template: >
{% set status = value.replace('</motionDetectAlarm>','<motionDetectAlarm>').split('<motionDetectAlarm>') %}
{% set values = {'0':'Disabled', '1':'None', '2':'Detected'} %}
{{ values[status] if status in values.keys() else 'Not Determined'}}
Home Assistant’s RESTsensor supports XML (it rewrites it to JSON), BUT it only works if the endpoint returns “Content-Type: text/xml”
unfortunately Foscam, incorrectly, returns “Content-Type: text/plain”
Funny enough I stumpled upon this few days ago when working with my underfloor heating system, so this seems to be a common problem with many XML endpoints.
There is this request open about adding a option to force XML: