How to set the state of a person entity in Node-Red

I have a person entity representing a household member with access to an iOS device with the HA Companion app installed… so, it’s got a valid device tracker.

For this entity, though, the device is only occasionally going to represent the person’s actual location. I have a flow that will enable and disable the device tracker dynamically. When the device is not_home, I can assume it’s with the person. When it is home, I don’t want to make that assumption and don’t want the home zone to reflect the presence of that person.

When that device tracker gets disabled, I want to set the state of the person entity to “unknown,” as it sits today. That way it won’t affect the home.zone count or anything else.

SO… how can I set the state of a person entity to unknown? I can easily set the payload to unknown (or whatever string), but there is no person.set_location command. How can I set an entity state with Node-RED?

Thanks.

You can’t. Mostly.

Home Assistant is a state engine, and models the real-world through entities. Each entity is created and then maintained by an integration, and the rule is that only that integration can change the entity state. If you, or anything else, changes an entity state then the HA state no longer represents the real world.

There are a couple of exceptions. All of the input_whatever platform entities are created by Home Assistant and provided as human-input, so we can place them on the dashboard and directly input values.

Some integrations also provide Actions, through which some of the integration owned entities may have the state set / updated. This very much depends on the integration. All of the input_whatever have equivalent actions for setting and updating the entity state values.

As far as Person integration goes, the documentation says:

The Person integration allows connecting [device tracker] entities to one or more person entities. The state updates of a connected device tracker will set the state of the person.

So, the person-state is updated when connected device tracker states change.

As it happens, there is an Action for device_trackers [device_tracker.see], which allows you to manually change the state of a legacy device_tracker. Legacy device_trackers are held in the file known_devices.yaml.

It is possible to use this Action to create a new device_tracker, which has a state that is only updated by this Action. It is then possible to attach this device_tracker to the person of interest. If that is the only device_tracker for that person, then the person state will be updated directly in line with the device_tracker state provided by the device_tracker.see. If you have other device_trackers associated with the person as well, then the state will be also updated by changes in those device_trackers, in accordance with the rules for having several device_trackers connected to a person.

I guess it would be possible to have one or more real device_trackers as well as a false device_tracker, and to be able to disable the real trackers and then update the false tracker, which would then update the person location accordingly.

There is a helpful post Using device_tracker.see service to troubleshoot zone automations

which explains how to use device_tracker.see, and in a quick test it certainly seems to work. It is not possible to use device_tracker.see directly to update the state of a real device_tracker, only the dummy (legacy) device_tracker created first by using device_tracker.see with a new tracker id.

Good luck!

1 Like

That’s a good workaround, easily incorporated into my existing flow. I’ll just make the real and spoofed device_tracker entities dynamic and set accordingly. Thanks!