Hi
If you are using an older foscam then you may have found the projects like foscam.py and the CGI commands don’t work. If you need the controls and sensor for movement see below as the commands aren’t the same, these all work for me;
Fill in your own internal ip, port number, user name (must be an administrator in the cam settings) and password))
The image for the camera to add to your configuration is below (the foscam homeassistant component didn’t work for this cam), I have ffmpeg installed.
platform: mjpeg
mjpeg_url: http://yourcamip:yourcamport/videostream.cgi?user=yourusername&pwd=yourpassword
name: Front
A movement sensor;
#cam sensor
- platform: command_line
name: "Front Camera Motion"
command: curl -k --silent "http://yourip:yourport/get_status.cgi?user=yourusername&pwd=yourpassword"
value_template: >-
{% set status = value | regex_findall_index('alarm_status=(\d+);') %}
{%- if status == "0" -%}
no
{%- elif status == "1" -%}
yes
{% else %}
not sure
{%- endif -%}
scan_interval: 3
Here are some shell commands for presets and to turn motion on and off (I have these in shell.yaml), if you want switches to activate these you can add command line switches or input boolean/automation switches
#front cam preset
front_preset_1: curl -k "http://yourip:yourport/decoder_control.cgi?user=youruser&pwd=yourpassword&command=31"
front_preset_2: curl -k "http://yourip:yourport/decoder_control.cgi?user=youruser&pwd=yourpassword&command=33"
front_preset_3: curl -k "http://yourip:yourport/decoder_control.cgi?user=youruser&pwd=yourpassword&command=35"
front_preset_4: curl -k "http://yourip:yourport/decoder_control.cgi?user=youruser&pwd=yourpassword&command=37"
front_preset_5: curl -k "http://yourip:yourport/decoder_control.cgi?user=youruser&pwd=yourpassword&command=39"
#front cam motion on off
front_motion_off: curl -k "http://yourip:yourport/set_alarm.cgi?user=youruser&pwd=yourpassword&motion_armed=0"
front_motion_on: curl -k "http://yourip:yourport/set_alarm.cgi?user=youruser&pwd=yourpassword&motion_armed=1"
There’s a lot more you can do for CGI commands just google FI8918W-CGI-Commands.pdf you can download this, just ensure that you format the same way as above and work out where to put the command.
And some automation examples;
#front cam motion move to preset for doorbell
- alias: front cam motion pic and move
initial_state: true
trigger:
platform: state
entity_id: sensor.front_cam_motion
to: 'yes'
#condition:
#condition: state
#entity_id: sun.sun
#state: 'below_horizon'
action:
- service: tts.google_translate_say
entity_id: media_player.speaker_1
data_template:
message: There is movement on the front camera is some one going to ring the bell
- delay:
seconds: 0.4
- service: camera.snapshot
data:
entity_id: camera.front
filename: /home/homeassistant/.homeassistant/tmp/front.jpg
#- delay:
#seconds: 1
#- service: shell_command.convertpic (theres a way to use this if you have MIME errors, but this cam should be ok)
- delay:
seconds: 0.4
- service: shell_command.front_motion_off
- delay:
seconds: 0.2
- service: shell_command.front_preset_2
- service: notify.one_notification
data:
title: Movement on Front Cam
message: There is movement
data:
file:
/home/homeassistant/.homeassistant/tmp/front.jpg
- delay:
seconds: 0.4
- service: notify.two_notification
data:
title: Movement on Front Cam
message: There is movement
data:
file:
/home/homeassistant/.homeassistant/tmp/front.jpg
- delay:
seconds: 25
- service: shell_command.front_preset_2
- delay:
seconds: 3
- service: shell_command.front_motion_on
#front motion on off
- alias: front motion on
initial_state: true
trigger:
platform: state
entity_id: input_boolean.front_motion
to: 'on'
#condition:
#condition: state
#entity_id: sun.sun
#state: 'below_horizon'
action:
- service: shell_command.front_motion_on
- alias: front motion off
initial_state: true
trigger:
platform: state
entity_id: input_boolean.front_motion
to: 'off'
#condition:
#condition: state
#entity_id: sun.sun
#state: 'below_horizon'
action:
- service: shell_command.front_motion_off