One Notification for multiple Sensors

Hi all,

I’m using the Nintendo Wishlist component which is able to track the price of games in the nintendo eshop. The component creates a sensor for each game which is on the list. Each sensor has the state 0 if the game is not on sale and 1 if the game is on sale. Each has a name like:

sensor.nintendo_wishlist_game_a
sensor.nintendo_wishlist_game_b

And attributes like:

on_sale:
unit_of_measurement: on sale
friendly_name: Nintendo Wishlist game a
icon: mdi:nintendo-switch
custom_ui_state_card: state-card-custom-ui

on_sale:
unit_of_measurement: on sale
friendly_name: Nintendo Wishlist game b
icon: mdi:nintendo-switch
custom_ui_state_card: state-card-custom-ui

I want to create a notification based on the change of the state of the sensor. In the notification I want to see the name of the game. How can I archieve this?
I’ve created a basic notification but dont know how to geht the name from friendly_name of the game which is on sale in the text and how to use a wildcard in the entity id.


  - alias: 'Benachrichtigung wenn eShop Angebot.'
    trigger:
     platform: numeric_state
     entity_id: sensor.nintendo_wishlist_onimusha
     above: 0
    action:
     service: notify.ios_my_devices
     data:
      title: "Nintendo eShop Angebot:"
      message: "Neues Spiel im Angebot"

Can someone give me a hint about what to do next?
Thank you in advance

Trigger on any of the sensors to have a state change to 1, then template the action to include trigger.friendly_name in the notification?

1 Like

almost what @brahmafear said. Try this:

  - alias: 'Benachrichtigung wenn eShop Angebot.'
    trigger:
     platform: numeric_state
     entity_id:
      - sensor.nintendo_wishlist_onimush_a
      - sensor.nintendo_wishlist_onimush_b
      - sensor.nintendo_wishlist_onimush_c
     above: 0
    action:
     service: notify.ios_my_devices
     data_template:
      title: "Nintendo eShop Angebot:"
      message: "Neues Spiel im Angebot: {{ trigger.entity_id.attributes.friendly_name }}"

Note:
This assumes the sensor returns a number (most return a string)
if unsure / if a string is returned, you can then remove the above: 0 line and add a condition:

      - condition: template
        value_template: '{{ trigger.to_state.state | int > 0 }}'

the full automation being:

  - alias: 'Benachrichtigung wenn eShop Angebot.'
    trigger:
     platform: numeric_state
     entity_id:
      - sensor.nintendo_wishlist_onimusha
      - sensor.nintendo_wishlist_onimushb
      - sensor.nintendo_wishlist_onimushc
    condition:
      - condition: template
        value_template: '{{ trigger.to_state.state | int > 0 }}'
    action:
     service: notify.ios_my_devices
     data_template:
      title: "Nintendo eShop Angebot:"
      message: "Neues Spiel im Angebot: {{ trigger.entity_id.attributes.friendly_name }}"

@lolouk44:
Thank you very very much for your help. I understand what to do now.
The only problem I had with your example code is the last Line:

     message: "Neues Spiel im Angebot: {{ trigger.entity_id.attributes.friendly_name }}"

When I use {{ trigger.entity_id.attributes.friendly_name }} in the message i cant trigger the notification:( I dont know how to solve this.

Another thing: How do you people know about this? Did you have a link for me? So that I can help myself in the future?

Again, thank you very much.

What do you mean by

if you mean you can’t trigger the automation manually, then yes it’s correct. as the automation was not triggered by a state change, {{ trigger.entity_id is invalid and therefore the automation fails to run

You can always manually set an entity’s state (Developer Tools > States > Set State) to trigger an automation

I change the value from one of the entities to 1.
The automation is triggered but i dont get the value of “friendly_name”. When I delete {{ trigger.entity_id.attributes.friendly_name }} I get the the notification.

Did you have any clue why this happend?

hum odd.
Can you try this instead: state_attr(trigger.entity_id, 'friendly_name')
so the full line would be:

message: "Neues Spiel im Angebot: {{ state_attr(trigger.entity_id, 'friendly_name') }}"

This works, but instead of the friendly name of the entity it shows “None”

Strange.

that just means that there is no such attribute in your entity and that’s why you didn’t get notification with your original code.

try this:

message: "Neues Spiel im Angebot: {{ state_attr(trigger.to_state, 'friendly_name') }}"