Phone detection automation question

Good Afternoon, I am playing with the automation in my home assistant, I want to have it that if both mine and my wife;s phones are out of the house the music stops. I have it working that if her phone is gone and mine leaves it shuts off the music. Just did this by using a trigger on my phone and a condition that her’s is gone. Is that the best way to do this? Also that means I then have to build a second one right for the opposite scenario? It seems triggers are essentially or statements and conditions are and statements. is that right?

thanks

You can create template sensor which counts how many people are currently in home and then setup trigger on state change from anything to 0. Such sensor can be usefull for many other automation soon (-:

1 Like

Thanks will look into how to build the template sensor. But if you got any insight would be greatly appreciated.

Home assistant pages have some documentation on it, you can also test live templates on running home assistant. I’ll check later in my another installation, where I’m using such template sensors.

In my sensors.yaml file i have following entry:

- platform: template
  sensors:
    in:
      value_template: '{{states.device_tracker|map(attribute="attributes")|sum("in")}}'
      friendly_name: in the building
      unit_of_measurement: human

But I have locally enchanced device_tracker with boolean in attribute, http://your-hass/dev-state shows for device_tracker.sokolowski:

{
  "source_type": "work_time",
  "id": "sokolowski",
  "in": true,
  "human": true
}

I suggest first playing with templates via http://your-hass/dev-template.

Usefull knowledge resources:

You could also put both phones into a group. The group will be home as long as at least 1 member/phone is home and only away when both phones are away.
Sounds like a good fit for your problem.

Thank you will look into both, having some issues with the whole detection now, had to reset my router and now my log says it cant find the devices. Changed all the ips in the yaml as well.

A group is the easiest option… I use it for lights, both phones/trackers are int he group.family

- alias: 'Switch on lights when we both go out'
  hide_entity: False
  trigger:
    platform: state
    entity_id: group.family
    from: 'home'
    to: 'not_home'
  condition:
    - condition: numeric_state
      entity_id: sensor.solar_angle
      below: 1.0
  action:
     - service: light.turn_on
       entity_id: light.living_room_colour,light.landing
       data:
         rgb_color: [255, 255, 255]
         brightness: 190

I have sample of exact presence sensor you need inside here: Follow Me Lights Automation Implementation

Thanks everyone group did exactly what I needed. The other suggestions were pretty cool as well so will habe to remember them as I start getting more into this.