HowTo: Node Red / FritzBox – presence detection with the FritzBox

An important event that your SmartHome should be able to react to is the occupant's presence status. For example, you can switch off lights when they are absent or switch on radiators when they are present.
If you happen to still have a FritzBox, this presence detection is particularly easy.

All you need is a FritzBox, NodeRed and the MAC address(es) of the resident smartphones.

How to implement presence detection with the FritzBox in NodeRed is described in the following article.


Safety instructions

I know the following notes are always kind of annoying and seem unnecessary. Unfortunately, many people who knew "better" have lost eyes, fingers or other things due to carelessness or injured themselves. Data loss is almost negligible in comparison, but even these can be really annoying. Therefore, please take five minutes to read the safety instructions. Because even the coolest project is not worth injury or other trouble.
https://www.nerdiy.de/sicherheitshinweise/

Affiliate links/advertising links

The links to online shops listed here are so-called affiliate links. If you click on such an affiliate link and make a purchase via this link, Nerdiy.de will receive a commission from the relevant online shop or provider. The price does not change for you. If you make your purchases via these links, you support Nerdiy.de in being able to offer other useful projects in the future. 🙂 


Requirements

Helpful articles:
To be able to use this configuration, NodeRed should of course already be installed.
How to prepare a RaspberryPi and then install NodeRed on it is described in the following articles.

The following articles describe what has to be done to prepare the RaspberryPi so far:
RaspberryPi – setup for nerdiys!
RaspberryPi – The first configuration!
RaspberryPi – Control the RaspberryPi via SSH

NodeRed – Installing NodeRed on the RaspberryPi
NodeRed – Install new nodes

Tools required
-no-

Required material:

In the following list you will find all the parts you need to implement this article.


Log into the NodeRed configuration interface

Before you can edit your NodeRed configuration, you must - if activated - first log into the NodeRed configuration interface.

View of the login dialog. Here you have to enter the login data that you specified during the configuration of the login. You can find information about this in the article NodeRed - set up user login.

Install FritzBox node

In order for NodeRed to communicate with your FritzBox, you need to install the node "node-red-contrib-fritz". How to install nodes is described in the article NodeRed – Install new nodes described.


Enter FritzBox node configuration

So that the FritzBox node you have just installed can also communicate with your FritzBox, you must enter your FritzBox login data in the node configuration.

To do this, click on the "Fritz!Box Callmonitor" node. A new window will open in which you can select "Add new fritzbox-config" from the drop-down list in the "Device" line. Select this and then click on the pencil icon to the right of it.
In the window that now opens, you must enter the login data for your FritzBox. First enter the name so that the configuration does not remain nameless and then the user name and password. If the FritzBox is in your private network, you can leave the details for Host as they are. Only if you are accessing a remote FritzBox do you have to enter the URL to the FritzBox here. Then you should also make sure that this connection is encrypted via HTTPS. in this case you must also check the box "Is SSL connection". once you have entered everything, confirm this by clicking on "Add".
This will take you back to the previous window. The New FritzBox configuration is now already selected. You only need to confirm the window by clicking on "Done".

Node code for presence detection

Presence detection via the FritzBox basically works by checking which smartphones are logged into the FritzBox's Wi-Fi or network.

First you have to insert the node code listed below into your NodeRed configuration.
Then you need the MAC addresses of the smartphones whose presence you want to detect. You must then enter this in the configuration of the Fritz!

Node structure in the NodeRed configuration

Node code:

[
    {
        "id": "cf98613.60e11a",
        "type": "comment",
        "z": "7289f257a02aeac1",
        "name": "PresenceHandy1",
        "info": "",
        "x": 210,
        "y": 720,
        "wires": []
    },
    {
        "id": "eedc08fb.12b8f8",
        "type": "inject",
        "z": "7289f257a02aeac1",
        "name": "PresenceHandy1",
        }, "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "60",
        "crontab": "",
        "once": true,
        "onceDelay": "1",
        "topic": "",
        "payload": "{'NewMACAddress': 'XX: XX: XX: XX: XX: XX: XX'}",
        "payloadType": "jsonata",
        "x": 260,
        "y": 780,
        "wires": [
            [
                "38b70c39.68f504"
            ]
        ]
    },
    {
        "id": "c546f3f1.387d1",
        "type": "debug",
        "z": "7289f257a02aeac1",
        "name": "PresenceHandy1",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload.NewActive",
        "x": 680,
        "y": 760,
        "wires": []
    },
    {
        "id": "1c07ae94.c6b621",
        "type": "trigger",
        "z": "7289f257a02aeac1",
        "name": "",
        "op1": "PresenceMobile1 is logged into the network",
        "op2": "0",
        "op1type": "str",
        "op2type": "str",
        "duration": "0",
        "extend": false,
        "units": "ms",
        "reset": "0",
        "bytopic": "all",
        "outputs": 1,
        "x": 950,
        "y": 780,
        "wires": [
            [
                "38b38282.c0058e"
            ]
        ]
    },
    {
        "id": "3c25ea32.a803d6",
        "type": "change",
        "z": "7289f257a02aeac1",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "payload.NewActive",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 700,
        "y": 840,
        "wires": [
            [
                "1c07ae94.c6b621",
                "379d6bd2.312594"
            ]
        ]
    },
    {
        "id": "379d6bd2.312594",
        "type": "trigger",
        "z": "7289f257a02aeac1",
        "name": "",
        "op1": "PresenceMobile1 is no longer logged into the network",
        "op2": "0",
        "op1type": "str",
        "op2type": "str",
        "duration": "0",
        "extend": false,
        "units": "ms",
        "reset": "1",
        "bytopic": "all",
        "outputs": 1,
        "x": 950,
        "y": 860,
        "wires": [
            [
                "59fcf739.918c68"
            ]
        ]
    },
    {
        "id": "38b38282.c0058e",
        "type": "pushbullet",
        "z": "7289f257a02aeac1",
        "config": "274f4530.883c1a",
        "pushtype": "note",
        "title": "Presence",
        "chan": "",
        "name": "",
        "x": 1170,
        "y": 780,
        "wires": []
    },
    {
        "id": "59fcf739.918c68",
        "type": "pushbullet",
        "z": "7289f257a02aeac1",
        "config": "274f4530.883c1a",
        "pushtype": "note",
        "title": "Presence",
        "chan": "",
        "name": "",
        "x": 1170,
        "y": 860,
        "wires": []
    },
    {
        "id": "38b70c39.68f504",
        "type": "fritzbox-in",
        "z": "7289f257a02aeac1",
        "device": "eef817a2.74b848",
        "name": "",
        "service": "urn:dslforum-org:service:Hosts:1",
        "action": "GetSpecificHostEntry",
        "arguments": "{'NewMACAddress':'value'}",
        "x": 460,
        "y": 780,
        "wires": [
            [
                "c546f3f1.387d1",
                "3c25ea32.a803d6"
            ]
        ]
    }
]

It is important that you update the MAC address entered in the FritzBox node after importing the NodeCode. This should of course correspond to the device whose presence you want to monitor. How you can find out the MAC address(es) of devices in your network is described in the article Display/find out the IP address of the devices in the network mentioned.

View of the FritzBox node in which you should specify the MAC address of the device to be monitored.

Set a fixed MAC address for the smartphone

Some smartphone manufacturers have now started to randomly change the MAC addresses of their devices. This is a security feature so that your smartphone cannot be tracked in potentially unfamiliar WLANs.

In our case, however, it is a hindrance as we identify the smartphones by the fixed MAC address. You should therefore deactivate this function for your Wi-Fi.

Disable random MAC address on Android 11:

Switches to:

  • Settings
  • Connections
  • WLAN
  • Click on the cogwheel next to your (connected) WLAN
  • Extended
  • MAC address type -> Set to "Phone MAC"

Deactivate random MAC address under iOS:

On iOS, this function is somewhat cryptically hidden under the term "Private WLAN address". You can find it under:

  • Settings
  • WLAN
  • Network (the one you are currently connected to)
  • Private WLAN address -> deactivate

Have fun with the project

I hope everything worked as described for you. If not or you have questions or suggestions please let me know in the comments. I will then add this to the article if necessary.
Ideas for new projects are always welcome. 🙂

PS Many of these projects - especially the hardware projects - cost a lot of time and money. Of course I do this because I enjoy it, but if you think it's cool that I share the information with you, I would be happy about a small donation to the coffee fund. 🙂

Buy Me a Coffee at ko-fi.com       

8 comments

  1. Hello all,

    I used your instructions as described above.
    Unfortunately, the following appears in the "debug" bar:

    "No credentials set for pushbullet config."

    where can I set credentials for pushbullet configuration?
    And what do I have to set there exactly?
    Hope you can help me 🙂
    Sincerely
    Jurgen

  2. Hello I hope that this area is still under observation. When I want to import the Node code, Node RED writes me a syntax error in various places

    1. Hi Stefan,
      You're right, thanks for the tip. I have now uploaded the code again. It should work now 🙂
      Best regards
      Fabian

      1. The inject type is incorrect. It must be set to "JSONata" for the MAC address, not "JSON". Then the fun will work as it should 🙂

        But thanks for the tip with Pushbullet, that's exactly what I was looking for.

        1. Hi,
          oh then something must have changed in the implementation. I had used the code like this before. But I have adapted it now.
          Thank you for the tip. 🙂
          Best regards
          Fabian

  3. Hi Fabian, I have a question; everything is working fine, however I am not receiving a push message when the iPhone is back on the network. I see that there is a square box under the other node "Trigger and Block". My second question is that I have another Fritzbox (same SSID, no DHCP etc) on my network to strengthen my network. When my iPhone goes there, I also get a notification from the network

    1. Hi Bert,
      Did you pay attention to the point about the Mac address on the iPhone? To prevent unauthorized tracking, the iPhone simulates different Mac addresses by default when it logs into a WLAN. You should deactivate this for your WLAN. I think I described this in the article. (Unfortunately I can't look it up at the moment). Have you already considered this point? 🙂
      Best regards
      Fabian

Kommentar hinterlassen

Your email address will not be published. Erforderliche Felder sind mit * markiert

This site uses Akismet to reduce spam. Learn how your comment data is processed.