#Need help with adding YAML code from a community post to HA config

1 messages · Page 1 of 1 (latest)

rocky lake
#

I've never ever done any coding in raw yaml in home assistant before. Until now, i've done ALL automations in the GUI. However, i often see people posting yaml codes with "I just created this smart sensor that can do X" or "i use the X thing to do Y" and i feel very limited when i don't know exactly how to just copy it and make it work. Now i found an example of something i would like, that (as far as i know, with my limited knowledge) cannot be done in the GUI: I would like to have a history of the persistent notifications that are created in Home assistant. I found a community post about it, and it seems a guy did it: https://community.home-assistant.io/t/history-of-notifications/196518 first answer from VDRainer. I tried copying his code into my automation.yaml file in the config folder, but it started throwing a lot of errors that i'm not sure how to resolve.

Any help is very appreciated!

gray nebula
#

where are you putting this yaml? in the configuration file? why not just create an automation using the yaml editor in the ui?

rocky lake
#

yeah, im putting it in the automation.yaml file, which is referenced in the configuration.yaml file

#

i'm not sure how to (re)create this in the gui

gray nebula
#

it's a much safer way to do it if you aren't comfortable with yaml in general

#

That said, I think all you need to do is remove the automation: line and then select all of it and shift+tab it to reduce the indentation level of the remaining text by 1

#

the notify stuff has to be set up differently too, it doesn't go in your automations.yaml

rocky lake
#

Wow, i didn't even think of trying a yaml editor in the automation creation!

#

Now, i'm trying to make it work in there

gray nebula
#

ok yeah, delete the notify stuff for now, and the automation:

#

and then select the rest and shift tab

rocky lake
#

Like this

gray nebula
#

yup

#

that should save now

rocky lake
#

it says: Message malformed: extra keys not allowed @ data['0']

gray nebula
#

oh do

#

you want to delete the "- " before alias

#

and then unindent it all one more time

rocky lake
#

That worked

gray nebula
#

like that

rocky lake
#

And then do another for the notify stuff?

gray nebula
#

easier to go into integrations and then pick file

rocky lake
#

And is that it then?

gray nebula
#

sorry - just looking at it now - i haven't done any logging to file ^^

#

actually looks like the easiest thing to do is go into your configuration.yaml and copy that notify: block in

rocky lake
#

done

gray nebula
#

if there's already a notify: block, just copy the - platform etc underneath what's already there

rocky lake
#

Can i do a fake persistent notification to test?

gray nebula
#

do you have developer tools active?

rocky lake
#

yes

gray nebula
#

you likely have to reload the configuration in the yaml tab as well for the notify changes to kick in too

rocky lake
#

doesn't seem to be working

gray nebula
#

even after reloading the configuration?

#

might need a restart... i don't actually know when the notify reloads

rocky lake
#

wait

#

the automation hasnt been saved

#

i just did it again and i cant find it in the automations overview

gray nebula
#

weird... you didn't mess around with automations import in the configuration.yaml?

rocky lake
#

no

gray nebula
#

i'm gonna poke someone who knows more about the backend than me

rocky lake
#

now it's there

#

but it's still not working

#

This is what i got in the configurations.yaml file

#

And this is the automation

#

This just came up

jade pawn
#

Did you restart HA after adding the notify to your config it's a new key, so it usually needs a restart.

rocky lake
#

no, just did a recheck of configuration

#

I will restart it

#

The error is still there

jade pawn
#

Go to developer tools > services > and look for the notify service and see what options there are.

#

I'm pretty sure you actually need to add that notify service through the UI, I didn't read the YAML before due to it being a screenshot and I wasn't wearing my glasses 😅

rocky lake
#

do you mean developer tools > states? If so:

#

i already added the notify service via the ui by adding the file integration

jade pawn
#

And did you add wherever the file is to the config as per the integration page?

rocky lake
#

yes

indigo hareBOT
rocky lake
jade pawn
#

Make sure that the file you want to use is added to the allowlist_external_dirs. The file will be created if it doesn’t exist, but make sure the folder exists. Add the path of your configuration folder (for example, /config/file_notifications) to save the file there.

rocky lake
#

And here you can see the file opened

jade pawn
#

Good. Then try editing and saving the automation.

rocky lake
#

the error is still there

#

wait

#

i think i know what the problem is

#

in the error, it says: The automation "persistent_notification_log" (automation.persistent_notification_log) has an unknown action: notify.custom_log.

Which might be because when i tried with the yaml code i changed the notify line to match the name i gave the notify sensor/entity/whatever it is called

#

But now that i made it via the ui, i didn't give it a name, so i think that line needs to be changed again, but idk what to, since i didn't give it a name

#

now i've changed the entity ID to notify.pn_log for the file integration. I also changed it in the automation, but it still produces an error. I think it is because the code is missing something, because it doesnt make sense to me that the last line is "action" and the next thing is just a file/integration. Shouldn't it tell more, link open the file, append data or something like that?

jade pawn
#

The action should be to send a notification.

#

The notification action for files has changed. You should try configuring it in the UI, you'll end up with something like this:

target:
  entity_id: notify.log_file
data:
  title: Kitchen Light Switch
  message: >-
    Kitchen Light Level {{ states('sensor.kitchen_light_sensor_illuminance_lux')
    }}
action: notify.send_message

rocky lake
#

I dont get it sorry. Can you send me a screenshot of how i should configure it in the UI?

jade pawn
#

Just try doing it 😉
Add an action, look for notify, and go from there.

rocky lake
#

I really cant get it to work lol

#

When i go to traces and the trace timeline, i can see there is a problem: "Error rendering data template: UndefinedError: 'dict object' has no attribute 'event'" and i guess its the {{ trigger.event.data.service_data.title }} {{ trigger.event.data.service_data.message }} lines, but i don't know how to figure out what it should be instead

gray nebula
#

Did you run the automation manually?

#

Because that results in an empty trigger which would result in an error like that