Automation based on who is home

I am trying to create an automation to trigger a night scene when both persons gone to bed. I do this based on the the phones are being charged using sensor provides Mobile App.

I also want to trigger the night scene if only one person is at home and going to bed, but I cant really figure out how to configure the trigger.

Thanks for input

Multiple triggers work like an or - condition. So you just have to add both phones:


trigger:
  - platform: state
    entity_id: sensor.first_phone_battery_state
    to: charging

  - platform: state
    entity_id: sensor.second_phone_battery_state
    to: charging

condition: 
  …
action:
  - scene: scene.YOURSCENE

That’s how I done it today, and it works fine when both are home. What I want to do is to trigger the action based on phones that are home.

If one of the phones are not home, I want to trigger the action based on the remaining phone at home.

Just replace the state in the example above:


trigger:
  - platform: state
    entity_id: sensor.first_phone_battery_state
    to: charging

  - platform: state
    entity_id: sensor.second_phone_battery_state
    to: charging

  - platform: state
    entity_id: sensor.first_phone_battery_state
    to: home

  - platform: state
    entity_id: sensor.second_phone_battery_state
    to: home

condition: 
  …
action:
  - scene: scene.YOURSCENE

I have not tried the suggested automation, but I understand that would trigger the action/scene when both phones are home and charging.
What I am trying to acheive is if one one person is home and going to bed (charging the phone) , the night-scene should be trigged. If we are both home, both phone must be in charging state in order for the action to happen.

As I said above, triggers are or - conditions. First trigger comes and serves.

I’d do it like this:

Create a group with the all: option set to true, this way the group will show home only if all persons in the group are home.

group:
  everyone:
    all: true
    name: Everyone Home
    entities:
      - person.husband
      - person.wife

And the automation part:

trigger:
  - platform: state
    entity_id: 
      - sensor.first_phone_battery_state
      - sensor.second_phone_battery_state
    to: charging
action:
  - choose:
      # Both persons home and both phones charging
      - conditions: 
          - "{{ states('group.everyone') == 'home' }}"
          - "{{ states('sensor.first_phone_battery_state') == 'charging' }}"
          - "{{ states('sensor.second_phone_battery_state') == 'charging' }}"
        sequence:
          - service: scene.turn_on
            target:
              entity_id: scene.night_scene
      # Only one person home
      - conditions:
          - "{{ states('group.everyone') == 'not_home' }}"
        sequence:
          - service: scene.turn_on
            target:
              entity_id: scene.night_scene

I’d probably also add some conditions to only do it between certain times to not trigger it when you charge the phone during the day.

Good point!

Great! Thanks for that, just what I wanted.