Camera.Record multiple filenames

Hello HA community!
I just had a quick question.
I am trying to add recordings to my camera outputs (currently just do images).
I tried to output with two file paths so that I can have a “latest” and also a time stamp version.
Unfortunately I am doing something wrong, or it just isn’t supported (yet).

This is what I tried in the service tab:



service data:
  "entity_id": "camera.backporch",
  "filename":["/.../backporch_{{ now().strftime('%Y%m%d_%H%M%S') }}.mp4",

If I do one or the other it works, just not both.
I first tried using this, but got an error for duplicate keys:

  "entity_id": "camera.backporch",
  "filename":"/.../backporch_{{ now().strftime('%Y%m%d_%H%M%S') }}.mp4",

So after some reading I found out you can wrap multiple values for a key in [ ], but this is giving an error as well:

template value should be a string for dictionary value @ data['filename']

Traceback (most recent call last):
  File "/usr/src/app/homeassistant/components/websocket_api/", line 121, in handle_call_service
  File "/usr/src/app/homeassistant/", line 1130, in async_call
    processed_data = handler.schema(service_data)
  File "/usr/local/lib/python3.7/site-packages/voluptuous/", line 267, in __call__
    return self._compiled([], data)
  File "/usr/local/lib/python3.7/site-packages/voluptuous/", line 589, in validate_dict
    return base_validate(path, iteritems(data), out)
  File "/usr/local/lib/python3.7/site-packages/voluptuous/", line 427, in validate_mapping
    raise er.MultipleInvalid(errors)
voluptuous.error.MultipleInvalid: template value should be a string for dictionary value @ data['filename']

If anyone has experience and can help me figure out the right way to call the service - or simply know that it cannot be done this way, I would appreciate it.


So I’ve been digging through the HA code (still learning) - and I have found where the error comes from:

In camera.record it imports homeassistant.helpers.config_validation as cv.
This is being used to validate the template (the vol.required line):

        vol.Required(CONF_FILENAME): cv.template,
        vol.Optional(CONF_DURATION, default=30): vol.Coerce(int),
        vol.Optional(CONF_LOOKBACK, default=0): vol.Coerce(int),

Checking out the config_validation module, I found the error is thrown if it finds a list, dictionary, or some other template that is referenced (the if isinstance check):

def template(value):
    """Validate a jinja2 template."""
    from homeassistant.helpers import template as template_helper

    if value is None:
        raise vol.Invalid("template value is None")
    if isinstance(value, (list, dict, template_helper.Template)):
        raise vol.Invalid("template value should be a string")

    value = template_helper.Template(str(value))

SO - my severely limited knowledge of this wants to ask if it would be possibly and fix my issue if the call to cv.template was changed to cv.template_complex. This is the next def in the config_validation module:

def template_complex(value):
    """Validate a complex jinja2 template."""
    if isinstance(value, list):
        return_value = value.copy()
        for idx, element in enumerate(return_value):
            return_value[idx] = template_complex(element)
        return return_value
    if isinstance(value, dict):
        return_value = value.copy()
        for key, element in return_value.items():
            return_value[key] = template_complex(element)
        return return_value

    return template(value)

This appears to loop through lists and dictionaries… so in theory it would allow me to use multiple file paths so that I can save the recording in two locations.

Are there any knowledgeable people who can comment on if this would work? I don’t have experience developing, and don’t know what issues this might cause…