Home assistant & node-red presence detection (multiple people)

Presence detection for home assistant always feels like the holy grail. With your presence you can trigger actions and set variables. I am not spinning around this one so let’s get started

Prerequisites

In order to get this to work the fastest and easiest way we need to have the following in place.

  • Home assistant up and running
  • node-red up and running
  • The people you want to track need Homeassistant companion app installed

Home assistant side

Navigate to your Homeassistant setup > configuration > people. Click the plus icon to get the following screen.

New person in Home assistant
New user in home assistant

Give the new person the same name as your user to keep things simple.

Next, we need to navigate to configuration > helpers and add 4 input_booleans

  • user1_home
  • user2_home
  • anyone_home
  • guests

Obviously you can choose your own naming for me it’s dennis_home and so forth.

input boolean in home assistant

Next restart Homeassistant and go to Node-red

Node-red side

To keep things super simple I have made an export for you which you can import in your setup. Please note: You need to change my values to yours with the booleans you made!

[
    {
        "id": "6b46b849.592a48",
        "type": "api-call-service",
        "z": "a5e1f88b.118eb8",
        "name": "",
        "server": "d886c793.f0a088",
        "version": 1,
        "debugenabled": false,
        "service_domain": "input_boolean",
        "service": "turn_on",
        "entityId": "input_boolean.tineke_thuis",
        "data": "",
        "dataType": "json",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 340,
        "y": 20,
        "wires": [
            []
        ]
    },
    {
        "id": "7ac0df01.b2b0a",
        "type": "server-state-changed",
        "z": "a5e1f88b.118eb8",
        "name": "Tineke",
        "server": "d886c793.f0a088",
        "version": 1,
        "exposeToHomeAssistant": false,
        "haConfig": [
            {
                "property": "name",
                "value": ""
            },
            {
                "property": "icon",
                "value": ""
            }
        ],
        "entityidfilter": "person.tineke",
        "entityidfiltertype": "exact",
        "outputinitially": true,
        "state_type": "str",
        "haltifstate": "home",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "outputs": 2,
        "output_only_on_state_change": true,
        "x": 110,
        "y": 100,
        "wires": [
            [
                "6b46b849.592a48"
            ],
            [
                "16114d4f.9f9cc3"
            ]
        ]
    },
    {
        "id": "4e43134b.d7f35c",
        "type": "server-state-changed",
        "z": "a5e1f88b.118eb8",
        "name": "Dennis",
        "server": "d886c793.f0a088",
        "version": 1,
        "exposeToHomeAssistant": false,
        "haConfig": [
            {
                "property": "name",
                "value": ""
            },
            {
                "property": "icon",
                "value": ""
            }
        ],
        "entityidfilter": "person.dennis",
        "entityidfiltertype": "exact",
        "outputinitially": true,
        "state_type": "str",
        "haltifstate": "home",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "outputs": 2,
        "output_only_on_state_change": true,
        "x": 110,
        "y": 160,
        "wires": [
            [
                "52da1ea8.5e542"
            ],
            [
                "8f282fb8.45cf8"
            ]
        ]
    },
    {
        "id": "16114d4f.9f9cc3",
        "type": "api-call-service",
        "z": "a5e1f88b.118eb8",
        "name": "",
        "server": "d886c793.f0a088",
        "version": 1,
        "debugenabled": false,
        "service_domain": "input_boolean",
        "service": "turn_off",
        "entityId": "input_boolean.tineke_thuis",
        "data": "",
        "dataType": "json",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 340,
        "y": 80,
        "wires": [
            []
        ]
    },
    {
        "id": "52da1ea8.5e542",
        "type": "api-call-service",
        "z": "a5e1f88b.118eb8",
        "name": "",
        "server": "d886c793.f0a088",
        "version": 1,
        "debugenabled": false,
        "service_domain": "input_boolean",
        "service": "turn_on",
        "entityId": "input_boolean.dennis_thuis",
        "data": "",
        "dataType": "json",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 360,
        "y": 140,
        "wires": [
            []
        ]
    },
    {
        "id": "8f282fb8.45cf8",
        "type": "api-call-service",
        "z": "a5e1f88b.118eb8",
        "name": "",
        "server": "d886c793.f0a088",
        "version": 1,
        "debugenabled": false,
        "service_domain": "input_boolean",
        "service": "turn_off",
        "entityId": "input_boolean.dennis_thuis",
        "data": "",
        "dataType": "json",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 360,
        "y": 200,
        "wires": [
            []
        ]
    },
    {
        "id": "8ea80f7b.91ad3",
        "type": "server-state-changed",
        "z": "a5e1f88b.118eb8",
        "name": "Dennis Home",
        "server": "d886c793.f0a088",
        "version": 1,
        "exposeToHomeAssistant": false,
        "haConfig": [
            {
                "property": "name",
                "value": ""
            },
            {
                "property": "icon",
                "value": ""
            }
        ],
        "entityidfilter": "input_boolean.dennis_thuis",
        "entityidfiltertype": "substring",
        "outputinitially": true,
        "state_type": "str",
        "haltifstate": "on",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "outputs": 2,
        "output_only_on_state_change": true,
        "x": 110,
        "y": 300,
        "wires": [
            [],
            [
                "76ff614c.e3aa3"
            ]
        ]
    },
    {
        "id": "5e7a5281.9bb07c",
        "type": "server-state-changed",
        "z": "a5e1f88b.118eb8",
        "name": "Tineke Home",
        "server": "d886c793.f0a088",
        "version": 1,
        "exposeToHomeAssistant": false,
        "haConfig": [
            {
                "property": "name",
                "value": ""
            },
            {
                "property": "icon",
                "value": ""
            }
        ],
        "entityidfilter": "input_boolean.tineke_thuis",
        "entityidfiltertype": "substring",
        "outputinitially": true,
        "state_type": "str",
        "haltifstate": "on",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "outputs": 2,
        "output_only_on_state_change": true,
        "x": 110,
        "y": 360,
        "wires": [
            [],
            [
                "576fef00.7e22e"
            ]
        ]
    },
    {
        "id": "76ff614c.e3aa3",
        "type": "api-current-state",
        "z": "a5e1f88b.118eb8",
        "name": "Tineke Home",
        "server": "d886c793.f0a088",
        "version": 1,
        "outputs": 2,
        "halt_if": "on",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "override_topic": false,
        "entity_id": "input_boolean.tineke_thuis",
        "state_type": "str",
        "state_location": "payload",
        "override_payload": "msg",
        "entity_location": "data",
        "override_data": "msg",
        "blockInputOverrides": false,
        "x": 330,
        "y": 300,
        "wires": [
            [],
            [
                "806802c8.fe5f1"
            ]
        ]
    },
    {
        "id": "576fef00.7e22e",
        "type": "api-current-state",
        "z": "a5e1f88b.118eb8",
        "name": "Dennis Home",
        "server": "d886c793.f0a088",
        "version": "1",
        "outputs": 2,
        "halt_if": "on",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "override_topic": false,
        "entity_id": "input_boolean.dennis_thuis",
        "state_type": "str",
        "state_location": "payload",
        "override_payload": "msg",
        "entity_location": "data",
        "override_data": "msg",
        "blockInputOverrides": false,
        "x": 340,
        "y": 360,
        "wires": [
            [],
            [
                "806802c8.fe5f1"
            ]
        ]
    },
    {
        "id": "68a06492.f9578c",
        "type": "server-state-changed",
        "z": "a5e1f88b.118eb8",
        "name": "Dennis Home",
        "server": "d886c793.f0a088",
        "version": 1,
        "exposeToHomeAssistant": false,
        "haConfig": [
            {
                "property": "name",
                "value": ""
            },
            {
                "property": "icon",
                "value": ""
            }
        ],
        "entityidfilter": "input_boolean.dennis_thuis",
        "entityidfiltertype": "substring",
        "outputinitially": true,
        "state_type": "str",
        "haltifstate": "off",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "outputs": 2,
        "output_only_on_state_change": true,
        "x": 110,
        "y": 440,
        "wires": [
            [],
            [
                "c5c67c30.e01db"
            ]
        ]
    },
    {
        "id": "fc058f87.982e9",
        "type": "server-state-changed",
        "z": "a5e1f88b.118eb8",
        "name": "Tineke Home",
        "server": "d886c793.f0a088",
        "version": 1,
        "exposeToHomeAssistant": false,
        "haConfig": [
            {
                "property": "name",
                "value": ""
            },
            {
                "property": "icon",
                "value": ""
            }
        ],
        "entityidfilter": "input_boolean.tineke_thuis",
        "entityidfiltertype": "substring",
        "outputinitially": true,
        "state_type": "str",
        "haltifstate": "off",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "outputs": 2,
        "output_only_on_state_change": true,
        "for": "",
        "forType": "num",
        "forUnits": "minutes",
        "ignorePrevStateNull": false,
        "ignorePrevStateUnknown": false,
        "ignorePrevStateUnavailable": false,
        "ignoreCurrentStateUnknown": false,
        "ignoreCurrentStateUnavailable": false,
        "x": 110,
        "y": 520,
        "wires": [
            [],
            [
                "c5c67c30.e01db"
            ]
        ]
    },
    {
        "id": "21916f6b.480ab",
        "type": "api-call-service",
        "z": "a5e1f88b.118eb8",
        "name": "Away",
        "server": "d886c793.f0a088",
        "version": "1",
        "debugenabled": false,
        "service_domain": "input_boolean",
        "service": "turn_off",
        "entityId": "input_boolean.thuis",
        "data": "",
        "dataType": "json",
        "mergecontext": "",
        "output_location": "payload",
        "output_location_type": "msg",
        "mustacheAltTags": false,
        "x": 790,
        "y": 300,
        "wires": [
            []
        ]
    },
    {
        "id": "c5c67c30.e01db",
        "type": "api-call-service",
        "z": "a5e1f88b.118eb8",
        "name": "Home",
        "server": "d886c793.f0a088",
        "version": 1,
        "debugenabled": false,
        "service_domain": "input_boolean",
        "service": "turn_on",
        "entityId": "input_boolean.thuis",
        "data": "",
        "dataType": "json",
        "mergecontext": "",
        "output_location": "payload",
        "output_location_type": "msg",
        "mustacheAltTags": false,
        "x": 290,
        "y": 440,
        "wires": [
            []
        ]
    },
    {
        "id": "806802c8.fe5f1",
        "type": "api-current-state",
        "z": "a5e1f88b.118eb8",
        "name": "House Guests",
        "server": "d886c793.f0a088",
        "version": 1,
        "outputs": 2,
        "halt_if": "on",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "override_topic": false,
        "entity_id": "input_boolean.gasten",
        "state_type": "str",
        "state_location": "payload",
        "override_payload": "msg",
        "entity_location": "data",
        "override_data": "msg",
        "blockInputOverrides": false,
        "x": 540,
        "y": 300,
        "wires": [
            [],
            [
                "21916f6b.480ab"
            ]
        ]
    },
    {
        "id": "d886c793.f0a088",
        "type": "server",
        "z": "",
        "name": "Home Assistant",
        "addon": true
    }
]

Select and copy the above code.

Paste it into node-red by going to the hamburger menu and select import

Import node-red

In the next windows paste and click import

paste code node-red

It will look like the following:

Change to your values in node-red

After you changed to your configuration and you have pressed deploy presence detection will work as it should be.

Don’t forget to follow my other tutorial; for example node-red and philips hue in HA

If you have any further question, ask them in the comments.

Dennis

Related Post

Comments (4)

  1. Great article, thank you.

    Most of this makes sense to me – but I’m not clear on the “guests”. Is that something that’s supposed to be manually activated? How is that supposed to work?

    Jim
    June 2, 2021
    1. Hi There Jim, Sorry that it took me this long to respond.
      The guest part is something which you could activate, it will be useful for setting house guests.
      When you are away from your house and mother in law watches the kids, she is in a dark cold house when the guests thing isn’t there
      maybe a poor example, but it’s accurate haha.
      You can create the input boolean by simply going to the helpers menu within the settings menu in home-assistant.
      If you have further questions, I’m happy to assist you.

      June 9, 2021
  2. Thank you for this tutorial – I’m a few days in with Home Assistant & Node Red, and this got me on the right track for my presence detection automations. Appreciate your work!

    Josh
    October 16, 2021
    1. Thank you for your comment Josh! Please let me know which tutorials you would like to see in the future!

      October 16, 2021

Leave A Comment

Name

Website

Comment