Camera patrol based on profiles

Hello everybody!
I am trying to create a patrol path with my onvif camera which is not supported in HA. But I managed with your help to use a shell command with ssh to start predefined points with profiles. So I have a card with the image of the camera and underneath buttons with the profiles 1,2,3,4 for example and when pressing the camera it moves to those points.


What I am trying to do is that after for example midnight the camera moves between those defined movement profiles, “patrolling” each sector of the garden every 10 minutes.
For example that goes from point 1 to 2 and after 10 minutes to point 3 and so on until the last, after that it would return to point 1.

I was thinking of some way to save the point where the camera is, for example profile 1 with button 1. and when it starts after midnight first read that state and run the shell service from point 2, save that state and after 10 minutes read state (2) and continue to 3 and so on until reaching state 6 and back to 1. After dawn, it is located at point 1 and stops.

Any help or direction you can give me will be more than appreciated.
Thanks!
PS: Using google translator sorry.

Following this example I would think that I am almost there.
However I get this error when executing the automation. the scripts that run the shell command work perfectly separately and scripts too.

Errors:

Cam Patrols: Error executing script. Error for call_service at pos 1: Template rendered invalid entity IDs: - script.ptz_slider_add - script.cptz_2

Logger: homeassistant.components.automation.cam_patrols
Source: helpers/script.py:1324
Integration: Automation (documentation, issues)
First occurred: 2:43:37 AM (3 occurrences)
Last logged: 12:23:42 PM

Cam Patrols: Error executing script. Error for call_service at pos 1: Template rendered invalid entity IDs: - script.ptz_slider_add - script.cptz_2
Cam Patrols: Error executing script. Invalid data for call_service at pos 1: not a valid value for dictionary value @ data['entity_id']

Error while executing automation automation.cam_patrols: Template rendered invalid entity IDs: - script.ptz_slider_add - script.cptz_2
Logger: homeassistant.components.automation.cam_patrols
Source: components/automation/__init__.py:504
Integration: Automation (documentation, issues)
First occurred: 2:43:37 AM (3 occurrences)
Last logged: 12:23:42 PM

Error while executing automation automation.cam_patrols: Template rendered invalid entity IDs: - script.ptz_slider_add - script.cptz_2
Error while executing automation automation.cam_patrols: not a valid value for dictionary value @ data['entity_id']

Scripts: ptz1 , ptz2, ptz3 etc

scripts (works ok)

Execute shell ssh and move the camera

alias: cptz_1
sequence:
  - service: shell_command.pos_1
mode: single

Input slider +1

alias: ptz_Slider_add
sequence:
  - condition: numeric_state
    entity_id: input_number.ptz_1
    below: '4'
    above: '0'
  - service: input_number.increment
    target:
      entity_id: input_number.ptz_1
mode: single

Reset Slider to 1 if reach 4

alias: ptz_Slider_zero
sequence:
  - condition: numeric_state
    entity_id: input_number.ptz_1
    above: '3.0'
    below: '5.0'
  - service: input_number.set_value
    target:
      entity_id: input_number.ptz_1
    data:
      value: 1
mode: single

my configuration.yaml (works ok)

shell_command:
  pos_1: 'ssh -o UserKnownHostsFile=/config/.ssh/known_hosts [email protected] -i /config/.ssh/id_rsa ''onvif-ptz goto-preset --baseUrl=http://192.168.88.43 -u=admin -p=XXXXX --preset=1'''

Automation:

alias: Cam Patrols
description: ''
trigger: []
action:
  - service: script.turn_on
    data_template:
      entity_id: |
        {% if is_state('input_number.ptz_1', '1.0') %}
          script.ptz_slider_add
          script.cptz_2
        {% elif is_state('input_number.ptz_1','2.0') %}
          script.ptz_slider_add
          script.cptz_3
        {% elif is_state('input_number.ptz_1', '3.0') %}}
          script.ptz_slider_add
          script.cptz_4
        {% elif is_state('input_number.ptz_1', '4.0') %}}
          script.cptz_1
          script.ptz_Slider_zero
        {% endif %} 
mode: single

I leave it here in case someone can use it or improve it

Automation:

alias: Cam Patrols
description: ''
trigger:
  - platform: time_pattern
    minutes: /10
condition:
  - condition: sun
    before: sunrise
    after: sunset
    after_offset: '+05:00:00'
action:
  - service: script.turn_on
    data_template:
      entity_id: |
        {%  if is_state('input_number.ptz_1', '1.0') %}

        script.cptz1
        {% elif is_state('input_number.ptz_1','2.0') %}

        script.cptz2
        {% elif is_state('input_number.ptz_1', '3.0') %}

        script.cptz3
        {% elif is_state('input_number.ptz_1', '4.0') %}

        script.cptz4
        {%  endif %} 
mode: single

First script, the others are almost the same, only the above and below are changed

alias: cptz1
sequence:
  - service: shell_command.pos_2
  - condition: numeric_state
    entity_id: input_number.ptz_1
    below: '5'
    above: '0'
  - service: input_number.increment
    target:
      entity_id: input_number.ptz_1
mode: single

Shell command:

shell_command:
  pos_1: 'ssh -o UserKnownHostsFile=/config/.ssh/known_hosts [email protected] -i /config/.ssh/id_rsa ''onvif-ptz goto-preset --baseUrl=http://192.168.88.43 -u=admin -p=XXXX --preset=1'''

1 Like