I have added my fritzbox router as a device_tracker
. This checks for devices on my local area network and marks them as home/not_home
. Using this I can create automations with known devices (i.e. my own devices).
Considering I know all personal devices in my network, I am now trying to figure out if any additional devices have locked in, that I do not own (i.e. are not part of a defined list), to find out, if any guests are in the house.
Does anybody have an idea how to check, if any devices not contained in a defined list are marked home
?
I think you can work out this with NMAP device tracker. Please go through this. Just keep all the known devices in exclude list so that all new device in your network will be tracked.
do you want to trigger something with this new devices or do you want to show them only in lovelace?
Yes, I would like to set a boolean to true, whenever a device is connected to the WiFi that does not belong to the family. This can then be used in various automations.
I am currently using the Fritzbox router provided device tracker generally they have a similar capability. The question to be answered would be the same. Also using the NMap device tracker excluding the all family devices I would need to find out the number of remaining tracked devices that are marked home. I would just spare the act to subtract the number of family devices from this amount.
For those interested, I have found a solution to my problem. It turns out, that device_tracker
is a domain in home assistant, for which the state can be retrieved. states.device_tracker
as such returns a string of all devices.
To identify whether or not guests are present (connected to my wifi), I created the following template:
{% set own_devices = ['Own-Device-1','Own-Device-2','Own-Device-n'] %}
{% set devices = states.device_tracker|selectattr('state', 'eq', 'home')
|rejectattr('name','in',own_devices)
|list %}
{{ devices|count > 0 }}
Hello,
I have been looking for this. Can you explain me where do i Create that template? im still very fresh here…
I have an automation, that triggers by the above mention template and sets a boolean to true indicating the presence of guests, which I then use in other automations as a condition.
- alias: Guest - Enable Guest Mode
id: 'guest_enable_guest_mode'
trigger:
#Guest Device detected in Wifi
- platform: template
value_template: >-
{% set own_devices = ['Own-Device-1','Own-Device-2','Own-Device-n']%}
{% set devices = states.device_tracker|selectattr('state', 'eq', 'home')
|rejectattr('name','in',own_devices)
|list %}
{{ devices|count > 0 }}
condition:
- condition: state
entity_id: input_boolean.guest_mode
state: 'off'
action:
- service: input_boolean.turn_on
entity_id: input_boolean.guest_mode
do I need to put the whole entity_id there? (device_tracker.device_1) or only the last part (device_1)
In my example I am checking the friendlyname.