Use any switch as "person" presence

Hi,

I have a HomeKit setup in which HomeKit switches on a switch when a user arrives home and turns off the switch when the user leaves the house. Working great. Now i would like to use the “switch” (which is just a virtual switch) as the presence for a user, but i can only use the device_tracker entities there. Is there any workaround to make this work?

Dennis

1 Like

like your idea bro

could be a feature Request

letting us add the a ‘on’ status to a person(s) thing

1 Like

There’s a workaround for this that I’m using myself to use anything as a device tracker.
Create an MQTT device tracker. Then create an automation that triggers on any change of the virtual switch and sends the payload “home” or “not home” to the topic defined in the MQTT device tracker.
Let me know if you need more information.

1 Like

Not sure if i’m 100% clear on what you want to achieve, but i’m using templated binary sensors to result in an on/off switch (home_occupied) for presence:

- platform: template
  sensors:
    home_occupied:
      friendly_name: Home Occupied
      device_class: presence
      value_template: >-
        {{ is_state('person.gareth', 'home')
           or is_state('person.kristina', 'home')
           or is_state('input_boolean.home_guest_mode', 'on') }}
      delay_off: 00:01:30

He wants to have a device tracker that shows the presence of a person based on a switch. He wants this because you can only bind device trackers to a person, not switches or other types of entities.

1 Like

Maybe I’m stupid but I’m with @gareth78 here.
You say a virtual switch, is that an input_boolean ?
You say homekit switches it ? Based on what ?
Is this per individual, or as a group ?
Why not just use a standard device tracker integration like life360 (other brands available) ?
When I first read this I imagined a bank of switches just inside the door labelled ‘mum’, ‘dad’, ‘jonny’, ‘alice’ and ‘fido’ making people clock in and out as they pass by.

It’s ofcourse per individual. That is how “Persons” work in HA now. You can only select device_tracker entities as presence for the user. But why not normal “switches” (not booleans)?

As of why not Life360, because that adds more components to the setup. We already have Apple everywhere so the HomeKit support is very nicely integrated.

Use my method, I’ve been doing this since the introduction of the person integration.

4 Likes

Yeah that might be the best solution indeed. Thanks so much for the suggestion!

To expand on this solution, you can also do this with a “virtual device-tracker”. No MQTT required for this solution if you don’t already use it.
Just add some fantasy-device in known_devices.yaml, and change it’s state based on the switch’s state with an automation.

This can be done with the device_tracker.see service and you’ll have a device_tracker device that can be loaded into the person integration.
I do it in node-red but it’d be very easy to create an automation for when your switch turns on and off



3 Likes

I wouldn’t bet on this one being supported in the future, as the known_devices.yaml is slowly getting deprecated, lots of device tracker integrations don’t support it anymore. I assume that at one point they’ll remove known_devices.yaml. But that’s just a guess, otherwise great alternative.

Yeah, I know ;.(
Hopefully by then it will be possible to associate some binary sensor to a person.

Thanks Burningstone for the suggestion.

Maybe it’s a new thing that wasn’t available a year ago, but you don’t even need an automation for this. You can set the service to call in the template switch directly:

switch:
  - platform: template
    switches:
      home:
        friendly_name: Home
        turn_on:
          service: mqtt.publish
          data:
            topic: location/martin
            payload: "home"
        turn_off:
          service: mqtt.publish
          data:
            topic: location/martin
            payload: "not home"

This already existed back then, however I was under the assumption that the switch wad given by his system and not something configured by himself.

1 Like

This method has an issue, when you reboot HA. The “device_tracker” integration doesn’t remember the status and always defaults back to not_home. so you will have to re-trigger the switches which is not practical. Not sure what options we have here, you can create an automation, but the issue is that it doesnt’ remember state through restarts

Thank you. It’s really that simple. Just fill in a name for the new device_tracker entity in an automation and it creates the entity, the first time the automation executes. Nice! I also added a trigger for the homeassistant startup, to check the condition of the source sensor. Otherwise it stays not_home after a restart of ha.

Exactly… so vote for this

Or use a HA startup trigger automation to set it to the proper state again.

… which is a workaround (startup automation) on top of a workaround (fake device tracker). Oh and we’ll need a workaround when known_devices is gone.

I really have to believe that the devs have the same problems and have a grand scheme in the works. In the meantime I’m going to try RFID tags to work around all my workarounds.