hello, I am new at this and I have a foscam too, could you tell me how can I integrate it to the home assistant thx
Awesome info!! Worked like a charm.
Just one comment in case anyone faces a similar issue:
the getDevState
seems to require credentials for an Administrator
role. Using an Operator
won’t be enough.
@ fanaticDavid thank you very much for sharing the curl commands. There’re other projects but the simplicity and practicality of your approach is best. All I wanted was to be able to use the motion sensor and this worked fine on my Foscam C1. I couldn’t get the switches to work but I guess this is due to camera differences. Thank you again.
What exactly are you trying to do?
Thanks for this!
I had my cameras sending motion detected through Blue Iris on my PC. For some reason my garage camera had a really long delay from the time motion was detected (and Blue Iris started recording) till BI sent the motion detected signal to HA. It was a delay of anywhere from 15 to 30 seconds!
The rest of my cameras (4 others) were pretty much immediate. As soon as BI started recording based on motion it sent the signal to HA. I’m not sure why that camera is so delayed. As far as I can see the config for all of them are exactly the same.
This allows me to get an almost instant response from the camera to HA (based on the polling interval…) and then turn my lights on. And if I have any issues with my Blue Iris/PC I will still have access to the camera motion status.
The Dahua Starlight 5231 IP cam is one of the best bang for the buck POE IP cameras on the market. See extensive review and discussion here: https://ipcamtalk.com/threads/dahua-starlight-varifocal-turret-ipc-hdw5231r-z.14683/
Camera-based motion detection is pretty inaccurate and ends in lots of false positives. New cameras from Hikvision and Dahua and other manufacturers include smarter motion detection with virtual tripwires, zone intrusion, etc. that is significantly more accurate.
User cor35vet on ipcamtalk wrote a small python script to monitor Dahua IVS events. See here: https://ipcamtalk.com/threads/trigger-blue-iris-with-ivs.17303/#post-1631964. I modified it to send MQTT messages so I could incorporate my cameras into HomeAssistant. See here: https://github.com/johnnyletrois/dahua-watch/blob/master/watch.py. It would be awesome if someone smarter than me would make a native component for HomeAssistant.
I use the following binary sensors to monitor the MQTT topics:
binary_sensor:
- platform: mqtt
state_topic: "home-assistant/cameras/0/IVS"
name: "Garage Tripwire"
- platform: mqtt
state_topic: "home-assistant/cameras/1/IVS"
name: "NWhouse Tripwire"
- platform: mqtt
state_topic: "home-assistant/cameras/2/IVS"
name: "SWhouse Tripwire"
One of my automations using the above sensors is to play a dog barking on my patio speakers and turn my office light on if the garage sensor is tripped:
- alias: Garage cam tripwire
initial_state: true
trigger:
platform: state
entity_id: binary_sensor.garage_tripwire
to: 'on'
condition:
condition: and
conditions:
condition: time
after: '22:30:00'
before: '06:00:00'
action:
- service: notify.ios_john_iphone_app
data:
message: "Garage tripwire activated"
data:
attachment:
url: !secret ip_cam_garage_image_login_url
content-type: jpeg
hide-thumbnail: false
- service: light.turn_on
data:
entity_id: light.office_ceiling_level
brightness: 255
- service: script.dog_bark
- delay: '00:00:{{ (range(30, 55)|random|int) }}'
- service: light.turn_off
entity_id: light.office_ceiling_level
So far I’m not seeing any false positives from my Foscam cameras. Or even the one REALLY cheap Tenvis camera that I bought several years ago.
And at double the price of my Foscams I’m not seeing the advantage of that camera for my uses.
I just want to see the live image of the camera in the visu of home assistant, I add it in the configuration. Yaml as the example that comes in the page components (foscam) but in the visu of HA it says error loading image so I don’t know what is wrong thanks for your help
can you post your configuration code so we can take a look for any problems?
So far I have three Foscam cameras working with the command line sensor as above.
I also have older Foscam and Tenvis cameras that don’t use the same CGI binary commands as the one posted.
Here is the cgi command that gets me the status:
http://192.168.1.XX:XXXX/get_status.cgi?user=XXXX&pwd=XXXXX
I’m trying to modify the command to parse out the status result I’m getting but can’t quite seem to figure it out.
Here is the result of the cgi command when I run it from a browser window:
var id=‘00626E52160D’;
var sys_ver=‘11.37.2.65’;
var app_ver=‘2.0.10.15’;
var alias=‘foscam1’;
var now=1511383922;
var tz=18000;
var alarm_status=1;
var ddns_status=500;
var ddns_host=‘XXXXXXXXX’;
var oray_type=0;
var upnp_status=0;
var p2p_status=0;
var p2p_local_port=25940;
var msn_status=0;
var wifi_status=0;
var ppcn=0;
var temperature=0.0;
var humidity=0;
var tridro_error=’’;
The piece I’m trying to parse out and test for is “var alarm_status=1”
Here is what I have as the command line:
'curl -k --silent "http://192.168.1.XX:XXXX/get_status.cgi?user=XXXX&pwd=XXXXX" | grep -oP "(?<=alarm_status=).*?(?=;>)"'
I get an error that says “Command failed”.
I did a little searching and it led me to try the following but it failed as well:
'curl -k --silent "http://192.168.1.XX:XXXX/get_status.cgi?user=XXXX&pwd=XXXXX" | grep -oP "\alarm_status=\K.*(?=\; var ddns_status)"'
I’m very new to linux. Where is my error?
I have an ip camera which use as a ( platform: generic ) . They show up in my HA nicely.
**I would like to put the on-off switch which show in ui. Most of my camera command are not the same as foscam or other cameras. They don’t have “getDevState”
The camera has cgi command by http. However, I couldn’t understand some command such as
command_state: ‘curl -k --silent “https://192.168.xxx.xx:443/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=YOURUSER&pwd=YOURPASSWORD” | grep -oP “(?<=infraLedState>).*?(?=)”’
value_template: ‘{{ value == “1” }}’
Can you recommand and show me step by step.
Here is the list of commands for my camera which I put as - platform: command_line
platform: command_line
switches:
office_cam_infrared:
friendly_name: “Infrared”
command_on: ‘curl -k “http://xxx:[email protected]:8300/cgi-bin/hi3510/param.cgi?cmd=setinfrared&-infraredstat=open”’
command_off: ‘curl -k “http://xxx:[email protected]:8300/cgi-bin/hi3510/param.cgi?cmd=setinfrared&-infraredstat=close”’
office_cam_infrared_auto:
friendly_name: “Infrared Auto”
command_on: ‘curl -k “http://xxx:[email protected]:8300/cgi-bin/hi3510/param.cgi?cmd=setinfrared&-infraredstat=auto”’
command_off: ‘curl -k “http://xxx:[email protected]:8300/cgi-bin/hi3510/param.cgi?cmd=setinfrared&-infraredstat=close”’
value_template: ‘{{ value == “1” }}’
office_cam_snapshot_email:
friendly_name: “Snapshot to Email”
command_on: ‘curl -k “http://xxx:[email protected]:8300/cgi-bin/hi3510/param.cgi?cmd=setsnaptimerattrex&-as_enable=1&-as_type=email”’
command_off: ‘curl -k “http://xxx:[email protected]:8300/cgi-bin/hi3510/param.cgi?cmd=setsnaptimerattrex&-as_enable=0&-as_type=email”’
office_cam_snapshot:
friendly_name: “Snapshot to SD”
command_on: ‘curl -k “http://xxx:[email protected]:8300/cgi-bin/hi3510/param.cgi?cmd=setsnaptimerattrex&-as_enable=1&-as_type=snap”’
command_off: ‘curl -k “http://xxx:[email protected]:8300/cgi-bin/hi3510/param.cgi?cmd=setsnaptimerattrex&-as_enable=0&-as_type=snap”’
office_cam_move_left:
friendly_name: “Move left”
command_on: ‘curl -k “http://xxx:[email protected]:8300/cgi-bin/hi3510/ptzctrl.cgi?-step=1&-act=left”’
command_off: ‘curl -k “http://xxx:[email protected]:8300/cgi-bin/hi3510/ptzctrl.cgi?-step=1&-act=home”’
office_cam_move_right:
friendly_name: “Move right”
command_on: ‘curl -k “http://xxx:[email protected]:8300/cgi-bin/hi3510/ptzctrl.cgi?-step=1&-act=right”’
command_off: ‘curl -k “http://xxx:[email protected]:8300/cgi-bin/hi3510/ptzctrl.cgi?-step=1&-act=home”’
office_cam_move_up:
friendly_name: “Move up”
command_on: ‘curl -k “http://xxx:[email protected]:8300/cgi-bin/hi3510/ptzctrl.cgi?-step=1&-act=up”’
command_off: ‘curl -k “http://xxx:[email protected]:8300/cgi-bin/hi3510/ptzctrl.cgi?-step=1&-act=home”’
office_cam_move_down:
friendly_name: “Move down”
command_on: ‘curl -k “http://xxx:[email protected]:8300/cgi-bin/hi3510/ptzctrl.cgi?-step=1&-act=down”’
command_off: ‘curl -k “http://xxx:[email protected]:8300/cgi-bin/hi3510/ptzctrl.cgi?-step=1&-act=home”’
office_cam_alarm:
friendly_name: “Cam Alarm”
command_on: ‘curl -k “http://xxx:[email protected]:8300/cgi-bin/hi3510/param.cgi?cmd=setscheduleex&-ename=md&-week0=PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP&-week1=PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP&-week2=PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP&-week3=PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP&-week4=PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP&-week5=PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP&-week6=PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP&”’
command_off: ‘curl -k “http://xxx:[email protected]:8300/cgi-bin/hi3510/param.cgi?cmd=setscheduleex&-ename=md&-week0=NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN&-week1=NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN&-week2=NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN&-week3=NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN&-week4=NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN&-week5=NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN&-week6=NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN&”’
office_cam_motion:
friendly_name: “Cam Motion”
command_on: ‘curl -k “http://xxx:[email protected]:8300/cgi-bin/hi3510/param.cgi?cmd=setmdattr&-enable=1&-s=50&-name=1&-x=0&-y=0&-w=720&-h=1280”’
command_off: ‘curl -k “http://xxx:[email protected]:8300/cgi-bin/hi3510/param.cgi?cmd=setmdattr&-enable=0&-s=50&-name=1&-x=0&-y=0&-w=720&-h=1280”’
It is not a good idea to keep the admin password for your cameras in your post…
You should probably XXXX them out.
Thank you very much.
Sorry for my dalay answer I just add the next configuration
camera:
- platform: foscam
ip: xxx.xxx.x.xx
port: 80
username: USERNAME
password: PASSWORD
In the configuration.yaml of course with the ip of the camera in my net and the user name and pasword for the camera I include the port cuz my camera has port 80 instead of 88
and in my viso of hassio it apears the message
Foscam Camera(Image not avaible)
Make sure the username you’re using is an administrator account on the Foscam camera. Also, did you check the Home Assistant log file for errors?
Yeip the username that I am using is an administrator account from the foscam and yeip I looked into the logs of home assistant and there are some warnings timeout and phyton but the truth is that I don’t know what they are, tomorrow I would copy what they say to posted here may be you can understand where is the error and you can tell me thanks
PD the model of the foscam that I have is not new
And I assume you can use the IP address, port, username & password you have in your config file to access the camera using a browser?
I just noticed the last line of you last post…
I also have an older model Foscam that I can’t access using the standard Foscam component.
Try this (modifying the details with your info ):
platform: mjpeg
mjpeg_url: http://IP ADDRESS:PORT/videostream.cgi?user=XXXX&pwd=XXXXX
username: !secret cam_user
password: !secret cam_pw
authentication: basic
name: XXXX
yes using the ip adress, port username & password directly in a browser I can get in without problems to the camera, but having the hassio I prefer to have all my devices in the hassio visu, so I will try today the configuration you say I hope it works like that thanks
Yeip it works! Thank you so much Finity with the configuration you tell me now I am able to see the camera in the visu of Hassio may be later you can teach me how to include alerts of movement and that stuff =D!
You’re Welcome!
I haven’t been able to figure out how to parse out the CGI command reply to integrate the motion for the older style cameras yet.
I have the question posted above in this thread but I haven’t had any takers yet on a request for help.
Once I do I’ll be glad to share what I’ve found out.