How to read lock status

Looking to read out the

states.lock.front_door.attributes.lock_status

Can’t seem to pull it off, what node to I need to use? Want to track who unlocked the door and at what time. .lock_status shows “User # Unlocked Door by Keypad.” I can then use a time stamp to append to user # and log it.

Stick a debug node on the lock events state node and make it a complete message debug.
Then you’ll be able to see exactly where that info is stored in the message.

I have, nothing shows up, zero, ziltch, nada, zip. Hence why I’m asking what node I need to use to read that data.

lock.front_door.attributes.lock_status is the point I need to pull the data from(i know that it is in that field). NR can’t seem to do so I suspect its a issue of PEBKAC.

If you stick a debug node after a event: state node, and you mark the debug node as COMPLETE MSG OBJECT, then it will get EVERY piece of information that comes from that entity. If you don’t see any data there, then there is no data. The debug node captures all.

Try this:

Select your lock:

Expand out the lock and read the attributes available. If it is available, a debug node WILL read it, and you can use any method you like to extract the data from it (function, change, switch, etc)

I can drill down to it, . and the data is there in lock.front_door_lock.attributes.lock_status (see below image)

but I don’t know what I’ve got set wrong to extract it. Which has been my issue, I know its there, can see it in HA’s states screen. lock_status shows various messages based on last action with it. Locked/Unlocked by RF. Manually Locked/Unlocked, code unlocked by User X. etc. I just need to extract that string and pass it on to the next node to log it appended with time/date. as I said its a PEBKAC issue.

Debug log shows this error

“Entity could not be found in cache for entity_id: lock.front_door_lock.attributes.lock_status”

i’ve done lock.XXX states.XXX states.lock.XXX all throw the same error.

We might help you better if you can post your entire flow.

Door Unlocks and the inject both trip read lock status with the same error message.

Door unlocks fires when it goes false which is the open status for the lock.

right now its a very limited diagnostic type flow to see how to extract the data first.

I can’t see the inside of nodes. Can you please post the code as well ( you may need to edit out sensitive information)

this what your looking for?

nothin sensitive in such.

Your entity isn’t

It’s lock.front_door_lock

The attributes come FROM the entity. You will have to use a change node or something to output the attributes where you want them.

Change looks to be of no use, I don’t want to change the value, just read it so I can parse it.Can I not extract that specific value/string from the entity? Current state seemed to be logical to read that attribute’s state.

Current state reads the current state of the entity.

You’re not understanding the functionality of the change node. You’re not changing it but you can set another payload to be that attribute…

the state would be whats contained within that value I would have thought when directed to a specific point. is the state only the true false of the high level contact/lock/etc?

I’ve looked at change, I don’t see how it can be used to read that value. I have set/change/delete/move. All require it to be first be read. I haven’t gotten to the point that i can be read yet.

Granted I’m very inexperienced with node red and so am running into what may seem to you to be simple issues.

image

Let’s say I want to extract the next_rising attribute out of this.

So the data I want is msg.data.new_state.attributes.next_rising

Lets’ make a flow.

[
    {
        "id": "4b94865a.9ff478",
        "type": "server-state-changed",
        "z": "196ff00e.dd19f",
        "name": "",
        "server": "d86c8a3e.cc7138",
        "version": 1,
        "exposeToHomeAssistant": false,
        "haConfig": [
            {
                "property": "name",
                "value": ""
            },
            {
                "property": "icon",
                "value": ""
            }
        ],
        "entityidfilter": "sun.sun",
        "entityidfiltertype": "exact",
        "outputinitially": true,
        "state_type": "str",
        "haltifstate": "",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "outputs": 1,
        "output_only_on_state_change": true,
        "x": 300,
        "y": 2240,
        "wires": [
            [
                "d5c5fc28.0156"
            ]
        ]
    },
    {
        "id": "7a1a9c68.b68b74",
        "type": "debug",
        "z": "196ff00e.dd19f",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "x": 770,
        "y": 2240,
        "wires": []
    },
    {
        "id": "d5c5fc28.0156",
        "type": "change",
        "z": "196ff00e.dd19f",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "data.new_state.attributes.next_rising",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 600,
        "y": 2240,
        "wires": [
            [
                "7a1a9c68.b68b74"
            ]
        ]
    },
    {
        "id": "d86c8a3e.cc7138",
        "type": "server",
        "z": "",
        "name": "Home Assistant",
        "legacy": false,
        "hassio": false,
        "rejectUnauthorizedCerts": true,
        "ha_boolean": "y|yes|true|on|home|open",
        "connectionDelay": true,
        "cacheJson": true
    }
]

image

See how the payload changed? I can use this information to output to a telegram bot for example, by formatting this new payload.

1 Like

You already HAVE the data though. You don’t need to read it again. The data is RIGHT THERE in the attributes of the state change. It’s up to YOU to parse it. How do you want it parsed?

1 Like

Yes its in HA and available there. My issue is I’ve yet to figure out how to bring it into the nodes from that attribute to use it.

Before change can use it it has to be available. Can I not target the specific data I want? I don’t want to have to log every bit of the data in the entity, its 99% trash. I specifically want and only want the data from lock.front_door_lock.attributes.lock_status nothing else. it should logically be possible to pull only that data. if I use a string node that allows for a “contains” " user 1" it doesn’t work as it doesn’t seem to be able to find “user 1” when that user unlocks the door. so my thoughts have been that it isn’t receiving that data in any form it can process. its may receive everything but it doesn’t know where to look for it.

I get that the system has it, I get that you can show it has it and how to change it. But I have yet to see or figure out how to extract targeted data.

in simplest terms. I want only the data I want, nothing else. so I want to parse/search the specific data string for “user x” output a true bit, hits the next node that logs User X unlocked at Time Y.

I went ahead and created a notification using the Android mobile app, using my example above, but changed it slightly.

[
    {
        "id": "4b94865a.9ff478",
        "type": "server-state-changed",
        "z": "196ff00e.dd19f",
        "name": "",
        "server": "d86c8a3e.cc7138",
        "version": 1,
        "exposeToHomeAssistant": false,
        "haConfig": [
            {
                "property": "name",
                "value": ""
            },
            {
                "property": "icon",
                "value": ""
            }
        ],
        "entityidfilter": "sun.sun",
        "entityidfiltertype": "exact",
        "outputinitially": true,
        "state_type": "str",
        "haltifstate": "",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "outputs": 1,
        "output_only_on_state_change": true,
        "x": 300,
        "y": 2200,
        "wires": [
            [
                "d5c5fc28.0156"
            ]
        ]
    },
    {
        "id": "d5c5fc28.0156",
        "type": "change",
        "z": "196ff00e.dd19f",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "sunrise",
                "pt": "msg",
                "to": "data.new_state.attributes.next_rising",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 500,
        "y": 2200,
        "wires": [
            [
                "e380d578.8f8788"
            ]
        ]
    },
    {
        "id": "e380d578.8f8788",
        "type": "api-call-service",
        "z": "196ff00e.dd19f",
        "name": "",
        "server": "d86c8a3e.cc7138",
        "version": 1,
        "debugenabled": false,
        "service_domain": "notify",
        "service": "mobile_app_oneplus_6",
        "entityId": "",
        "data": "{\"message\":\"The next time the sun rises is at {{ sunrise }}\",\"title\":\"Sun Rise\"}",
        "dataType": "json",
        "mergecontext": "",
        "output_location": "payload",
        "output_location_type": "msg",
        "mustacheAltTags": false,
        "x": 740,
        "y": 2200,
        "wires": [
            [
                "b96812da.04014"
            ]
        ]
    },
    {
        "id": "b96812da.04014",
        "type": "debug",
        "z": "196ff00e.dd19f",
        "name": "Alert - APP",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "x": 970,
        "y": 2200,
        "wires": []
    },
    {
        "id": "d86c8a3e.cc7138",
        "type": "server",
        "z": "",
        "name": "Home Assistant",
        "legacy": false,
        "hassio": false,
        "rejectUnauthorizedCerts": true,
        "ha_boolean": "y|yes|true|on|home|open",
        "connectionDelay": true,
        "cacheJson": true
    }
]

The data is RIGHT THERE in the attributes of the state change. When the event fired, the attributes are available RIGHT THERE.

It’s already there.

Yes, but every time a state changes, all the attributes are right there in the message object. Again, it’s right there already.

Then go ahead and pull that out of the event state that changed that fired the flow.

You can literally pull any data you want from that event.

Ok, so its there, yes we agree on that. You’re telling me to pull it. What I am saying I do not know how. I don’t seem to be able to do so. Your example is useless to me because I do not understand the underlying code or functionality in it.

I need to pull the string from .lock_status, only from .lock_status, not look at anything else. check that for user 1, set a true if its found so the next sections can then handle logging for me. I’m still working at as we speak here. trying to figure out the solution on my own (I hate being beat by tech). Being totally new to programming in this language I haven’t figured out alot. I have some simple flows working to automate dimmer settings, home occupancy, door locking etc. This one extracting/parsing data from a specific string is beyond me as of yet.

Sorry if I seem to be griping, I’m a little frustrated with my inability to kick this one in teeth as if yet.

How? I took an attribute that I wanted from an event that happened (a state change) and put it into a message to my mobile device. How is this useless? I literally did exactly what you said you wanted to do.

OK. I don’t understand the quandary here. You have the data and you can pull just what you want from it. So what’s the problem?

So is the attribute literally “user 1”? That’s all the attribute has in it? If so, you don’t have to do anything but feed that attribute where you want it to go.