Older Old Foscam FI8910W Control and Curl Commands

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
  
    
1 Like

Thank you for this!

I have the my FI8910W cams working but I’m a little new and unsure of how to use the movement sensor. Is it a binary sensor?

For now, as I learn I’d like it to just show if motion occurs on the UI like my ring doorbell does. So I tried setting it as a binary_sensor as follows:

camera 4:
  - platform: mjpeg
    mjpeg_url: http://10.2.10.###:###/videostream.cgi?user=USER&pwd=PASS
    name: OfficeCam    
    
binary_sensor 4:    
  - platform: command_line
    name: "OfficeMotion"
    command: 'curl -k --silent "http://10.2.10.###:####/get_status.cgi?user=USER&pwd=PASS" | grep alarm | cut -b 18'
    value_template: >-
      {%- if value == "0" -%}
        off
      {%- elif value == "1" -%}
        on
      {%- endif -%}
    scan_interval: 3  

But I never see the sensor change state or log any motion changes.

Any help would be appreciated. Gonna have to dig a little deeper I guess.

Hi, make sure you have either homeassistant allowed to run curl commands in etc/sudoers or I would add a sudo into your sensor command;

sudo curl -k --silent "http://yourip:yourport/get_status.cgi?user=yourusername&pwd=yourpassword"

I have all my sensors in a sperate file sensors.yaml just create a new file with that name and drop sensors all in without the need for binary sensor. but I have to include sensor: !include sensors.yaml as a line in my configuration.yaml.

Hi Ding…

Thanks for that. I did add sudo but don’t see a difference. No binary_sensor change is registered.

Would you be willing to post one of your camera motion sensors from your sensors.yaml? I would like to make sure I have everything right.

Thanks in advance!

So I’ve tried both sudo on the curl line and adding

homeassistant to /etc/sudoers

Both do not give any change in indication of the binary_sensor.

This is my sensor;

  - platform: command_line
    name: "OfficeMotion"
    command: sudo 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

make sure motion is activated on the camera.

You can test the cgi status response by SSH into the Pi on port 22 in Putty and run the command to test you get a response;

sudo curl -k --silent "http://yourip:yourport/get_status.cgi?user=yourusername&pwd=yourpassword"

You should get something returned like this;

var id=‘xxxx’;
var sys_ver=‘xxxx’;
var app_ver=‘xxxx’;
var alias=‘mycam’;
var now=xxxx;
var tz=0;
var alarm_status=0;
var ddns_status=0;
var ddns_host=’’;
var oray_type=0;
var upnp_status=0;
var p2p_status=0;
var p2p_local_port=xxxx;
var msn_status=0;
var wifi_status=1;
var ppcn=0;
var temperature=0.0;
var humidity=0;
var tridro_error=’’;

If not there may be an issue with the command, I have seen a slight variation on the cam CGI commands on these cameras so that could be the issue, I’ve seen where login is something like 'loginuse=youruser" and something slightly different for password, maybe google around to check the command is correct for the CGI status. I tried the foscam.py solution initially as there are conversations on that but I couldn’t get that to work with my older cam.

Just turn on Motion Detection Alarmed and adjust sensitivity as needed:

I am also stuck. The sensor just show unknown. I can run the command with or without sudo and it works -
curl -k --silent “http://10.0.0.xx:xx/get_status.cgi?user=xx&pwd=xx”
var id=‘0062xewe34’;
var sys_ver=‘11.37.2.65’;
var app_ver=‘2.4.10.13’;
var alias=‘outside’;
var now=1586935817;
var tz=28800;
var alarm_status=0;
var ddns_status=600;
var ddns_host=‘xxxx’;
var oray_type=0;
var upnp_status=1;
var p2p_status=0;
var p2p_local_port=22424;
var msn_status=0;
var wifi_status=0;
var ppcn=0;
var temperature=0.0;
var humidity=0;
var tridro_error=’’;

My sensor config is

- platform: command_line
  name: "Motion"
  command: curl -k --silent "http://10.0.0.xx:xx/get_status.cgi?user=xx&pwd=xxt"
  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

Any ideas?

Not sure why it would be showing as unknown for you, hopefully you got it working, I assume the sensor is showing in your entities?

Thanks for all this great info in this thread! It helped me getting my old foscam setup!

I pulled together a bunch of different pieces and put together a card with direction control. Thought it might be worth sharing.

image

Lovelace picture-elements card

type: picture-elements
entity: camera.foscam
camera_image: camera.foscam
camera_view: live
elements:
  - type: icon
    icon: 'mdi:stop'
    style:
      background: 'rgba(255, 255, 255, 0.5)'
      right: 25px
      bottom: 25px
    tap_action:
      action: call-service
      service: shell_command.foscam_stop
      service_data: null
  - type: icon
    icon: 'mdi:arrow-up'
    style:
      background: 'rgba(255, 255, 255, 0.5)'
      right: 25px
      bottom: 50px
    tap_action:
      action: call-service
      service: script.foscam_move
      service_data:
        direction: up
  - type: icon
    icon: 'mdi:arrow-down'
    style:
      background: 'rgba(255, 255, 255, 0.5)'
      right: 25px
      bottom: 0px
    tap_action:
      action: call-service
      service: script.foscam_move
      service_data:
        direction: down
        movement: down
  - type: icon
    icon: 'mdi:arrow-left'
    style:
      background: 'rgba(255, 255, 255, 0.5)'
      right: 50px
      bottom: 25px
    tap_action:
      action: call-service
      service: script.foscam_move
      service_data:
        entity_id: camera.foscam
        direction: left
  - type: icon
    icon: 'mdi:arrow-right'
    style:
      background: 'rgba(255, 255, 255, 0.5)'
      right: 0px
      bottom: 25px
    tap_action:
      action: call-service
      service: script.foscam_move
      service_data:
        entity_id: camera.foscam
        direction: right
  - type: icon
    icon: 'mdi:arrow-top-left'
    style:
      background: 'rgba(255, 255, 255, 0.5)'
      right: 50px
      bottom: 50px
    tap_action:
      action: call-service
      service: script.foscam_move
      service_data:
        entity_id: camera.foscam
        direction: up_left
  - type: icon
    icon: 'mdi:arrow-top-right'
    style:
      background: 'rgba(255, 255, 255, 0.5)'
      right: 0px
      bottom: 50px
    tap_action:
      action: call-service
      service: script.foscam_move
      service_data:
        entity_id: camera.foscam
        direction: up_right
  - type: icon
    icon: 'mdi:arrow-bottom-left'
    style:
      background: 'rgba(255, 255, 255, 0.5)'
      right: 50px
      bottom: 0px
    tap_action:
      action: call-service
      service: script.foscam_move
      service_data:
        entity_id: camera.foscam
        direction: down_left
  - type: icon
    icon: 'mdi:arrow-bottom-right'
    style:
      background: 'rgba(255, 255, 255, 0.5)'
      right: 0px
      bottom: 0px
    tap_action:
      action: call-service
      service: script.foscam_move
      service_data:
        entity_id: camera.foscam
        direction: down_right

Script for handling the move and stop commands

alias: Foscam Move
sequence:
  - service: 'shell_command.foscam_{{direction}}'
    data: {}
  - delay: '3'
  - service: shell_command.foscam_stop
    data: {}
mode: restart
icon: 'mdi:arrow-all'
fields:
  direction:
    description: The direction to move
    example: up

Shell comands ./shell.yaml

foscam_stop: curl -k "http://<foscam_ip>/decoder_control.cgi?command=1&user=<username>&pwd=<pass>"
foscam_up: curl -k "http://<foscam_ip>/decoder_control.cgi?command=0&user=<username>&pwd=<pass>"
foscam_down: curl -k "http://<foscam_ip>/decoder_control.cgi?command=2&user=<username>&pwd=<pass>"
foscam_right: curl -k "http://<foscam_ip>/decoder_control.cgi?command=4&user=<username>&pwd=<pass>"
foscam_left: curl -k "http://<foscam_ip>/decoder_control.cgi?command=6&user=<username>&pwd=<pass>"
foscam_up_right: curl -k "http://<foscam_ip>/decoder_control.cgi?command=90&user=<username>&pwd=<pass>"
foscam_up_left: curl -k "http://<foscam_ip>/decoder_control.cgi?command=91&user=<username>&pwd=<pass>"
foscam_down_right: curl -k "http://<foscam_ip>/decoder_control.cgi?command=92&user=<username>&pwd=<pass>"
foscam_down_left: curl -k "http://<foscam_ip>/decoder_control.cgi?command=93&user=<username>&pwd=<pass>"    
4 Likes

Thanks for that, that’s great on the card, been meaning to do that with the picture elements since upgrading to latest HA few weeks ago as the foscam component/card wasn’t having it!

This is great, works like a charm!
One thing though: is it possible to adjust the speed of the movement? Or is this a camera specific setting? (As in: is this something to set up in the camera software itself?)

Edit: found it, it’s the ptz settings in the camera itself, so fixed :+1:

Hi,
I have two of the F18910W cameras and using the curl commands to get the alarm status has shown that the result is incredibly inconsistent. I have changed the sensitivity to different levels and still have not achieved a reliable result. My conclusion is that after 7 years I need new cameras! Cheers.

I also have an old FOSCAM camera. This thread helped me to get it up and running. But, I couldn’t get the picture-elements to work - I just get empty image (no error).
Btw, if anyone is interested, a full description of the cgi commands can be found here: ipcam cgi sdk