I’m trying to add a timestamp to the camera.snapshots and send the image to a persistent notification. I would like to define the timestamp only once and put the timestamp in a string variable. Afterwards I would like to reuse that variable to send out the persistent notification.
When doing this I will have a unique photoname and it will not be subject on browsers image cache. I tried using the data_template within the persistent notification but I did not get it working.
The best thing I have right now is creating two camera snapshots, one for just archiving and one to use with the persistent notification.
Any help to get it working with defining the timestamp into a variable and re-using it in the persistent notication is welcome.
you can set value of input_datetime and use it for generating timestamps (as I can see you use word timestamp to describe a string representation of date/time, is that correct)?
I just worked up a test automation and used an input text to save the timestamp and it works great for me. As a matter of fact I think I’m going to save it for my own use now. I’ve already got a couple of camera snapshot automations but I’ve been wanting to do something like this for a while but just kept putting it off.
Thanks for giving me the nudge!
Here is my automation I used using my own entities and english But I think you can adapt it back to your own stuff easily enough:
input_text:
deck_snap_timestamp:
name: Timestamp for Deck Camera Snapshot test
automation:
- alias: 'gatorade button push test snapshot actions'
trigger:
- platform: event
event_type: gatorade_button_pressed
action:
- data:
message: Someone is in the CR
title: Gatorade Button Pressed
service: notify.pushbullet_notify
# - data:
# deviceID:
# - ipad_living
# entity_id: camera.cam_voordeur
# large: true
# service: browser_mod.more_info
- service: input_text.set_value
entity_id: input_text.deck_snap_timestamp
data_template:
value: '{{ now().strftime("%Y%m%d_%H%M%S") }}'
- data:
filename: /config/www/snapshots/{{ states.input_text.deck_snap_timestamp.state }}_deck.jpg
entity_id: camera.deck
service: camera.snapshot
- delay: 00:00:02
- data_template:
message: 'Someone is in the CR: [photo deck](https://xxxxxxxxxxxxxxx.ui.nabu.casa/local/snapshots/{{ states.input_text.deck_snap_timestamp.state }}_deck.jpg)'
title: Gatorade Button Pressed test
service: persistent_notification.create
# - delay: 00:01:00
# - service: browser_mod.close_popup
Thank you finity, this was exactly what I was looking for. I didn’t understand how to use the data_template integration together with a camera snapshot. Now it is clear I need to use a different service for this.
Thank you very much for the example code and good luck with your own integration
While debugging I was stuck using data_templates from within the automations GUI and was starting to implement the datetime, date and time variables to test with. I figured that they could be useful later on as well.
After debugging I came to the conclusion that it had to do with parsing the datetime object and using the correct single quotes, and using them twice… The automation GUI translated this and I reused it directly inside the automation.yaml.
I don’t know if what I’m using is the best approach but for now it’s the only way I can get everything working.
The only thing odd is that I can’t use the Automations GUI to set the correct data template.
I never use the GUI for writing anything (automations, scripts, lovelace…). I always write it out by hand.
I don’t like the way it formats everything (like in your example) and writing it out by hand is almost as fast for me. Especially when you add in needing to use all of the drop down lists and scrolling thru to find what you want in the long lists. Then, again using your example, there’s the ambiguity of using templates and what syntax the editor is expecting.
It’s just a personal preference tho. But most users who have been around for very long prefer to hand write the yaml. So that says something.
just a fact they have that skill because at those days there was nothing but yaml
well, add to it the fact that almost all UI editors have their limitations comparing to yaml (and some bugs, too)
the bottom line is one uses UI if that’s what they comfortable with and something else if it limits them.
I don’t like generated automations and I almost hate Lovelace-sorted configs… but have to live with it