Function "Or" and "AND", not working with mobile devices

Hello all,
I’m pleased to use Home assistant and I want to support this project as much as I use it.
I have been using automations on Hass.io but I discovered that under “conditions”, the “and” or “or” do not work properly. I tried many different options in order to find what could I be doing wrong but I wasn’t.
I want to use to mobile phones to be the condition (home or away) to notify if a door is open. If I’m at home I do not want to know if the door is open, only when I’m not at home.
Is there anyone with the same issue as me? If yes, did you found a solution?

- id: 'GGGGGGG'
  alias: Notify garage door open
  description: 
  trigger:
  - type: opened
    platform: device
    device_id: UUUUUUU
    entity_id: binary_sensor.window_door_sensor
    domain: binary_sensor
  condition:
  - condition: or
    conditions:
    - condition: device
      device_id: XXXXXXX
      domain: device_tracker
      entity_id: device_tracker.user1
      type: is_not_home
  - condition: device
    device_id: YYYYYYY
    domain: device_tracker
    entity_id: device_tracker.User2
    type: is_not_home
  action:
  - service: notify.notify
    data:
      message: Garage door is open and you are not there! Check cameras and close
        the door.
  - service: camera.record
    data:
      service: camera.record
      data:
        entity_id: camera.mjpeg_camera
        filename: /media/my_stream.mp4
        duration: 30
    entity_id: camera.mjpeg_camera
  mode: single

Hi and welcome to the forums.

Could you please edit your post so that the pasted automation configuration is formatted correctly. See point 11 here: Help us help you. We should then be able to see what needs to be chaged.

Also just for your reference, it has not been called Hassio for over a year.

They do. You did wrong. Unfortunately, since you did not use the “code” formatting option (icon </>), it’s hard to see what you did wrong.

Please try again.

Sorry guys, it is the first time that I’m sharing my code :slight_smile: I will fix it

1 Like

I can see now that the name is Home Assistant again :slight_smile: I have changed the title of my post.

You also need to:

Sorry Tom and m0wlheld :slight_smile:
I have now used the formatting tool for my code.

Good.

Now I can see, that you created a single OR condition and an additional condition which is not part of the OR sequence and therefore “AND’ed” with the result of the OR condition.

OR in other words: You need to indent the second condition to the same level, as the child of the OR condition, like this.

  condition:
  - condition: or
    conditions:
    - condition: device
      device_id: XXXXXXX
      domain: device_tracker
      entity_id: device_tracker.user1
      type: is_not_home
    - condition: device
      device_id: YYYYYYY
      domain: device_tracker
      entity_id: device_tracker.User2
      type: is_not_home
1 Like

Yeah you made an AND not an OR… it’s a bastard getting your head around this but @m0wlheld has you covered…

I see… It make sense. I just don’t know why the indent is wrong because I made the automation directly on Home Assistant and not on the YAML.
Let me try to correct the YAML and not using the browser version.

It’s easy to do that in the GUI… the different levels are a struggle. Made the same mistake myself… (after you edit the yaml check the GUI… I often use the GUI and then check the yaml)

ohhh. thank you David.
let me try then both options on the YAML and also on the GUI.

You can just use one to see the results with the other… it’s easy to screw up… I do it regularly…

I was jumping from GUI and YAML to compare both and for now I just made changes on the GUI:

condition:
  - condition: or
    conditions:
      - condition: device
        device_id: 1
        domain: device_tracker
        entity_id: device_tracker.user1
        type: is_not_home
      - condition: device
        device_id: 2
        domain: device_tracker
        entity_id: device_tracker.user2
        type: is_not_home

by using the example from DavidFW1960, I realized that the GUI is puting two more spaces on the indent of the “or” and that is the reason why I couldn’t use the GUI for the “OR”. David, without your example I wouldn’t understand :slight_smile: . By building the automation on the GUI and then going into the YAML to correct the indent then I manage to make it to work!!! :slight_smile: :slight_smile: Thank you all for the help!!
This means that the GUI is putting more spaces on the indent and this was driving me crazy! Can this be fixed on the next update?

The issue is you added the second condition in the wrong place on the GUI… it’s not the software doing it it’s you and as I said it’s easily done. (It wasn’t my example BTW but thanks)

:slight_smile: A big thank you also to m0wlheld Christoph Dahlen. Only with your example I could see the right indent…
You are all the best!
I will keep trying to make more automations now that I know the right indent.