How to automate a camera PAN with a motion sensor (http commands)?

Hi,

I got a camera that has good feature for the price (50$), it can control the pan with http command.

I am newb and not sure how I can put in front end the commands: ideally just a button for each preset.
Of course would be good some code for automation (like if there is a motion, with an external motion sensor) to make the camera move to a preset position automatically

PT control
Up: http://camera_ip:web_port/decoder_control.cgi?command=0&user=username&pwd=password
Stop up: http://camera_ip:web_port/decoder_control.cgi?command=1&user=username&pwd=password
Down: http://camera_ip:web_port/decoder_control.cgi?command=2&user=username&pwd=password
Stop down: http://camera_ip:web_port/decoder_control.cgi?command=3&user=username&pwd=password
Left: http://camera_ip:web_port/decoder_control.cgi?command=4&user=username&pwd=password
Stop left: http://camera_ip:web_port/decoder_control.cgi?command=5&user=username&pwd=password
Right: http://camera_ip:web_port/decoder_control.cgi?command=6&user=username&pwd=password
Stop right: http://camera_ip:web_port/decoder_control.cgi?command=7&user=username&pwd=password
Set Preset position 1: http://camera_ip:web_port/decoder_control.cgi?command=30&user=username&pwd=password
Go Preset position 1: http://camera_ip:web_port/decoder_control.cgi?command=31&user=username&pwd=password
Set Preset position 2: http://camera_ip:web_port/decoder_control.cgi?command=32&user=username&pwd=password
Go Preset position 2: http://camera_ip:web_port/decoder_control.cgi?command=33&user=username&pwd=password
Set Preset position 3: http://camera_ip:web_port/decoder_control.cgi?command=34&user=username&pwd=password
Go Preset position 3: http://camera_ip:web_port/decoder_control.cgi?command=35&user=username&pwd=password
Set Preset position 4: http://camera_ip:web_port/decoder_control.cgi?command=36&user=username&pwd=password
Go Preset position 4: http://camera_ip:web_port/decoder_control.cgi?command=37&user=username&pwd=password
Set Preset position 5: http://camera_ip:web_port/decoder_control.cgi?command=38&user=username&pwd=password
Go Preset position 5: http://camera_ip:web_port/decoder_control.cgi?command=39&user=username&pwd=password
Set Preset position 6: http://camera_ip:web_port/decoder_control.cgi?command=40&user=username&pwd=password
Go Preset position 6: http://camera_ip:web_port/decoder_control.cgi?command=41&user=username&pwd=password

This thread may provide some help

very cool, but I have already enough difficulties with programming just the configuration.yaml :smile:

Small steps, @anon35356645. Don’t overwhelm yourself by trying to do everything at once.

Look how far you’ve come already!

1 Like

thanks for encouragement.

For the beginning I need something simple:
at night the camera goes to a certain preset position
(http://camera_ip:web_port/decoder_control.cgi?command=31&user=username&pwd=password)

at day the camera goes to a different preset position
http://camera_ip:web_port/decoder_control.cgi?command=32&user=username&pwd=password

what would be the easiest way?

That would be the automation part. for all the rest I can continue using the web interface of the producer

You could do a command line switch and use CURL.

I was looking into this myself to automate my Foscam and turn off the IR at night (It faces a window making IR useless, but I can’t permanently turn it off) but I didn’t go that far with it.

In the bookmarks folder I have for this project I have these threads; presumably to figure out curl usage. It may help.

1 Like

you mean using 2 commands only?

I actually have two presets to use: so have command on to go to one preset and command off to go second preset.

Not an elegant solution, but should work

Or you could use an input select.

mmhh have never done it, will have to study it

Something like this? But where/how you put the curl?

input_select:
      camera_presets:
        name: Office camera presets
        options:
         - Inside
         - Outside
        initial: Inside
        icon: mdi:camera



automation:
  - alias: Presets Inside
    trigger:
      platform: sun
      event: sunset
    action:
      - service: input_select.select_option
        data:
          entity_id: input_select.camera_presets
          option: Inside

Yeah… didn’t get that far in my project.

But maybe another user will come here and bail us both out!

did this instead:

in automation

  - alias: Office camera inside
    trigger:
      platform: sun
      event: sunset
    action:
      service: homeassistant.turn_off
      entity_id: office_camera_presets_1_2
  - alias: Office camera outside
    trigger:
      platform: sun
      event: sunrise
    action:
      service: homeassistant.turn_on
      entity_id: office_camera_presets_1_2

configuration

switch 3:
  platform: command_line
  switches:
    office_camera_presets_1_2:
      #presets1 office outside
      command_on: 'curl -X GET http://192.168.1.45:web_port/decoder_control.cgi?command=31&user=admin&pwd=xxx'
      #presets2 office inside
      command_off: 'curl -X GET http://192.168.1.45:web_port/decoder_control.cgi?command=33&user=admin&pwd=xxx'

not working, what is wrong?

17-01-15 23:47:22 homeassistant.bootstrap: Invalid config for [automation]: Entity ID office_camera_presets_1_2 is an invalid entity id for dictionary value @ data[‘action’][0][‘entity_id’]. Got None. (See /home/hass/.homeassistant/automation.yaml:1). Please check the docs at https://home-assistant.io/components/automation/
17-01-15 23:47:22 homeassistant.bootstrap: Invalid config for [automation]: Entity ID office_camera_presets_1_2 is an invalid entity id for dictionary value @ data[‘action’][0][‘entity_id’]. Got None. (See /home/hass/.homeassistant/automation.yaml:1). Please check the docs at https://home-assistant.io/components/automation/
17-01-15 23:47:22 homeassistant.core: Bus:Handling <Event call_service[L]: service_call_id=1977193360-7, service=create, service_data=notification_id=invalid_config, title=Invalid config, message=The following components and platforms could not be set up:

To allow control of an Amcrest camera pan & tilt, I added an input_select, automation and shell_command to my configuration.yaml, and a shell script.

The reason for the “1” in the list of the input_select is to allow moving the camera in the same direction twice. For example, if you select “Left,” the camera will move left. If you select “Left” again, the camera won’t move because the automation will not be triggered. I couldn’t find any other way to do this. So if you want to move left twice, you need to select “Left,” “1” and then “Left” again.

input_select:
move_camera:
name: Move Camera
options:
- Left
- Right
- 1
- Up
- Down
- Reboot

automation:

  • alias: cam_move
    hide_entity: true
    trigger:
    platform: state
    entity_id: input_select.move_camera
    action:
    service: shell_command.ptz_amcrest

shell_command:
ptz_amcrest: bash /home/hass/.homeassistant/camera.move 254 {{states(‘input_select.move_camera’)}}

Here’s the contents of camera.move. It expects two arguments, the ending IP address, (in this example 254) and the command to be passed
from input_select.move_camera
.

#!/bin/bash

if [ $2 == Reboot ]
then
curl -k -m10 -u USERNAME:PASSWORD “http://192.168.1.$1/cgi-bin/magicBox.cgi?action=reboot”

else

curl -k -m10 -u USERNAME:PASSWORD “http://192.168.1.$1/cgi-bin/ptz.cgi?action=start&channel=0&code=$2&arg1=0&arg2=2&arg3=0&arg4=0”
sleep 2

curl -k -m10 -u USERNAME:PASSWORD “http://192.168.1.$1/cgi-bin/ptz.cgi?action=stop&channel=0&code=$2&arg1=0&arg2=2&arg3=0”

fi