Get all entity values from one single device

Hello community,

i am happy to join this community. Let me know if I miss any rules of conduct!
But now my question:

I have connected a Aqara motion sensor via zigbe2mqtt to Homeassistant. I am using the “Event: State” node in NodeRed to react on state changes to turn on the light based on detected motion. Now i want to increase or decrease the light level based on the detected lux level of the motion sensor.

Here is a simple example of my actual setup (import it in node red):


[
    {
        "id": "7aed969a2bd869dc",
        "type": "server-state-changed",
        "z": "2c0a0e68adf6163b",
        "name": "motion",
        "server": "5e373819.692cb8",
        "version": 5,
        "outputs": 2,
        "exposeAsEntityConfig": "",
        "entityId": "binary_sensor.ankleidezimmer_bewegungssensor_occupancy",
        "entityIdType": "exact",
        "outputInitially": false,
        "stateType": "str",
        "ifState": "off",
        "ifStateType": "str",
        "ifStateOperator": "is",
        "outputOnlyOnStateChange": true,
        "for": "10",
        "forType": "num",
        "forUnits": "seconds",
        "ignorePrevStateNull": false,
        "ignorePrevStateUnknown": false,
        "ignorePrevStateUnavailable": false,
        "ignoreCurrentStateUnknown": false,
        "ignoreCurrentStateUnavailable": false,
        "outputProperties": [
            {
                "property": "payload",
                "propertyType": "msg",
                "value": "",
                "valueType": "entityState"
            },
            {
                "property": "data",
                "propertyType": "msg",
                "value": "",
                "valueType": "eventData"
            },
            {
                "property": "topic",
                "propertyType": "msg",
                "value": "",
                "valueType": "triggerId"
            }
        ],
        "x": 90,
        "y": 800,
        "wires": [
            [
                "87dbbc7288472de4"
            ],
            [
                "2b69a334788c4b63"
            ]
        ]
    },
    {
        "id": "2b69a334788c4b63",
        "type": "api-call-service",
        "z": "2c0a0e68adf6163b",
        "name": "",
        "server": "5e373819.692cb8",
        "version": 5,
        "debugenabled": false,
        "domain": "light",
        "service": "turn_on",
        "areaId": [],
        "deviceId": [
            "46f1fd5b9217a2cd1adb3aee68e93861"
        ],
        "entityId": [],
        "data": "",
        "dataType": "jsonata",
        "mergeContext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 290,
        "y": 820,
        "wires": [
            []
        ]
    },
    {
        "id": "87dbbc7288472de4",
        "type": "api-call-service",
        "z": "2c0a0e68adf6163b",
        "name": "",
        "server": "5e373819.692cb8",
        "version": 5,
        "debugenabled": false,
        "domain": "light",
        "service": "turn_off",
        "areaId": [],
        "deviceId": [
            "46f1fd5b9217a2cd1adb3aee68e93861"
        ],
        "entityId": [],
        "data": "",
        "dataType": "jsonata",
        "mergeContext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 290,
        "y": 760,
        "wires": [
            []
        ]
    },
    {
        "id": "5e373819.692cb8",
        "type": "server",
        "name": "Home Assistant",
        "addon": true
    }
]

The problem is that I can only read the value of the motion entity (binary_sensor.ankleidezimmer_bewegungssensor_occupancy).

How can I get all (or a specific) entity values from one single device in one payload?

Regards

Here is my actual workaround for this:

[
    {
        "id": "46d8fe6a82c2debd",
        "type": "server-state-changed",
        "z": "d3cb46827cf84d29",
        "name": "Ankleidezimmer-Bewegungssensor",
        "server": "5e373819.692cb8",
        "version": 5,
        "outputs": 2,
        "exposeAsEntityConfig": "",
        "entityId": "binary_sensor.ankleidezimmer_bewegungssensor_occupancy",
        "entityIdType": "exact",
        "outputInitially": false,
        "stateType": "str",
        "ifState": "off",
        "ifStateType": "str",
        "ifStateOperator": "is",
        "outputOnlyOnStateChange": true,
        "for": "10",
        "forType": "num",
        "forUnits": "seconds",
        "ignorePrevStateNull": false,
        "ignorePrevStateUnknown": false,
        "ignorePrevStateUnavailable": false,
        "ignoreCurrentStateUnknown": false,
        "ignoreCurrentStateUnavailable": false,
        "outputProperties": [
            {
                "property": "payload",
                "propertyType": "msg",
                "value": "",
                "valueType": "entityState"
            },
            {
                "property": "data",
                "propertyType": "msg",
                "value": "",
                "valueType": "eventData"
            },
            {
                "property": "topic",
                "propertyType": "msg",
                "value": "",
                "valueType": "triggerId"
            }
        ],
        "x": 160,
        "y": 740,
        "wires": [
            [
                "efa2c8d3e11b2494"
            ],
            [
                "efa2c8d3e11b2494"
            ]
        ]
    },
    {
        "id": "efa2c8d3e11b2494",
        "type": "function",
        "z": "d3cb46827cf84d29",
        "name": "Magic",
        "func": "const lux = global.get('homeassistant.homeAssistant.states[\"sensor.ankleidezimmer_bewegungssensor_illuminance_lux\"].state');\nconst motion = global.get('homeassistant.homeAssistant.states[\"binary_sensor.ankleidezimmer_bewegungssensor_occupancy\"].state');\n\nconst mapNumRange = (num, inMin, inMax, outMin, outMax) => ((num - inMin) * (outMax - outMin)) / (inMax - inMin) + outMin;\n\nif(motion == \"off\") {\n    \n    msg.payload = {\n        \"service\": \"turn_off\"\n    }\n    \n    return msg\n}\n\nif(motion == \"on\") {\n\n    msg.payload = {\n        \"service\": \"turn_on\",\n\n        \"data\": {\n            \"brightness_pct\": mapNumRange(lux, 0, 400, 1, 100)\n        }\n    }\n\n    return msg\n}",
        "outputs": 1,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 430,
        "y": 740,
        "wires": [
            [
                "6cbe672e1e231095"
            ]
        ]
    },
    {
        "id": "6cbe672e1e231095",
        "type": "api-call-service",
        "z": "d3cb46827cf84d29",
        "name": "Ankleidezimmer-Deckenlampe",
        "server": "5e373819.692cb8",
        "version": 5,
        "debugenabled": false,
        "domain": "light",
        "service": "",
        "areaId": [],
        "deviceId": [
            "46f1fd5b9217a2cd1adb3aee68e93861"
        ],
        "entityId": [],
        "data": "{}",
        "dataType": "json",
        "mergeContext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 670,
        "y": 740,
        "wires": [
            []
        ]
    },
    {
        "id": "5e373819.692cb8",
        "type": "server",
        "name": "Home Assistant",
        "addon": true
    }
]

I am using a node red function and this code to get the value of single entity values:

const lux = global.get('homeassistant.homeAssistant.states["sensor.ankleidezimmer_bewegungssensor_illuminance_lux"].state');

But anyway I still have the same question:
Is there an easy way to get all devices entities in one payload if there is a state change from one of this entities?