My 1st post, so forgive my transgressions. I am also VERY new to HA and especially automation.
I wrote a script to record a camera stream given the entity and duration. I want the filename to use the friendly name instead of the full entity string. I have tried many suggestions but none have worked for whatever reasons. I have listed the latest version. It works except it names the stream “camera.c120_minorStream…” I want it to start “SideYard…” like I see in the logbook message I created. (I also don’t understand the nuances of quotes and spaces and such in the syntax, but that’s another topic.)
One thing I see aside from whether the actual code is correct or not, all templates, things in {{ }} brackets need to be in quotes or proceeded by a designator in the prior line These are > | in certain cases
You have a couple of things that are not.
The next tricky thing is the path name. The path is usually not what you think it is. Media source - Home Assistant.
The use ", ', >, | is part of my confusion. I see things done various ways in examples and posts and never really know what to do or exactly what the nuances are. I am having trouble finding a concise language syntax/semantic definition, so a link to one would be great. What I typically find are fairly narrow topics that assume I know everything else – somewhat like learning English from a dictionary.
Anyway, I took you suggestion and enclosed all {{}} in “” (there were only two where they were not already). The only change was the logbook message, which went from “SideYard” (when there were no quotes) to “camera.c120_minorStream” (when I added the quotes). (I didn’t post updated script because the change was small I wanted to avoid clutter. But I will surely post the final script once it works.)
Two things are puzzling (to me) about this. First, what is the semantic definition of the added quotes that caused the logbook message to change (between two “reasonable” values)? And why did the filename not change whether or not the quotes were there?
I read a little more and noodled around with the {{}} stuff and found something that works. I will list it below, but would appreciate telling me if the syntax is correct, especially with respect to the quotes and {{ }} stuff, or if this just works by happenstance. Also, to be clear, is it true that all instances of the {{ }} constructs are Templates (in the sense of Jinja)? And do all the HA references to Templates imply Jinja?
Neither of those are quoted, and the path is still wrong.
I’m sorry I can’t help more, I’m traveling and don’t have all my tools at hand.
Look at those links and add what you need to to help with your path for media_source, local, and that stuff.
Thanks again for the help. Your development advice is exactly how I proceeded. I didn’t add templates until I had it working with direct entities. Then I added fields with hard-coded filenames. Then tried to make friendly (shorter) filenames, which is where I got stuck.
I’m not still sure how the path is wrong since the files are being created exactly where I expect them. This might be one of those “just happens to work even though its wrong” things. Still, I would like to understand what is wrong.
Thanks for your input and advice so far and I look forward to hear from you when you return. Meanwhile, the script now does what I wanted, so I can live it with for now.
@Sir_Goodenough, as I said in my last post, the original topic of the thread appears to be working – I able to name my recordings according to the friendly name. And the files are where I expect them to be. But I am still concerned that with your comment that “… the path is still wrong.” When you return, I would be grateful for any details about how it is wrong. Below is a relevant excerpt from my configuration.yaml file.
I tend to point to here in for calling my mp3 sound calls, for instance: media-source://media_source/local/mp3
Here mp3 is a lower folder from the /local/.
This is the homeassistant.yaml:
media_dirs:
local: /media
The /local/ in the top one is internally replaced by the local: path listed in the bottom one.
For simple paths id complicates things,but for more complex ones…
Thanks for your help and advice, and especially thank you for making your production HA files available on github. One the things I find difficult is getting complete solutions understandable to a complete noob like me. Having a full working system as an example is helpful to overcome the “inside baseball” feeling I often get when reading some of the threads or documentation – somewhat akin to learning a new language by reading a dictionary.