And / Or Condition

Hi guys,

I am trying to configure my automations.yaml file to include a condition whereby the automation will only run if the TV (media_player.sony_bravia_tv) is OFF and either one or both of our phones are home.

I followed the section titled " MIXED AND AND OR CONDITIONS" on the Docs page https://www.home-assistant.io/docs/scripts/conditions/

This is what I have so far…

condition:
condition: and
conditions:
- condition: state
entity_id: media_player.sony_bravia_tv
state: ‘OFF’
- condition: or
conditions:
- condition: state
entity_id: device_tracker.3c_28_6d_1f_73_dc
state: home
- condition: state
entity_id: device_tracker.18_65_90_83_67_56
state: home

When I check my config I get “Configuration valid!” but when I view the automation using the Configuration ? Automation editor I see an error message that says

Unsupported condition: and
{
“condition”: “and”,
“conditions”: [
{
“condition”: “state”,
“entity_id”: “media_player.sony_bravia_tv”,
“state”: “OFF”
},
{
“condition”: “or”,
“conditions”: [
{
“condition”: “state”,
“entity_id”: “device_tracker.3c_28_6d_1f_73_dc”,
“state”: “home”
},
{
“condition”: “state”,
“entity_id”: “device_tracker.18_65_90_83_67_56”,
“state”: “home”
}
]
}
]
}

This is all quite new to me so any advice would be greatly appreciated.

You need to use the code blocks to format the text properly.

1 Like

It looks about right but you need to post it again showing the indents you have.

Thanks for your replies, I’ve not posted config snippets before but realize the importance of indentations in yaml now! If anyone can spot what I’m doing incorrectly in this condition please let me know, I’d love to get it working.

  condition:
    condition: and
    conditions:
    - condition: state
      entity_id: media_player.sony_bravia_tv
      state: 'OFF'
    - condition: or
      conditions:
      - condition: state
        entity_id: device_tracker.3c_28_6d_1f_73_dc
        state: home
      - condition: state
        entity_id: device_tracker.18_65_90_83_67_56
        state: home

Try this:

  condition:
    condition: and
    conditions:
    - condition: state
      entity_id: media_player.sony_bravia_tv
      state: 'off'
    - condition: or
      conditions:
      - condition: state
        entity_id: device_tracker.3c_28_6d_1f_73_dc
        state: 'home'
      - condition: state
        entity_id: device_tracker.18_65_90_83_67_56
        state: 'home'
1 Like

Perfect, thanks 123!

I was using the incorrect case for the state and missing the inverted commas around ‘home’

Thanks for pointing this out for me