AND condition not working

I have an automation condition that is driving me nuts… I’m trying to do a simple AND condition checking the state of two entities and then fire an alert. If I put each entity in by itself, I get the alert, so I know I have the entities right. As a further test, I tried using the same entity_id (shown below) with an AND in it… This doesn’t fire, however if I change the ‘and’ to an ‘or’ it fires. Seems the below should fire either way. My end results, the second entity_id will be another device with a state of ‘on’…

- alias: MediaTVAlert
   trigger:
     - platform: time
       seconds: 15
   condition:
     condition: and
     conditions:
       - condition: state
         entity_id: media_player.denon_avrs910w
         state: 'off'
       - condition: state
         entity_id: media_player.denon_avrs910w
         state: ‘off’
    action:
    service: notify.ios_qiphone
    data:
      title: "Media TV Alert"
      message: "TV in Media Room has been left on"
      data:
        push:
          thread-id: “MediaTVAlert-1”

you appear to have 2 identical conditions and your whole code is unreadable because you didn’t follow the instructions at the top telling you how to post code.

My bad - fixed the code block… Yes, in the example above I do have two of the same… As mentioned that was for testing and trying to better illustrate that the ‘and’ isn’t working while putting an ‘or’ there instead does work — two exact items ANDed together or the same two items ORed together should yield the same results to me.

End results my condition would look like this once I can figure out the ‘and’ issue:

- alias: MediaTVAlert
  trigger:
    - platform: time
      minutes: 15
  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: binary_sensor.media_tv_status
        state: 'on'
      - condition: state
        entity_id: media_player.denon_avrs910w
        state: ‘off’
  action:
   service: notify.ios_qiphone
   data:
     title: "Media TV Alert"
     message: "TV in Media Room has been left on"
     data:
       push:
         thread-id: “MediaTVAlert-1”

ok… the trigger is stuffed. 15 minutes what??? that is not a trigger.

FYI, conditions are ‘AND’ by default, you dont need to specify it

@DavidFW1960 I want to check these two conditions every 15 minutes to detect if the device was left on.

@sparkydave I tried not having the and condition and got the same behavior. I’ve tried numerous scenarios and testing methods. Sure it’s something simple but I can’t see it.

it’s still not a trigger the way you have defined it

I’m not sure how else I would do it… I saw some examples of using the platform time as a trigger elsewhere… If I remove the and conditions and have just 1 (either one) it works and fires every 15 minutes as i would expect.

scratch that.

your quote is different for each condition… the second type is invalid… have a close look

        state: 'on'
        state: ‘off’

same later down

2 Likes

Following the docs below… It sure seems like that’s a valid trigger… What am I misunderstanding?

see my edits

Oh, Son of a… been staring at this for hours… making changes to test!

1 Like

yeah that’s a nasty cut/paste that caused that. You’re not the first person to get hit with that!

Verified — that got it to fire correctly… Doesn’t help I’ve been doing all my edits vis ssh on my iPad either… seems and ssh session really dicks with tick marks for some reason. Thanks! Don’t know that I would have seen that.

Oh that’s a bastard! That iPad caught me as well with those bloody quotes! Glad you nailed it.

FWIW… Turning off “Smart Punctuation” in Settings -> General -> keyboards

Seems to fix the quote and tick marks in ssh sessions from my iPad.

1 Like