Swap cameras

I have several cameras (some are not always active).
Because the space on my front page is limited, I would like to switch between the cameras every x-second, in the same place. When a camera detects a movement, the switch must stop.

If a camera is not active, it should not be included in the sequence

Is this possible by making something like a loop ?

This is what you need

Thank you, I will examine this. Does it stop rotation when a motion is detected ?
At first sight it won’t

I have similar need to show 3 cameras in a loop within a card and re-purposed Slideshow card for that. Excellent card BTW, works great except I can’t figure out how to skip showing camera(s).

Prompted by your question, I just re-work my setup using this:

  - type: conditional
    conditions:
      - entity: input_number.camera_loop
        state_not: "9"
    card:
      type: picture-glance
      title: Camera Loop
      state_image:
        0: https://localhost:8123/api/camera_proxy_stream/camera.carport?api_password=password
        1: https://localhost:8123/api/camera_proxy_stream/camera.dining?api_password=password
        2: https://localhost:8123/api/camera_proxy_stream/camera.kitchen?api_password=password
      entity: input_number.camera_loop
      entities:
        [camera.carport, camera.dining, camera.kitchen]

To drive this card:

  • camera_loop controls which camera to display or not display card at all
  • an automation triggers every x second (display duration) to call a python script to update camera_loop based on motion detection state of camera

I also have 3 separate picture-glance cards to display each camera only when motion detected. So the camera is either shown in the loop card or its own.

1 Like

Looks nice. I will try this asap.

I know this is old but do you mind sharing your Python script, if you still have or run it?

Sure, not sure the camera_proxy_stream with api_password method is still working though.
Have not used that for a while but here is the python_script:

python_scripts\cameraloop.py:

# list of motion sensors correspond to cameras
motionList = data.get('motionList','group.garage_mvmnt,group.dining_mvmnt,group.kitchen_mvmnt')
motionList = motionList.split(",")

totcam=len(motionList)
maxlisti=totcam-1

# set the input_number.camera_loop
def set_loop(hass,loopid,state,chk):
  hass.states.set('input_number.'+loopid,state, {
     'initial': '0',
     'min': '0',
     'max': '10',
     'step': '1',
     'mode': 'slider',
     'friendly_name': loopid,
     'cnt': chk
     })
  return


chk=hass.states.get('input_number.camera_loop')
if ( chk is None ):
  #start with [0] if not exist
  set_loop(hass,'camera_loop',0,1)
else:
  # increment the camera_loop
  loopi=int(float(hass.states.get('input_number.camera_loop').state))
  if loopi < maxlisti:
    listi=loopi+1
  else:
    listi=0
  while listi < 9:
    if ( hass.states.get(motionList[listi]).state == 'off' or hass.states.get(motionList[listi]).state == 'not_home'):
      set_loop(hass,'camera_loop',listi,1)
      # logger.warning("chk found>>"+str(listi))
      break
    else:
      if listi == loopi:
        set_loop(hass,'camera_loop',9,1)
        # logger.warning("chk 9>>")
        break
      elif listi == maxlisti:
        listi=0
      else:
        listi=listi+1

Also, this is the automation used:

- id: camera loop
  alias: camera loop
  trigger:
  - platform: time_pattern
    seconds: '/5'
  - platform: template
    value_template: '{% if (is_state("input_number.camera_loop", "0") and is_state("group.carport_mvmnt", "on")) or
                        (is_state("input_number.camera_loop", "1") and is_state("group.dining_mvmnt", "on")) or
                        (is_state("input_number.camera_loop", "2") and is_state("group.kitchen_mvmnt", "on")) or
                        (is_state("input_number.camera_loop", "3") and is_state("group.liv_mvmnt", "on")) or
                        (is_state("input_number.camera_loop", "9") and (is_state("group.carport_mvmnt", "off") or 
                               is_state("group.dining_mvmnt", "off") or is_state("group.kitchen_mvmnt", "off") or 
                               is_state("group.liv_mvmnt", "off"))) %}true{% endif %}'                               
  action:
  - service: python_script.cameraloop

You can skip or modify the template platform your way to trigger immediate change in cameraloop.

Have fun.

1 Like