Determine who or what triggered a state change in Node Red

Hi All,

I just got a Home Assistant Voice PE and am starting to use it to test replacing some of my voice automations that are usually executed by Echo’s. In my flow, I check to see which Echo was last called, then use that to make announcements to the Echo as the Node Red flow progresses. That all works fine.

I’m trying to figure out how I determine what Home Assistant Voice device (I have the PE and an S3-Box) changed the state of an object, so I can use that then to play announcements back to the device.

For now I’m testing with an outlet. When I use the HA Voice devices to turn the outlet on or off, I can see the information of which one changed the state in the device history, but can’t see it in Node Red.

Googling it and searching here mentions Global Variables and Context, but I have no idea how to configure any of that. Any input would be greatly appreciated.

Thanks!

The trigger will have the entity id of the assist_satellite.xyz_sat entity.

I’m not sure I understand. I’m using the events: state node and all I get is the state of the outlet, i.e. on or off. I tried using the trigger: state node but still get the same thing.

Set the debug node to complete msg obj. There is a lot more information that is sent when the node is triggered.

image

1 Like

Awesome! Thank you very much. I’ve never used that option on the debug node. One last question, is there an easy way to look up the entity ID’s? I can use the debug nodes to figure it out but was curious if that is something you can do easily.

The right side main HA menu you should have an icon for dev tools. Clicking that icon and then choosing the ‘states’ tab will bring up all entities state and attributes.

1 Like

Thank you very much, I appreciate the help and getting me going in the right direction!! Have a great night.

1 Like

Take a look at the NR cookbook, it has a lot of examples of how to use the HA web socket nodes.

1 Like

Maybe I’m doing something wrong, but it seems the ID of the trigger changes each time I run it. Also, if I look up the Dev Tools it shows a friendly name but no ID like some of the other entities.

The name of the entity is the entity_id. The entity id for the below would be counter.frontend_cams

Here is my test flow.

image

and here is the output from the debug node.

1/20/2025, 8:18:37 AMnode: Off
switch.tradfri_outlet_office : msg : Object
object
topic: "switch.tradfri_outlet_office"
payload: "off"
data: object
event_type: "state_changed"
entity_id: "switch.tradfri_outlet_office"
event: object
entity_id: "switch.tradfri_outlet_office"
old_state: object
entity_id: "switch.tradfri_outlet_office"
state: "on"
attributes: object
device_class: "outlet"
friendly_name: "Outlet - Office"
last_changed: "2025-01-20T13:15:56.810609+00:00"
last_reported: "2025-01-20T13:15:56.810609+00:00"
last_updated: "2025-01-20T13:15:56.810609+00:00"
context: object
id: "01JJ1XNVN7J8WJCNVJ4P1QMFHY"
parent_id: null
user_id: null
new_state: object
entity_id: "switch.tradfri_outlet_office"
state: "off"
attributes: object
device_class: "outlet"
friendly_name: "Outlet - Office"
last_changed: "2025-01-20T13:18:39.096014+00:00"
last_reported: "2025-01-20T13:18:39.096014+00:00"
last_updated: "2025-01-20T13:18:39.096014+00:00"
context: object
id: "01JJ1XTTTRN0HSWDMN9KBGS5PR"
parent_id: null
user_id: null
timeSinceChangedMs: 14
origin: "LOCAL"
time_fired: "2025-01-20T13:18:39.096014+00:00"
context: object
id: "01JJ1XTTTRN0HSWDMN9KBGS5PR"
parent_id: null
user_id: null
failedComparators: array[1]
0: object
_msgid: "1088921242a2cb85"

I never see the entity ID of the Voice PE I’m using to turn the Outlet on or off, but here it is in my Dev Tools.

I thought the ID I am getting from the debug node would point to the Voice PE, but the number changes each time turn the outlet on or off with the Voice PE.

I doesn’t work that way, you would need to monitor the assist_satellite entities

What you describe above is already built in to assist. If I tell my VA turn on a light, it responds “I have turned on the light”. Let’s say I want to send an additional message to the same VA after it turned on the light. I would use a trigger state node to monitor the VAs.

image

That will trigger after a VA finishes it’s task. Otherwise for dynamic responses see the following.

https://zachowj.github.io/node-red-contrib-home-assistant-websocket/node/sentence.html#examples

The Sentence node was exactly what I’m looking for! Thanks for helping point me in the right direction! I appreciate it.

1 Like