Help getting this automation to work please

Hi all,

I’m trying query the state of two trackers (my wife’s mobile phone, and mine) and ONLY display notifications for specific devices when both are not_home. Here is what I currently do have. Unfortunately, I made a mistake somewhere as HA tells me "incorrect type. Expected “object”

automation:
  - alias: "Change Home Status to Away based on GPS"
    trigger:
      platform: state
      entity_id: device_tracker.cel_stelar_2, device_tracker.alf
    condition:
      condition: and
      conditions:
        - condition: state
          entity_id: device_tracker.cel_stelar_2
          state: "not_home"
        - condition: state
          entity_id: device_tracker.alf
          state: "not_home"
    action:
      - service: state.set
        entity_id: zone.home
        data:
          state: 0
          attributes:
            friendly_name: "Away"
      - service: binary_sensor.turn_on
        entity_id: binary_sensor.0x00124b00251c19b6_contact
      - service: binary_sensor.turn_on
        entity_id: binary_sensor.0x00124b0028944398_contact
  - alias: "Change Home Status to Home based on GPS"
    trigger:
      platform: state
      entity_id: device_tracker.cel_stelar_2, device_tracker.alf
    condition:
      condition: or
      conditions:
        - condition: state
          entity_id: device_tracker.cel_stelar_2
          state: "home"
        - condition: state
          entity_id: device_tracker.alf
          state: "home"
    action:
      - service: state.set
        entity_id: zone.home
        data:
          state: 1
          attributes:
            friendly_name: "Home"
      - service: binary_sensor.turn_off
        entity_id: binary_sensor.0x00124b00251c19b6_contact
      - service: binary_sensor.turn_off
        entity_id: binary_sensor.0x00124b0028944398_contact

Anyone has an idea of what I’m doing wrong ? I really would like to only get notifications of my cameras and door sensors once we are both out of the house.

THANKS !

Why are you setting the zone.home state? That should work by itself if you have set up Person objects. Zone - Home Assistant

What are the binary_sensor entities, and why are you trying to set their values? Unless they are provided by an integration that adds the binary_sensor.turn_on etc services, you’re trying to call a non-existent service.

If you’re treating them as “flags”, use input_boolean entities instead, but I guess these are door sensors of some sort?

This 100% looks like ChatGPT leading yet another person down the wrong path.

1 Like

OP, please be honest, did you use ChatGPT or OpenAI?

This is not a real service.

This is not a real service.

Lastly, the entire automation does not make sense. It does not provide any notifications.

1 Like

Hey, yes I asked chatGPT to help me out here.

I then adapted the code. But thanks for letting me know it did crap :smiley:

So how can I adapt this to get it to work ?

So I learned that I should not be using chatGPT to help me write this YAML code as a start.

  1. Don’t use ChatGPT.
  2. What are you trying to do?
1 Like

So in short, my wife and myself are running the home assistant companion app (which seem to update the gps state more often that the icloud integration).

I have several door sensors (sonoff zigbee) connected though Z2M, as well as several EZVIZ cameras.

Main idea is to say that when entities :
device_tracker.cel_stelar_2 AND device_tracker.alf are away, THEN and only THEN start getting notifications for the door sensors and cameras.
It’s pretty silly to receive door sensor notifications each time we open the front door or the garden door and I’d like to only get a notification about this when we are actually out of home.

So in short, when these two people are out, enable notifications for this and that entities status changes :

^^

All you need to do is use a condition in your automations that notify you. A condition that either you or your wife are not home. You don’t need an automation. You add that condition to whatever is going to be notifying you.

    condition:
      condition: and
      conditions:
        - condition: state
          entity_id: device_tracker.cel_stelar_2
          state: "not_home"
        - condition: state
          entity_id: device_tracker.alf
          state: "not_home"

Just put that condition in the automation that will ultimately be notifying you.

Or simpler (conditions are AND by default; and you can list entities in a state condition (docs)):

condition:
  - condition: state
    entity_id:
      - device_tracker.cel_stelar_2
      - device_tracker.alf
    state: "not_home"

If you set up Persons aligned to your device trackers, zone.home will have a state representing the number of people at home (docs), so you could use the even simpler:

condition:
  - condition: state
    entity_id: zone.home
    state: "0"
1 Like

First of all thanks to both of you :slight_smile:

Yes, indeed I’ve noticed that zone.home goes up to 2 :

So when I alone at home calue will be 1, when we are both home, value will be 2.

Indeed, I want to use this value as a condition, and only get notifications if value is set to 0.

Now, what is a little more obscure is how I apply this to a specific set of entities ?

For perfect clarity here are the sensors I only want to get notifications from when zone/home value is set to 0 :

binary_sensor.0x00124b00251c19b6_contact
binary_sensor.0x00124b0028944398_contact
binary_sensor.porte_de_devant_motion
camera.abri_terrasse
camera.devanture
camera.porche
camera-terrasse

how can I make sure this condition only do apply to these specific devices ?

You have to create the automation that notifies you first. Have you created any automations that notify you? If the answer is no, then you need to understand that you aren’t going to get any notifications until you do that. So it’s a moot point until you create an automation.

  1. Create group with all motion sensors that you want to monitor. You can also write all that sensors in automation but this is more readable.
  2. Create trigger that checks when state of that group changes to on.
  3. Add conditions like there’s noone at home
  4. Send notification
1 Like