Hi all,
I’ve configured correctly home assistant to interact with zoneminder. So now I can see my 4 cameras. 2 of them have PTZ support. From zoneminder I can move them, but I have no idea how to do that from Hass.
Any suggestion?
Thanks, Simon
One way you could do it:
Seems interesting! I’ll follow this way, even I fear it will not be so easy for me. Thanks! Simon
I found out it’s the easiest way to integrate cameras. Because ZM is good at it, and the PTZ script can be called even when ZM is off.
Use case : ZM is started (modect) only when nobody’s home. But I want to be able to have the camera display even if ZM is off. So my cams are declared both ways : ZM and “direct”. But doing PTZ the direct way is a pain, especially when you already have ZM able to do so !
1 : create one shell command
zm_ptz: 'sudo /usr/bin/zmcontrol.pl --id {{ id_cam }} -command=presetGoto -preset={{ id_preset }}'
2 : for each position you want to reach, create a script that calls this shell
ptz_garage: alias: Garage sequence: - service: shell_command.zm_ptz data_template: id_cam: '{{ 2 }}' id_preset: '{{ 1 }}'
See that you’ll have to retrieve the camera ID in ZM and the number of the preset you’ll want to reach.
3 : the script can be used everywhere in HA. For instance in lovelace, I have a picture element card, with scripts to call as button over the cam image. Something like :
type: picture-elements image: /local/1.jpg elements: - type : image entity: camera.sous_sol camera_image: camera.sous_sol style: left: 50% top: 50% width: 100% height: 100% - type: icon icon: mdi:car-convertible entity: script.ptz_garage tap_action: action: call-service service: script.ptz_garage hold_action: action: more-info style: left: 5% top: 95%
It looks like this (this my basement, right now, so really dark !) :
The only problem with that solution is that you have to have zoneminder in the same ‘computer’ as home assistant. Any way to make it work with a docker install?
Edit: A bit more information on what I want to achieve. I have Hass running in a docker container. Zoneminder is running on the docker host computer. So I need Hass inside the docker to access zmcontrol.pl on the host.
I have both services on the same VM, no container.
I would think “ssh” to run a distant command on the ZM machine. There is also the ZM API but I’m not aware how to use it.
Hello, my solution was to make a small modification in the official zoneminder integration and create a service to ptz
Follow the link with the necessary modifications
Basically a ptz function
def ptz_move_camera(call):
camera_id = call.data["camera_id"]
move_direction = call.data["move_direction"]
params = {
"view": "request",
"request": "control",
"id": camera_id,
"control": move_direction,
"xge": 43,
"token": zm_client._auth_token,
}
requests.request(
method="POST", url="{}{}".format(zm_client._server_url, "index.php"), params=params,
)
hass.services.register(DOMAIN, SERVICE_PTZ_MOVE_CAMERA, ptz_move_camera)
Service Layout
ptz_move_camera:
description: Move the ZoneMinder Camera
fields:
camera_id:
description: The string id of the ZoneMinder camera.
example: '1'
move_direction:
description: The string name of the ZoneMinder direction.
example: 'moveConRight'
The camera_id is the id camera in zoneminder and the move_direction is the direction you would like the camera move
With everything done just perform a call_service
I will create an issue proposing this improvement
This would be a nice feature. I recently implemented this functionality using Shell command. But doing it directly on zoneminder integration would be much better.
Could you create a PR so that everyone got this feature in futur HA release?