The way I’ve done this is with an input select, and it’s automated based on what is going on at the house.
For example, before I (or last person at home) leave home, a “Leaving Home” script is activated via Alexa or my tablet which changes the state from “Home” to “Away”, turns on my security camera via a WeMo switch, turns off any lights that are on, including TV etc.
When I arrive home, another automation (via the iOS app) changes the state from “Away” to “Home” and switches the security camera switch off. If someone else arrives before me, this is detected via NMAP and performs the same changes.
Since I live on my own, but occasionally have my partner or brother stay with me, I’ve also implemented a guest switch, so once on, certain automations are performed as if that was me.
Some examples:
Occupancy Input Select:
occupancy:
name: Occupancy
options:
- Home
- Away
initial: Home
Leaving Home Script:
leaving:
alias: 'Leaving Home'
sequence:
- service: homeassistant.turn_on
entity_id:
- switch.camera
- script.tvoff
- script.bedroomlights_off
- automation.guest_notification
- service: light.turn_off
data:
entity_id: light.study
transition: '3'
- service: input_select.select_option
data:
entity_id: input_select.occupancy
option: "Away"
Guest Input Boolean:
guest_mode:
name: 'Guest Mode'
initial: off
icon: mdi:account-plus
Automation for Input Boolean:
- alias: Guest Mode ON
initial_state: 'on'
hide_entity: true
trigger:
platform: state
entity_id: input_boolean.guest_mode
to: 'on'
action:
service: homeassistant.turn_on
entity_id: group.guestcontrols
- alias: Guest Mode OFF
initial_state: 'on'
hide_entity: true
trigger:
platform: state
entity_id: input_boolean.guest_mode
to: 'off'
action:
service: homeassistant.turn_off
entity_id: group.guestcontrols
Automation to return HA to “Home” based on me only:
- alias: Webcam Off
initial_state: 'on'
trigger:
platform: state
entity_id: device_tracker.iphone
to: 'home'
condition:
condition: state
entity_id: switch.camera
state: 'on'
action:
- service: homeassistant.turn_off
entity_id:
- switch.camera
- automation.guest_notification
- service: input_select.select_option
data:
entity_id: input_select.occupancy
option: "Home"
Automation to return HA to “Home” based on Guest’s status:
- alias: Webcam Off Guest
initial_state: 'off'
trigger:
platform: state
entity_id: group.guests
from: 'not_home'
to: 'home'
condition:
condition: and
conditions:
- condition: state
entity_id: input_boolean.guest_mode
state: 'on'
- condition: state
entity_id: switch.camera
state: 'on'
action:
- service: homeassistant.turn_off
entity_id: switch.camera
- service: input_select.select_option
data:
entity_id: input_select.occupancy
option: "Home"
Like I said, guests are tracked via their MAC address using NMAP and part of a group.
Hope this gives you something to work with!