I’m trying to sequentially iterate a camera snapshot filename by adding a helper:counter suffix to the filename to limit the number of saved files to the max value of the helper:counter (which hopefully will restart at 0 once the max is reached).
So I would like the filename to increment something like:
filename0.jpg
filename1.jpg
filename(max counter).jpg
then back to:
filename0.jpg
thus starting over by overwriting files to keep the number of saved files to a manageable level.
Any insight is appreciated.
The following works in the HA Template Editor but not in the automation.
{% set part1 = "/config/camera_files/camera.esp32cam1/on_motion/snapcam_" %}
{% set part2 = states('counter.counter_sequential') | string %}
{% set part3 = ".jpg" %}
{% set part4 = part1+part2+part3 %}
{{ part4 }}
But in the following automation (line70) once saved, changes from:
filename: {{ part4 }}```
to
filename:
"[object Object]": null```
and line 70 outputs this error:
Error: extra keys not allowed @ data['variables']
This is the automation code:
alias: Take ESP32Cam Snapshot
description: Use as sample code for other automations
trigger:
- platform: state
entity_id:
- binary_sensor.occup_living_room
from: "off"
to: "on"
condition:
- condition: state
entity_id: device_tracker.moto_g_5g_2022
state: not_home
enabled: true
action:
- if:
- condition: state
entity_id: light.tz3000_plug1_esp32cam_light
state: "off"
then:
- service: light.turn_on
metadata: {}
data: {}
target:
entity_id: light.tz3000_plug1_esp32cam_light
- wait_for_trigger:
- platform: template
value_template: "{{ states('camera.esp32cam1_camera') == 'idle' }}"
timeout:
hours: 0
minutes: 0
seconds: 8
milliseconds: 0
enabled: true
- if:
- condition: state
entity_id: switch.tz3000_okaz9tjs_ts011f_pwr_plug0
state: "off"
then:
- service: switch.turn_on
target:
entity_id: switch.tz3000_okaz9tjs_ts011f_pwr_plug0
data: {}
- if:
- condition: state
entity_id: switch.tz3000_okaz9tjs_ts011f_pwr_plug1
state: "off"
then:
- service: switch.turn_on
target:
entity_id: switch.tz3000_okaz9tjs_ts011f_pwr_plug1
data: {}
- delay:
hours: 0
minutes: 0
seconds: 4
milliseconds: 0
- wait_template: "{{ states('camera.esp32cam1_camera') == 'idle' }}"
continue_on_timeout: true
enabled: true
timeout: "00:00:07"
- service: camera.snapshot
target:
entity_id: camera.esp32cam1_camera
data:
variables: >-
{% set part1 =
"/config/camera_files/camera.esp32cam1/on_motion/snapcam_" %} {% set
part2 = states('counter.counter_sequential') | string %} {% set part3
= ".jpg" %} {% set part4 = part1+part2+part3 %}
filename: {{ part4 }} #NOTE: once saved "{{ part4 }}" changes to "[object Object]": null
- service: notify.mobile_app_moto_g_5g_2022
data:
message: TTS http://youtu.be/Bc33pm4-nnM
title: test tts & snapshot
data:
sticky: "true"
notification_icon: midi:dorbell-video
color: red
image: >-
http://192.168.50.135/local/camera_files/camera.esp32cam1/on_motion/*.jpg
actions:
- action: URI
title: open camera
uri: /my-history/esp32-cam
- action: LIVING_RM_LIGHTS_ON
title: Turn on LV Lights
- delay:
hours: 0
minutes: 0
seconds: 2
milliseconds: 0
- service: switch.turn_off
target:
entity_id:
- switch.tz3000_okaz9tjs_ts011f_pwr_plug0
- switch.tz3000_okaz9tjs_ts011f_pwr_plug1
data: {}
mode: single