Notify.send_message in 2024.6

Okay, so my setup writes simple weather log files every 10 minutes - or it did.

I have

notify:

  • name: weather
    platform: file
    filename: “/config/weather.txt”

…in my configuration.yaml, and my automation has

service: notify.weather
data_template:
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

This is now depracated and doesn’t work anymore.

Please can someone show me how to set up the same thing using the new notify.send_message service.

Please format your code as per Section 11 in How to help us help you - or How to ask a good question.

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.

3 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