Help with an automation trigger using sensor attribute data

I am attempting to send a sensors attribute as a notification but cant seem to figure out where I am going wrong. I am sure it probably involves using templates but honestly I struggle to get most things working. Here is what I have so far.

  - alias: Severe weather notification
    initial_state: True
    trigger:
        platform: numeric_state
        entity_id: sensor.pws_alerts
        above: 0
    action:
        service: rest_command.discord_notify
        data:
            message: "{{ states.sensor.pws_alerts.attributes.message }}"

I am currently using the wunderground sensor which has a sensor.pws_alerts containing the severe weather alert warning.

I have other automations using the service and it works fine but they are all static text and not dynamic data. Any help would be appreciated.

Try data_template: instead of data:

1 Like

Now I only get empty text instead of {{ states.sensor.pws_alerts.attributes.message }} as the actual message. Here is the data I am attempting to pass to the service

Its as simple as sending the Message attribute to the discord webhook. I simply cant figure it out.

Too much indent maybe… Check yaml syntax to get it right

I always run my YAML through Lint since I am mostly doing this by trial and error. These forums have been awesome for helping me figure this stuff out. Ive been able to get it all working up until now. Log file says nothing because technically the trigger is working, I am just not getting the data I want.

Have you tried sending any of the other attributes as a check?

Actually no I haven’t. Since its multiple lines could that be the issue?

I don’t know, but if you can send other things, it might just be a problem with that single attribute…

That worked. It seems as if Discord webhooks has a pretty tight character limit. Also attributes seem to be case sensitive. Ty for the help!

1 Like