Notify.send_message in 2024.6

The notify entities that will be the targets of the notify.send_message service are still being phased in… though it looks like the File notifier should be functional:

While data_template still works in older integrations, it was deprecated over 2 years ago; so it won’t be added to new or updated integrations. I haven’t personally tested File, but you may just need to use data in your service call instead of data_template.

I had exactly the same issue and I confess I found the documentation very difficult to follow. In the end, after a lot of trial and error, I found the following worked for me.

  • Keep the notify: configuration in configuration.yaml the same;
  • In the automation, change the service to notify.send_message and use notify. Weather as the entity_id for the target.
  • Change data_template: to data:

So the action in your automation would become:

service: notify.send_message
  target:
    entity_id: notify.Weather
  data:
    message: >
      {{ now().strftime(‘%d/%m/%Y %H:%M’) }}, {{
      states(‘sensor.weather_temperature’) | float }}, {{
      states(‘sensor.weather_relative_humidity’) | float }}, {{
      states(‘sensor.weather_grass’) | float }},
      … etc

If I have not got this right, I would really like to know.

1 Like

Just a heads up, have you tested your message code in the developer tool?

You have smart quotes vs the standard single quotes necessary. It may have just been a copy/paste issue, but anyone copying the code will have issues.

message: >
      {{ now().strftime('%d/%m/%Y %H:%M') }}, {{
      states('sensor.weather_temperature') | float }}, {{
      states('sensor.weather_relative_humidity') | float }}, {{
      states('sensor.weather_grass') | float }},

Sorry, I have not tested the code in a developer tool - that was the code used by @ahudson . I have used similar code in my automation and it works. I suspect I made a copy and paste error.

I agree that the documentation has been little help. I’m really struggling to figure out what changed here and how it will affect me.

Thank you for offering what you’ve learned through testing! Since I haven’t taken the plunge to update to 2024.6.x yet, I can go through and change data_template: to data: in my automations before updating, and at least have one less potential problem.

where we had this before:

      service: notify.filed_notifications
      data:
        message: >
          {% set message = trigger.event.data.service_data.message %}
          {% set service = trigger.event.data.service %}
            {{now().strftime('%d %b: %X')}} - {{service}}: {{message}}

we need to replace it with this now:

      service: notify.send_message
      target:
        entity_id: notify.filed_notifications
      data:
        message: >
          {% set message = trigger.event.data.service_data.message %}
          {% set service = trigger.event.data.service %}
            {{now().strftime('%d %b: %X')}} - {{service}}: {{message}}

thats all :wink:

admit it would have helped if this was in the documentation.

4 Likes

Thank you so much! It’s starting to make sense.

Did I read somewhere that the update to 2024.6.x will be making this change automatically, or is it something I need to do before updating?

Only the move from the notify.yaml (or configuration.yaml) to UI is done automatic, your automations you need to do manually.

1 Like

Good to know, thanks!

Do you know if the migration also creates the needed allowlist_external_dirs entries in configuraiton.yaml?

It did not in my case

1 Like

Do you know if we need to local directories (like config) to the allowlist_external_dirs list? And if so, what the syntax might be?

Hello,

I have also problems with the new file notification.
This is the old working version:

    - service: notify.energie
      data_template:
        message: "{{now().day}}-{{now().month}}-{{now().year}},
          {% if now().weekday() in (0,) %}Monday{% elif now().weekday() in (1,) %}Tuesday{% elif now().weekday() in (2,) %}Wednesday{% elif now().weekday() in (3,) %}Thursday{% elif now().weekday() in (4,) %}Friday{% elif now().weekday() in (5,) %}Saturday{% elif now().weekday() in (6,)%}Sunday{% endif %},
          {{ states.sensor.energie_meter_dag.state }},
          {{ states.sensor.energie_dag_afname.state }},
          {{ states.sensor.energie_dag_opbrengst.state }},
          {{ states.sensor.energie_meter_nacht.state }},
          {{ states.sensor.energie_nacht_afname.state }},
          {{ states.sensor.energie_nacht_opbrengst.state }},
          {{ states.sensor.energie_meter_zon.state }},
          {{ states.sensor.energie_gas.state }},
          {{ states.sensor.energy_verw_badk_yesterday.state }}"

I thought this was the new version but apperently, it doesn’t work:

    - service: notify.send_message
      target: 
        entity_id: notify.energy
      data:
        message: "{{now().day}}-{{now().month}}-{{now().year}},
          {% if now().weekday() in (0,) %}Monday{% elif now().weekday() in (1,) %}Tuesday{% elif now().weekday() in (2,) %}Wednesday{% elif now().weekday() in (3,) %}Thursday{% elif now().weekday() in (4,) %}Friday{% elif now().weekday() in (5,) %}Saturday{% elif now().weekday() in (6,)%}Sunday{% endif %},
          {{ states.sensor.energie_meter_dag.state }},
          {{ states.sensor.energie_dag_afname.state }},
          {{ states.sensor.energie_dag_opbrengst.state }},
          {{ states.sensor.energie_meter_nacht.state }},
          {{ states.sensor.energie_nacht_afname.state }},
          {{ states.sensor.energie_nacht_opbrengst.state }},
          {{ states.sensor.energie_meter_zon.state }},
          {{ states.sensor.energie_gas.state }},
          {{ states.sensor.energy_verw_badk_yesterday.state }}"

Any idea how to solve it?

E.

What error do you get ?

Never mind, I did something stupid…
entity_id must be notify.energie in stead of notify.energy.

Sorry to disturb you :wink:

Sorry I have been quiet.

@hbradlow - thank you VERY much for your reply. Your fix worked first time. The documentation is very sketchy in this area. A simple example would be so useful.

I added the “allowlist_external_dirs” but I am darned if I can find the documentation for that anywhere.

Once again, thank you!

EDIT: I found the info on allowlist_external_dirs. Google’s crawl of the documentation is out of date and it takes me to

…but that page has been edited recently and the relevent info is at

This worked perfectly @hbradlow . Never would have figured it out in a million years with the available documentation. Thank you!

Hello, I have the problem that the directory and file could not be installed.
I removed the
#notify:
# - name: write_to_csv_energie
# platform: file
# filename: /share/Hermes1/Home_Assistant_Energie.csv
# timestamp: false
# - name: write_to_csv_temperatur
# platform: file
# filename: /share/Hermes1/Home_Assistant_Temperatur.csv
# timestamp: false
# - name: write_to_csv_energie_geraete
# platform: file
# filename: /share/Hermes1/Home_Assistant_Energie_Geraete.csv
# timestamp: false
In automation I changed:

action:

  • service: notify.send_message
    target:
    entity_id: notify.write_to_csv_temperatur
    data:

Before everything worked proper with access to the files.
Where do I have to give the new permission?
What do I have to change?
I downgraded to the backup.

Best regards Helmut


All directories are now protected, and file write access must be granted in the Home Assistant configuration YAML

################## allow list of directories for file integration to write #############################
homeassistant:
  allowlist_external_dirs:
    - "/share/user_data/tub"
    - "/share/user_data/inverter"
    - "/share/user_data/battery"

Note that these are directories (not the files) and that part directory paths do not work, hence /config will allow access to the config directory, /config/data will allow access only to the /config/data directory and so on.

In your case, you probably need

homeassistant:
  allowlist_external_dirs:
    - "/share/Hermes1"

NOTE:
The new file-write notification integration requires all this to be set up (file integration, write access to the directories, and creation / use of the new target entities) and the update automatically sets (most of) this up, however the old YAML “notify” still works! It will be deprecated later this year, but you can still use it if you wish… If you do, you will get a warning notification, but you can ignore that.

1 Like

Hello,

I am now able to write text lines to a log file in automations.

What I can’t do, however, is to configure this in notify.yaml. My previous setup works, but HA acknowledges it with a message about using an obsolete function.

My setup in notify.yaml is:

 - name: ha_notifications
   service: notify.send_message
   platform: file
   filename: /config/reports/ha-notifications.txt
   timestamp: true

How to change this?

Regards, Eckart