Automation state based on presence

This blueprint can turn off multiple automations when a person’s state is “not_home”, it will also turn these automations back on when the state is “home”.
You can also invert the entire thing

blueprint:
  name: Presence Automations
  description: >
     Disable automation(s) when someone arrives. Re-enable them when they leave.
  domain: automation
  input:
    person:
      name: Person
      description: Select the person to be home.
      selector:
        entity:
          domain: person
    automation: 
      name: Automation
      description: Select the automation(s) that need to be turned off.
      selector:
        target:
          entity:
            domain: automation
    inverted:
      name: Invert Blueprint
      description: 'This will cause the selected automations to enable when the person comes home, instead of disabling them as per default. 
      This will in turn disable the automation when the person leaves.'
      default: false
      selector:
        boolean: {}            
trigger:
  - platform: state
    entity_id: !input 'person'
condition: []
variables:
  inverted: !input 'inverted'
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: !input 'person'
            state: home
        sequence:
        - choose:
          - conditions: '{{ inverted }}'
            sequence:
              - service: automation.turn_on
                data: {}
                target: !input 'automation'
          default:
          - service: automation.turn_off
            data: {}
            target: !input 'automation'
      - conditions:
          - condition: state
            entity_id: !input 'person'
            state: not_home
        sequence:
        - choose:
          - conditions: '{{ inverted }}'
            sequence:
              - service: automation.turn_off
                data: {}
                target: !input 'automation'
          default:
          - service: automation.turn_on
            data: {}
            target: !input 'automation'
    default: []

I will be keeping this updated on https://gist.github.com/dbeltman/b90156effaaa0ea963642334934e541e and i’m open to feedback

The idea is what I’m looking for, but it’s not very useful unless you can select multiple people or groups of people. Most automations need to keep running when only I leave the house and others remain…

1 Like

could this be used to turn on lights when me or my partner gets home?

we want several lights to come on if either gets home and no one is home allready

if someone is home and the other is home it should do nothing
if we both leave it should turn off all lights

I’ve had this wish as well, but we’re currently limited by the entity selector not being usable in a trigger ( yet?). The Workaround for this has been covered in other blueprints, what they do is give you a fixed size list of people to populate, and then do lights/switches based on (collective) presence.

I dont like this fixed approach so i stuck with other methods and this single-person blueprint. Lets hope homeassistant can soon trigger on entity selector targets!

This blueprint only switches on/off specific automation entities. So for example if you had an automation that does " turn on light when motion detected in hallway", you could turn that automation logic on/off based on presence with this blueprint.

But a problem with blueprints and multiple people is that i cant easily give (dynamically sized) list to the blueprint to trigger with. So selecting multiple specific people is a no-no for now unless you want to put up with an ugly blueprint with a fixed size list which never works for everyone.

However for your usecase (turn on lights if EITHER gets home and turn off when BOTH away), i would suggest creating a Group (of person entities) to turn on/off your lights. This group will be in ON state if any of the people are at home, and will be in OFF state when both are away.
It should then be a matter of a simple automation, or perhaps a modified version of my blueprint. Let me know if you would like that and ill see if i can find the time.

yes, i read again and my mind finally read automation, but then i read that multiple people are not very well supported in HA to begin with (Ha must have been written by a single :slight_smile: )

So i think i will wait for that to be supported and then just use the app to turn on the lights when i’m about to get home. and turn them off when i leave

i tried to create an automation

- id: '****'
  alias: Tænd lys når hjemme
  description: ''
  trigger:
  - platform: state
    entity_id: person.tina_andersen
    from: not_home
    to: home
  - platform: state
    entity_id: person.bo_herrmannsen_5
    from: not_home
    to: home
  condition:
  - condition: sun
    after: sunset
    before: sunrise
  action:
  - type: turn_on
    device_id: ****
    entity_id: light.kitchen_1
    domain: light
    brightness_pct: 60
  - type: turn_on
    device_id: *****
    entity_id: light.kitchen_2
    domain: light
    brightness_pct: 60
  mode: single

hope that can do the trick

2 Likes