Synology Surveillance Station and PTZ preset/movement Home Mode

Hello Guys,
I have an Reolink E1 Pro and I can’t use ONVIF component of home assistant for move the camera to the desidered preset so I used the Surveillance Station installed on Synology for achieve this.

So if you have a synology you can move all configured camera (PTZ compatible) to the desidered position…

Before to start you have to create some preset in Synology Surveillance Station on the camera:
I have created some preset: Home, Living, Kitchen, Bedroom and Rack

You have to follow this step carefully :slight_smile:

  1. First thing open browser and put this string changing the value with your value

https://your_IP:your_port/webapi/auth.cgi?api=SYNO.API.Auth&method=Login&version=2&account=your_username&passwd=your_password&session=SurveillanceStation&format=cookie

And will be a web page with this similar results

{“data”:{“sid”:“urOZvm591S5A6D9LPN00502”},“success”:true}

  1. issue the second command for display all information of your cameras in the browser

https://your_IP:your_port/webapi/entry.cgi?api=SYNO.SurveillanceStation.Camera&method=List&version=2

in this page you have to find with CTRL +F “cameraid=” and you will find all the IDs of the cameras configured in the synology, in my case the ID are 4 and 5. so keep a note of these IDs.

  1. Issue this command in the browser for be sure that the camera id is working

Remember to change cameraid= with your ID :slight_smile:

https://your_IP:your_port/webapi/entry.cgi?api=SYNO.SurveillanceStation.Camera&method=GetSnapshot&version=1&cameraId=4&timestamp=1571412595&preview=true

and you will see the snapshot of your camera, If you don’t see it repeat the steps from number 1.

  1. Now we have to acquire the preset names created before (remember to change the cameraid with your ID) :slight_smile:

https://your_IP:your_port/webapi/entry.cgi?api=SYNO.SurveillanceStation.PTZ&method=ListPreset&version=1&cameraId=4

In my case the output on the browser is like this:

{“data”:{“offset”:0,“presets”:[{“id”:2,“name”:“Home”,“type”:0},{“id”:8,“name”:“Living”,“type”:0},{“id”:9,“name”:“Kitchen”,“type”:0},{“id”:10,“name”:“Bedroom”,“type”:0},{“id”:11,“name”:“Rack”,“type”:0}],“total”:5},“success”:true}

  1. now you can change the position of your PTZ camera to the desired preset ID:

for example move the camera to the rack (remember to change cameraid and presetid to your value)

https://your_IP:your_port/webapi/entry.cgi?api=SYNO.SurveillanceStation.PTZ&method=GoPreset&version=1&cameraId=4&presetId=11

and you will see the camera move to your preset :-)… tha’s great… but if you open an incognito tab you will se it don’t work… why? it’s missing the sid!!

  1. add the sid at the end of the url and test it:

&_sid=aZWZZAKvChwhrsdasda903122

https://your_IP:your_port/webapi/entry.cgi?api=SYNO.SurveillanceStation.PTZ&method=GoPreset&version=1&cameraId=4&presetId=11&_sid=urOZvm591S5A6D9LPN00502

  1. add to configuration.yaml this parameters:
  ss_preset_home:
    url: !secret ss_preset_home
    method: get
    verify_ssl: false
  ss_preset_rack:
    url: !secret ss_preset_rack
    method: get
    verify_ssl: false

Add the url to the secret.yaml

ss_preset_home: 
ss_preset_rack:

and restart Home assistant

There is the API for setting Home mode ON and OFF too…

Enable Home Mode

https://your_IP:your_port/webapi/entry.cgi?api=SYNO.SurveillanceStation.HomeMode&version=1&method=Switch&on=true&_sid=urOZvm591S5A6D9LPN00502

Disable Home Mode

https://your_IP:your_port/webapi/entry.cgi?api=SYNO.SurveillanceStation.HomeMode&version=1&method=Switch&on=false&_sid=urOZvm591S5A6D9LPN00502

use it in your automation.yaml when you go out or come back to home:

Example:

####################################################
#               Nico Out Casetta                   #
####################################################

- id: zone-nico-out-casetta
  alias: Nico is going out - Notification
  initial_state: 'on'
  trigger:
     platform: zone
     entity_id: device_tracker.nico_nico
     zone: zone.casetta
     event: leave
  condition:
     condition: time
     after: '07:00:00'
     before: '23:59:00'         
  action:
   - service: notify.hassnico_bot
     data:
       message: "Nico is going out from Casetta at {{ states('sensor.date_time') }}"
   - service: script.alexatraffic2
   - service: rest_command.ss_home_off

At Home

####################################################
#                  Nico Casetta 2                  #
####################################################
- id: zone-nico-casetta
  alias: Nico at Home 2 - Notification
  initial_state: 'on'
  trigger:
     platform: state
     entity_id: device_tracker.nicogalaxys8
     from: 'not_home'
     to: 'home'
  action:
  - service: media_player.volume_set
    data:
      entity_id: media_player.nicolo_s_bose_home_speaker_500
      volume_level: 0.3
  - delay: 00:00:02
  - service: notify.alexa_media
    data:
      target: 
        - media_player.nicolo_s_bose_home_speaker_500
      data:
        type: tts
      message: >
       {{ [
       "Bentornato a casa Nico",       
       "Nico sei finalmente a casa",
       ] | random }}
  - service: rest_command.ss_home_on

This is how it look on lovelace
At the top left there are Preset for camera… at bottom left Lights and on Bottom right the command for move the camera

Capture

more to come… PTZ command :slight_smile:

4 Likes

Thank you. helped me connect hassio with synology very quickly. Everything very well explained for people who start !!

1 Like

@Ciquattro Could you advise, if such _sid is a long-time token? I successfully receive it and everything works well, but after some days it stops working until I receive new token.

it’s not a long-time token… I noticed that after a reboot you need to renewthe _sid… :frowning:… from API documentation seems they don’t have the long live token

How did you manage to run a service call from the small image on the picture glance card?

I’ve managed to create a flow in Node-RED to request a new SID on every call, which handles the expiration of the hardcoded SID in the REST command.

I’ll share it below, you’ll only need to create 2 input_boolean’s to accomodate a switch/button from the Home Assitant UI.

Node-RED flow, change to your Synology IP, port and username/password:

[{"id":"7c43c3c7.7a0a5c","type":"inject","z":"96b6c23d.d41b4","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":100,"wires":[["e84577e5.50c6e8"]]},{"id":"e84577e5.50c6e8","type":"http request","z":"96b6c23d.d41b4","name":"Login","method":"GET","ret":"txt","paytoqs":"ignore","url":"http://YOURIP:PORT/webapi/auth.cgi?api=SYNO.API.Auth&method=Login&version=3&account=USERNAME&passwd=PASSWORD&session=SurveillanceStation&format=sid","tls":"","persist":false,"proxy":"","authType":"","x":290,"y":100,"wires":[["22f6376e.be9ca8"]]},{"id":"22f6376e.be9ca8","type":"json","z":"96b6c23d.d41b4","name":"","property":"payload","action":"","pretty":true,"x":410,"y":100,"wires":[["cd401a10.193f88"]]},{"id":"cd401a10.193f88","type":"change","z":"96b6c23d.d41b4","name":"Save sid","rules":[{"t":"set","p":"sid","pt":"flow","to":"payload.data.sid","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":100,"wires":[["15880df5.6726e2"]]},{"id":"15880df5.6726e2","type":"template","z":"96b6c23d.d41b4","name":"Preset tuin","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"http://YOURIP:PORT/webapi/entry.cgi?api=SYNO.SurveillanceStation.PTZ&method=GoPreset&version=1&cameraId=1&presetId=7&_sid={{{flow.sid}}}","output":"str","x":270,"y":160,"wires":[["c645343d.545a08"]]},{"id":"c645343d.545a08","type":"http request","z":"96b6c23d.d41b4","name":"API","method":"GET","ret":"txt","paytoqs":false,"url":"{{{payload}}}","tls":"","persist":false,"proxy":"","authType":"","x":430,"y":160,"wires":[["3831e9d8.c141a6"]]},{"id":"3831e9d8.c141a6","type":"http request","z":"96b6c23d.d41b4","name":"Logout","method":"GET","ret":"txt","paytoqs":"ignore","url":"http://YOURIP:PORT/webapi/auth.cgi?api=SYNO.API.Auth&method=Logout&version=3&session=SurveillanceStation&_sid={{flow.sid}}","tls":"","persist":false,"proxy":"","authType":"","x":560,"y":160,"wires":[["79e5a9f0.f184d8"]]},{"id":"fa7f2187.dcc5c","type":"comment","z":"96b6c23d.d41b4","name":"Preset Tuin","info":"","x":150,"y":60,"wires":[]},{"id":"d4b34026.47f14","type":"inject","z":"96b6c23d.d41b4","name":"","props":[{"p":"payload","v":"","vt":"date"},{"p":"topic","v":"","vt":"string"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":340,"wires":[["ac201d4.bbae1e"]]},{"id":"ac201d4.bbae1e","type":"http request","z":"96b6c23d.d41b4","name":"Login","method":"GET","ret":"txt","paytoqs":"ignore","url":"http://YOURIP:PORT/webapi/auth.cgi?api=SYNO.API.Auth&method=Login&version=3&account=USERNAME&passwd=PASSWORD&session=SurveillanceStation&format=sid","tls":"","persist":false,"proxy":"","authType":"","x":290,"y":340,"wires":[["725c3758.e7d6e8"]]},{"id":"725c3758.e7d6e8","type":"json","z":"96b6c23d.d41b4","name":"","property":"payload","action":"","pretty":true,"x":410,"y":340,"wires":[["a2c31bb5.175fb8"]]},{"id":"a2c31bb5.175fb8","type":"change","z":"96b6c23d.d41b4","name":"Save sid","rules":[{"t":"set","p":"sid","pt":"flow","to":"payload.data.sid","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":340,"wires":[["2df64dfb.a41c92"]]},{"id":"2df64dfb.a41c92","type":"template","z":"96b6c23d.d41b4","name":"Preset woonkamer","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"http://YOURIP:PORT/webapi/entry.cgi?api=SYNO.SurveillanceStation.PTZ&method=GoPreset&version=1&cameraId=1&presetId=4&_sid={{{flow.sid}}}","output":"str","x":290,"y":400,"wires":[["4235779a.be9708"]]},{"id":"4235779a.be9708","type":"http request","z":"96b6c23d.d41b4","name":"API","method":"GET","ret":"txt","paytoqs":false,"url":"{{{payload}}}","tls":"","persist":false,"proxy":"","authType":"","x":450,"y":400,"wires":[["7ff86820.f6d2f8"]]},{"id":"7ff86820.f6d2f8","type":"http request","z":"96b6c23d.d41b4","name":"Logout","method":"GET","ret":"txt","paytoqs":"ignore","url":"http://YOURIP:PORT/webapi/auth.cgi?api=SYNO.API.Auth&method=Logout&version=3&session=SurveillanceStation&_sid={{flow.sid}}","tls":"","persist":false,"proxy":"","authType":"","x":570,"y":400,"wires":[["1c8fb495.94b51b"]]},{"id":"85409f71.95fbc","type":"comment","z":"96b6c23d.d41b4","name":"Preset Woonkamer","info":"","x":170,"y":300,"wires":[]},{"id":"a3685fd5.8b8d","type":"server-state-changed","z":"96b6c23d.d41b4","name":"","server":"852c0f18.d61a7","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_boolean.preset_tuin","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":200,"y":220,"wires":[["e84577e5.50c6e8"],[]]},{"id":"79e5a9f0.f184d8","type":"api-call-service","z":"96b6c23d.d41b4","name":"","server":"852c0f18.d61a7","version":1,"debugenabled":false,"service_domain":"input_boolean","service":"turn_off","entityId":"input_boolean.preset_tuin","data":"","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":780,"y":160,"wires":[[]]},{"id":"29bedd15.dd0022","type":"server-state-changed","z":"96b6c23d.d41b4","name":"","server":"852c0f18.d61a7","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_boolean.preset_home","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":210,"y":460,"wires":[["ac201d4.bbae1e"],[]]},{"id":"1c8fb495.94b51b","type":"api-call-service","z":"96b6c23d.d41b4","name":"","server":"852c0f18.d61a7","version":1,"debugenabled":false,"service_domain":"input_boolean","service":"turn_off","entityId":"input_boolean.preset_home","data":"","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":780,"y":400,"wires":[[]]},{"id":"852c0f18.d61a7","type":"server","name":"Home Assistant","addon":true}]

For anyone using this and running DSM 7, the API has slightly changed making the login API call non-functional with the above urls.

The URL below is fully functional on my system running the latest DSM 7:

http://YOURIP:PORT/webapi/entry.cgi?api=SYNO.API.Auth&method=Login&version=6&account=USERNAME&passwd=PASSWORD&session=SurveillanceStation&format=sid
1 Like

Hello, does the method still work for someone else ?

I have the DSM 7.0 and get no cameraid…maybe someone here could write a short tutorial that works ?

I’ve found an more solid way to use the PTZ control from HA. A webhook is an long live token.
Be shure to put the webhook link between “” in order to control your camera.

1 Like

Hi Bstanhope,

thank you for the great tutorial

Unfortunately, the site linked by Bstanhope is dead. Fortunately, it has been captured by the Wayback Machine :slight_smile:

In case that goes away too, I will quickly summarize it here:

  • in Surveillance Station, you configure an Action Rule triggered by a webhook. Under “Actions”, the rule tells the camera to move the way you want it to
  • HAss calls the webhook using rest_command (same as above)

This should work until we can get full PTZ+preset support in HAss :slight_smile: