Foscam Automation when Leaving Home

Hello Community,

I am interested in making an automation for my Foscam Cameras.
More specifically, I want them to:

  • start recording on motion detection when I leave home
  • stop recording when entering home

So far, I have created a test automation as below, using my phone as a tracker:

- alias: Entering Home
  trigger:
    platform: state
    entity_id: device_tracker.konstantinoss_iphone
    from: 'not_home'
    to: 'home'
  condition: []
  action:
  - alias: ''
    data: {}
    service: switch.turn_on
    entity_id: switch.shelly_nomad

So, I want the below URL to be executed when entering home (still working on the final URL but the main functionality is there), aka when the aforementioned automation is running:

http://foscam_camera_IP_address_here/cgi-bin/CGIProxy.fcgi?cmd=setScheduleRecordConfig&isEnable=1&recordLevel=0&isEnableAudio=1&schedule0=1023&schedule1=1023&schedule2=1023&schedule3=1023&schedule4=1023&schedule5=1023&schedule6=1023&usr=xxx&pwd=xxx

How can I implement that?

I have a foscam camera that I point away when home and to the record position when not_home.

you can use my code as a starting point to modify for your requirements:

automation:
  - alias: AS Computer Cam Position Control
    initial_state: 'on'
    trigger:
      - platform: state
        entity_id: person.me
    action:
      service: >
        {% if trigger.to_state.state == 'home' %}
          shell_command.as_comp_cam_top_pos
        {% else %}
          shell_command.as_comp_cam_record_pos
        {% endif %}

shell_command:
  as_comp_cam_record_pos: curl -k "http://192.168.1.53:8003/cgi-bin/CGIProxy.fcgi?cmd=ptzGotoPresetPoint&name=reboot&usr=my_user&pwd=my_pwd"
  
  as_comp_cam_top_pos: curl -k "http://192.168.1.53:8003/cgi-bin/CGIProxy.fcgi?cmd=ptzGotoPresetPoint&name=TopMost&usr=my_user&pwd=my_pwd"
1 Like

Thank you very much @finity, the below worked like a charm (at least in test mode since I must leave house in order to actually test it).
My only question is if I am able to integrate the below two automations in one, by inserting multiple actions inside the if statement.

- alias: foscam_record
  trigger:
    platform: state
    entity_id: person.me
  action:
  - alias: ''
    data: {}
    service: >
      {% if states.device_tracker.konstantinoss_iphone.state == 'home' %}
        shell_command.record
      {% else %}
        shell_command.not_record
      {% endif %}

- alias: foscam_motion
  trigger:
    platform: state
    entity_id: person.me
  action:
  - alias: ''
    data: {}
    service: >  
      {% if states.device_tracker.konstantinoss_iphone.state == 'home' %}
        shell_command.motion
      {% else %}
        shell_command.not_motion
      {% endif %}

no but you can just use one automation and put both services under the action:

- alias: foscam_record
  trigger:
    platform: state
    entity_id: person.me
  action:
  - service: >
      {% if states.device_tracker.konstantinoss_iphone.state == 'home' %}
        shell_command.record
      {% else %}
        shell_command.not_record
      {% endif %}
  - service: >  
      {% if states.device_tracker.konstantinoss_iphone.state == 'home' %}
        shell_command.motion
      {% else %}
        shell_command.not_motion
      {% endif %}
1 Like

Yeap, worked perfectly!
Once again, thank you for your amazing support!

1 Like