Which entity triggered group?

If I group all of my window binary sensors into a group and use that as a trigger for my alarm how can I determine which entity triggered the group? I want the group to trigger the alarm then notify me via telegram “(entity) window opened.” I can do this easily with single entities but am having trouble when they are grouped.

If you use a substring or regex match on the entity ID in Node-RED, the topic argument passed with the msg will be set to the entity ID. I do this for battery level notifications:

(Notice that I use "message": "{{ topic }}" in the data sent to the notification)

[
    {
        "id": "766ed452.b9b32c",
        "type": "api-call-service",
        "z": "ae24065a.1aeef8",
        "name": "Send push",
        "server": "74d5538b.e0092c",
        "version": 1,
        "debugenabled": false,
        "service_domain": "notify",
        "service": "mobile_app_paul_pixel",
        "entityId": "",
        "data": "{\"title\": \"🔋 Battery level low\", \"message\": \"{{ topic }}\"}",
        "dataType": "json",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 310,
        "y": 400,
        "wires": [
            [
                "bdf345f3.52b418"
            ]
        ]
    },
    {
        "id": "1850442a.5ef95c",
        "type": "server-state-changed",
        "z": "ae24065a.1aeef8",
        "name": "Battery level",
        "server": "74d5538b.e0092c",
        "version": 1,
        "exposeToHomeAssistant": false,
        "haConfig": [
            {
                "property": "name",
                "value": ""
            },
            {
                "property": "icon",
                "value": ""
            }
        ],
        "entityidfilter": "^sensor\\..*battery_level",
        "entityidfiltertype": "regex",
        "outputinitially": false,
        "state_type": "num",
        "haltifstate": "10",
        "halt_if_type": "num",
        "halt_if_compare": "lte",
        "outputs": 2,
        "output_only_on_state_change": true,
        "x": 130,
        "y": 400,
        "wires": [
            [
                "766ed452.b9b32c"
            ],
            []
        ]
    },
    {
        "id": "74d5538b.e0092c",
        "type": "server",
        "z": "",
        "name": "Home Assistant",
        "legacy": false,
        "hassio": true,
        "rejectUnauthorizedCerts": true,
        "ha_boolean": "y|yes|true|on|home|open",
        "connectionDelay": true,
        "cacheJson": true
    }
]

Thanks, but I had trouble applying this. I’m not exactly sure how regex works. From the looks of it the “^sensor\…*battery_level” just looks for anything that is a sensor and has an attribute name battery_level? Is there a guide on how to work this to whatever I want? I ended up using a get entities node after the event state node and that seems to work for now.

This is what I am using: Something similar to regex but you can use substrings as entity id in trigger:state node. This is assuming all your motion sensors have the name “motion” in it.

Then you can get the which motion sensor triggered alarm with this msg.data.event.new_state.attributes.friendly_name

image

I don’t think yuo can, all that individual state is hidden by the group entity. I suppose you could try to iterate over all the group members and check their state individually, but then you might as well just house them each as triggers…

This is how I do it. I use “binary_sensor.*_contact_sensor” for my contact sensors (and same for my motion sensors). In my function, I use this to get the device that triggered the alert:

var device  = msg.data.old_state.attributes.friendly_name;
var type    = msg.topic.includes("contact_sensor") ? "contact" : "motion";
var message;

if(type == "contact") {
    message = device + " has been " + msg.payload == "on" ? "opened" : "closed";
}
else {
    message = "Activity has " + (msg.payload == "on" ? "been detected" : "stopped") + " on " + device;
}

msg = {
    topic: "HASM Alert",
    url: "https://[my_ha_external_address]/",
    url_title: "Home Assistant",
    timestamp: new Date().getTime(),
    payload: message
};

return msg;