How to identify which entity ID triggered the group status change

Hi,

I have a binary sensor group (binary_sensor.texecom_alarm_contacten). Once that group changes status to “on”, I would like to send a notification that my alarm is triggers. However, I would like to include in that message which binary sensor actually triggered this.

I tried this by creating a template sensor:

  - trigger:
      - platform: state
        entity_id:
          - binary_sensor.texecom_alarm_contacten
    sensor:
      - name: "Entity that changed this group"
        unique_id: Tex_Trigger_ID
        state: >
            {{ trigger.to_state.state }}
        attributes:
          trigger_id_at: >
            {{ trigger.entity_id }}

But the trigger_entity_id returns the group “binary_sensor.texecom_alarm_contacten” and not the binary sensor in this group that actually triggered the status change.

Is there a way to retrieve which entity triggered the group status change?

I’m also open to Node-Red based solutions.

Thanks!

The way you do this is to list of the entity ids in the trigger section (and not use the group sensor)

That would indeed work. However, it would also mean I have to list every individual sensor again in my template sensor (while they are already maintained in the group). Double maintenance etc… I was raised in a way that this should be avoided. :slight_smile:

I was able to do it quite easily in Node-Red (which is fine, since my follow up actions also needed to be defined in Node-Red).

[{"id":"76165f02cca6da54","type":"server-state-changed","z":"2d8992acfe659777","name":"Rookmelder Sensor changed ","server":"a32e766.db9aa88","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.rookmelder_sensoren_alarm","entityidfiltertype":"exact","outputinitially":false,"state_type":"habool","haltifstate":"true","halt_if_type":"bool","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":true,"ignoreCurrentStateUnavailable":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":200,"y":140,"wires":[["159e1b60a14b7345"],[]]},{"id":"159e1b60a14b7345","type":"ha-get-entities","z":"2d8992acfe659777","name":"Get all rookmelder sensoren","server":"a32e766.db9aa88","version":0,"rules":[{"property":"entity_id","logic":"in_group","value":"binary_sensor.rookmelder_sensoren_alarm","valueType":"str"},{"property":"state","logic":"is","value":"on","valueType":"str"}],"output_type":"array","output_empty_results":false,"output_location_type":"msg","output_location":"data.RookmelderSensoren","output_results_count":1,"x":480,"y":140,"wires":[["566cc3f05f8fbe1a"]]},{"id":"566cc3f05f8fbe1a","type":"function","z":"2d8992acfe659777","name":"Identify the contact that triggered the group status change","func":"let trigger_id = msg.data.RookmelderSensoren.reduce((mostRecent, current) => {\n    if (new Date(mostRecent.last_changed) > new Date(current.last_changed)) {\n        return mostRecent;\n    }\n    return current;\n});\n\nreturn {\n    payload: {\n        sensor_id: trigger_id\n    }\n};\n\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":830,"y":140,"wires":[["d746414f2f70ee02","1cecdb1c3c026a7e","f2ea03836a5ccc95"]]},{"id":"a32e766.db9aa88","type":"server","name":"Home Assistant","addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"","connectionDelay":false,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"","areaSelector":"id","deviceSelector":"id","entitySelector":"id","statusSeparator":"","enableGlobalContextStore":false}]