ιΌ 
2020

Manual Presence Switch

A cornerstone of automation is the system knowing if you're close by (at home in this case). Home Assistant has a few methods of automated presence detection but they are highly reliant on detecting a mobile device. This wasn't working for me and I'm not keen on enabling options that help Google track me as well. The icon always showing me as "away" didn't bother me but one day I decided to try to change the status and found I couldn't. This led me to a lot of digging around until I found a solution for "manual" a presence I could toggle.

My solution was creating an MQTT switch I could toggle. The first step is deciding on a topic in your MQTT hierarchy. In configuration.yaml, set a device tracker

  device_tracker:
  - platform: mqtt
    devices:
       manual_toggle: "service/locator/{user}"
  

Next we create an MQTT switch that will set values

  - platform: mqtt
    name: 'Presence Toggle'
    icon: 'mdi:home-assistant'
    command_topic: 'service/locator/{user}'
    state_topic: 'service/locator/{user}'
    payload_on: 'home'
    payload_off: 'not_home'
    state_on: 'home'
    state_off: 'not_home'
    retain: true
  

First thing to note are the payload/state values. Initially I had these set as json but couldn't get the device tracker to cooperate unless using the values of "home" and "not_home". The other thing required is the "retain: true" setting. This means any connection reading this topic will always return the last value set on the topic, allowing the switch to stay on/off.

An option to track this device should be available in Home Assistant by going to configuration > People > {user}

This doesn't mean you always have to push a button to toggle this setting. You can set other automations to trigger this state. I have an NFC tags near my door on the inside and one on the door frame outside I can use to have my phone check in/out.

NPC Company