Disabling offline cameras on zoneminder

Hi,

I’m using zoneminder to manage my IP cameras but found that if one (or more) of them become offline zoneminder start to consume a lot of CPU. The real culprit should be the ffmpeg as it reports a unusual high fps to zoneminder… To avoid this I wrote a pair of automations to enable/disable the cameras. Maybe this could be useful for someone else, so I’m sharing it here.

binary_sensor:
  - platform: ping
    name: Hall Camera
    host: 192.168.x.x.
    scan_interval: 60

  - platform: ping
    name: Garage Camera
    host: 192.168.x.x
    scan_interval: 60

automation:
  - alias: disable offline camera
    trigger:
       - platform: state
         entity_id: binary_sensor.garage_camera
         to: 'off'
         for:
            minutes: 5
       - platform: state
         entity_id: binary_sensor.hall_camera
         to: 'off'
         for:
           minutes: 5
    action:
     - service: notify.<someone>
       data_template:
            message: "camera {{ trigger.entity_id }} offline"
     - service: shell_command.cam_control
       data_template:
          mon_id: >-
            {% if trigger.entity_id == 'binary_sensor.garage_camera' %}
              6
            {% elif trigger.entity_id == 'binary_sensor.hall_camera' %}
              4
            {% endif %}
          mon_function: None

- alias: enable online camera
    trigger:
      - platform: state
        entity_id: binary_sensor.garage_camera
        to: 'on'
        for:
          minutes: 5
      - platform: state
        entity_id: binary_sensor.hall_camera
        to: 'on'
        for:
          minutes: 5
    action:
     - service: notify.<someone>
       data_template:
            message: "camera {{ trigger.entity_id }} online"
     - service: shell_command.cam_control
       data_template:
          mon_id: >-
            {% if trigger.entity_id == 'binary_sensor.garage_camera' %}
              6
            {% elif trigger.entity_id == 'binary_sensor.hall_camera' %}
              4
            {% endif %}
          mon_function: Monitor

shell_command:
  cam_control: >-
    curl -XPOST http://localhost/zm/api/monitors/{{ mon_id }}.json -d "Monitor[Function]={{ mon_function }}&Monitor[Enabled]=1"

You will have to find on zoneminder the ID for each of your camera.

Thanks for sharing.
not sure if you can edit your post so it shows up under “share your projects”?

changed as requested :-).

1 Like