Multiply "AND" & "OR" Conditions In One Automation

Hi There, im wanting to have an automation that turns the heating on and off depending on a couple of conditions, one been if me or the wife leave the house and the second been if theres no motion on some smartthings motions detectors. so in my head it goes if me and the wifes trackers are “not_home” turn heating off or if there’s “inactive” on the detectors for 45mins turn the heating off but there’s 3 detectors so im guessing they need to be in a and condition so that all three have to be inactive for 45mins and not on its own that been said i believe i need it to go “AND” “OR” “AND”. i may be wrong but im no expert hopefully someone can help

  - alias: 'Nest Away No Motion Or No One Home'
trigger:
  - platform: state
    entity_id: device_tracker.psp
    state: 'not_home'
  - platform: state
    entity_id: device_tracker.ac3743a06a78
    state: 'not_home'
  - platform: state
    entity_id: sensor.smartthings_dining_room_motion_detection
    to: 'inactive'
    for: 00:45:00
  - platform: state
    entity_id: sensor.smartthings_kitchen_room_motion_detection
    to: 'inactive'
    for: 00:45:00
  - platform: state
    entity_id: sensor.smartthings_living_room_motion_detection
    to: inactive
    for: 00:45:00
condition:
  condition: and
  conditions:
  - condition: state
    entity_id: climate.heating
    state: heat
  - condition: state
    entity_id: device_tracker.psp
    state: 'not_home'
  - condition: state 
    entity_id: device_tracker.ac3743a06a78
    state: 'not_home'
  - condition: or
    conditions:
    - condition: and 
      conditions:
      - condition: state
        entity_id: climate.heating
        state: heat
      - condition: state
        entity_id: sensor.smartthings_dining_room_motion_detection
        to: 'inactive'
        for: 00:45:00
      - condtion: state
        entity_id: sensor.smartthings_kitchen_room_motion_detection
        to: 'inactive'
        for: 00:45:00
      - condtion: state
        entity_id: sensor.smartthings_living_room_motion_detection
        to: inactive
        for: 00:45:00
action:
  - service: nest.set_mode
    data:
      home_mode: away
  - service: notify.ios_pauls_iphone_
    data_template:
      title: "Heating"
      message: "Nest set to Away - Yippee, pennies are being saved :-)"

sorry if ive posted the text wrong :frowning: first post

Thanks Paul

1 Like

Put them in groups.
Make a group for presence and insert the 2 device_trackers (yours and wifes)
and one for motion detection with the 3 motion detectors
That way you can have ONLY 2 instances which will be off or on.
So that means that you can do something like this:
IF presence = off then turn heating off
IF presence = on then turn heating on

IF motion = off for 45mins then turn heating off

Your conditions would be much simpler and it still does the same thing.