Track devices on specific wireless network using Unifi

Hey all,

I just recently added the Unifi controller component to my HASS configuration to help get better home/away tracking for all of our cell phones. I have been using someone else’s Life 360 custom component to track our GPS movement, which seems to be working work. I had been watching someone’s Youtube video about Node Red and doing home/away stuff, which I wanted to add to my own Node Red setup. In the video I was watching, they mentioned they were using Google wifi to track home/away, and they were also tracking whether or not they had a visitor/house guests. I am not sure how they were tracking visitor/guests on Google wifi, but I have a guest wifi network configured on my Unifi controller that I was wondering if it would be possible to track whenever someone connects to it? I added the monitored condition of essid onto my Unifi config in HASS, and I can see the ESSID in the attributes of the device tracker:

I also have an ESSID that ends in -guest, so I know anyone connected to that network is a guest at my house. I know I can create input booleans that track specific device trackers, as I’ve done that for myself, my wife, and my kids. But is it possible to create an input boolean that looks to see if there is anything connected to the ESSID attribute that has ‘lastname’-guest? I found this custom component today:

However I’m not sure if it will do what I want. I was hoping however that I could do it without adding anything else to has to make it work.

Thanks in advance!

I’m using this component as well and it gives me this info - in Lovelace only (in combination with the custom entity-attributes-card):
image

If I had somebody on my guest network the guest network SSID would show up in the bottom table.
Is this - kind of - what you’re looking for?

1 Like

@chairstacker so I just added that custom component to my HASS, and I can see my SSID’s now:

Now I just need to figure out what the YAML would be to turn a input boolean on/off.

If you use something like this you will see how many devices are on each SSID:

        - type: custom:entity-attributes-card
          title: Networks
          heading_name: SSID
          heading_state: Clients
          filter:
            include:
              - sensor.unifi_ap_details.SSID*

not sure, if a wildcard like sensor.unifi_ap_details.*guest would work

@chairstacker Thanks for the info, but I haven’t started using Lovelace UI yet. Does that work if the guest network doesn’t have anything connected to it? I don’t always have something connected to the guest network, so I had to play around with the YAML to get it to work. Since the guest network wouldn’t show in the attributes unless something was connected, I had to create another sensor (sensor.guests) that would show on or off if the guest network showed in the attributes of sensor.unifi. Then I created two automations that would flip the input boolean on or off based on the state of sensor.guests.

I’m not aware of anything similar in the legacy UI to what I showed you in Lovelace.
Going via a separate sensor is probably the best way for the you right now.

I would have probably done something similar, but I’m loving the Lovelace interface - it’s flexibility and the custom cards people have started building for it.

Hi,

I think you don’t want a input boolean but a binary template sensor. Something like this should do what you want:

binary_sensor:
  - platform: template
    sensors:
      wifi_guests:
          friendly_name: "Wifi Guest"
          value_template: >-
              {{  states.sensor.unifi.attributes.guest_ssid|int > 0 }}

The template should return true/false, so if there’s someone on the guest network it will appear as “on”. You may try the template in <your_ip>:8123/dev-template

@chairstacker Yeah, I think I’m going to start moving towards Lovelace UI. I haven’t had a chance because I’ve been busy and I’m more used to the legacy UI so I could get things working in there better. But I’ve got some time off coming up so I hopefully can get some more of my planned projects done. I appreciate the help!

@clyra Thanks for the code. Let me give that a try and I’ll see if it works out better than what I’ve done.

@clyra So I tried this out tonight, and it didn’t do as I expected. I did not have anything connected to the guest network, so I received this error:

Error rendering template: UndefinedError: 'mappingproxy object' has no attribute 'lastname-guest'

The template will only return true/false if there are active clients connected to the SSID, otherwise the SSID does not show in the unifi sensor. So I think my best bet was the template sensor I wrote:

- platform: template
  sensors:
    guests:
      value_template: >
        {% if (states.sensor.unifi.attributes["lastname-guest"]) %}
          on
        {% else %}
          off
        {% endif %} 

Then I wrote automations that flip the input boolean on/off based on if the template returns on/off. I think it’s probably overkill, but I want to be able to write flows in Node Red and I think they work better with input booleans than the sensors.

I thought that this might happen (the error when there’s no guests) but glad that you figure out a fix. I still think the input boolean is overkill as you said because it only follows the sensor. If the sensor is on you turn the boolean on, if it’s off you toggle it off, right? Anyway, if it works to you, cool!

1 Like