Home Assistant Automation issue with "OR" condition

Hi Everyone,

I need your help about automations. I’m not expert with HA :slight_smile: I’ve two window sensor. If I’m not at home and one of the windows is open (i forgot the windows as open) I want to be notified. I can do this for a single window but what I want to do is get alerts no matter what window is open. I tried a lot of way but i could not. What’s wrong i dont know. My example automation is this;

alias: Example
description: ''
trigger:
  - platform: state
    entity_id: person.okan
    to: not_home
condition:
  - condition: and
    conditions:
      - condition: state
        entity_id: binary_sensor.salon_pencere_sensoru_pencere
        state: 'on'
      - condition: or
        conditions:
          - condition: state
            state: 'on'
            entity_id: binary_sensor.giris_kapisi_kapi_sensoru_kapi
action:
  - service: notify.mobile_app_okan_iphone
    data:
      message: Window is open!
mode: single

Very strange, looks like “or” is not working. I mean if one of window is open but another window is closed, not sent any notification. But normally should be if one of window is open it can be work, because i used “or” am i wrong? Please somebody check and help me about that?

Thanks in advance

Please format your posted config correctly.

https://community.home-assistant.io/t/how-to-help-us-help-you-or-how-to-ask-a-good-question/114371#oneone-format-it-properly-16

1 Like

I changed the command. I hope now is okay

The way you are combining and and or conditions doesn’t make sense. If you just want to alert if either of the windows is open:

condition:
  - condition: or
    conditions:
      - condition: state
        entity_id: binary_sensor.salon_pencere_sensoru_pencere
        state: 'on'
      - condition: state
        state: 'on'
        entity_id: binary_sensor.giris_kapisi_kapi_sensoru_kapi
2 Likes

It works :slight_smile: Thank you so much. So Is there a way to specify which one is open in the message content? For example if A window is open message will inform about it but if B window is open another message

An easier way would be to set up a group for the windows. I have a notification set up that if I leave a any window open in the group it will send an alert after we close our bedroom door in the evening.

description: ''
trigger:
  - type: not_opened
    platform: device
    device_id: e71c134acb81c8be7a35797a38ab10dd
    entity_id: binary_sensor.master_bedroom_door_home_security_intrusion
    domain: binary_sensor
condition:
  - condition: state
    entity_id: group.monitored_windows
    state: 'on'
  - condition: time
    after: '19:00:00'
    before: '23:59:00'
action:
  - service: notify.alexa_media_bedroom_dot
    data:
      message: Attention. A window is still open.
      data:
        type: announce
        method: all
mode: single

There is a way to announce what window is open, I just havent gotten that far.

1 Like

For triggers, it’s easy - there is an object you can reference and insert in your message.

For conditions, the only way I know is to compare all your states using a template that will be used to build your text message.

There is an example near the beginning of that page that should get you started, or possibly one of the code gurus reading this can whip one up for you.

1 Like

Looks good. I need to check how to create a group for this sensors. Thanks

I hope someone can prepare for me a code :slight_smile: Because I’m not good with HA codes :slight_smile: Thanks

Start with something like:

action:
  - service: notify.alexa_media_bedroom_dot
    data:
      message:  >
            {% if is_state('binary_sensor.salon_pencere_sensoru_pencere', 'on') %}
              Salon window is open!
            {% else %}
              Entrance door is open!
            {% endif %}
      data:
        type: announce
        method: all

This assumes only one is open… If you want to announce multiple states it can get complicated… Also you can expand members of a group and test them, again it’s all in the linked Templates document and the Jinja references it links to.

If you are going to start playing around with notifications in HA, I’m afraid you are going to have to learn how to write at least some code.

1 Like

Thank u so much. I’ll try and i’ll work on this

I copied the code like this but it’s not worked. I mean, there was an error. If is it possible Could you please test this on your HA? for a light or switch maybe.