#Multiconditional Automation

28 messages · Page 1 of 1 (latest)

upbeat rock
#

Hey everyone,

I'm trying to smack a bunch of conditionals all into one automation to avoid covering the same concept with multiples and I'm not really managing to do so.

I want to set it up so that when I charge my phone in bed and either my wife is also charging her phone OR she's not home, the lights turn off.

There's a few other conditions involved but it's this "Me and her or me and shes not here" condition that i can't seem to figure out.

description: >-
  Lights turn off after 10:30pm when my phone is charging and either Haruka and I are in the bedroom or just I am and Haruka is not home. 
triggers:
  - entity_id: sensor.jamie_mobile_battery_state
    to: charging
    trigger: state

conditions:
  - condition: time
    after: "22:30:00" 
  - condition: state
    entity_id: sensor.kansaigaijinpc_monitorpowerstate
    state: PowerOff
  - condition: state
    entity_id: sensor.jamies_mobile_ibeacon
    state: bedroom
    and
  - condition: state
    entity_id: sensor.harukas_mobile_ibeacon
    state: charging
    or
  - condition: state
    entity_id: sensor.haruka_location
    state: not_home

actions:
  - target:
      entity_id: group.house_lights
    action: homeassistant.turn_off
    data: {} ```
I added the `and` `or` comments to show you what I'm wanting but don't know how to write it correctly.

I get `Message malformed: required key not provided @ data['actions']` but the actions section hasn't been touched from the currently working automation?
dapper reef
#

just need to replace the last 2 with an OR condition including those 2:

  - condition: or
    conditions:
      - condition: state
        entity_id: sensor.harukas_mobile_ibeacon
        state: charging
      - condition: state
        entity_id: sensor.haruka_location
        state: not_home
upbeat rock
#

ahhhhhhhh I see how that works

dapper reef
#

unless within an "OR" condition, they are ANDed together

upbeat rock
#

the and/or is that

I am charging my phone in the bedroom AND she is charging her phoen in the bedroom
or
I am charging my phoen in the bedroom and she is not home

#
description: >-
  Lights turn off after 10:30pm when my phone is charging and either Haruka and I are in the bedroom or just I am and Haruka is not home. 
triggers:
  - entity_id: sensor.jamie_mobile_battery_state
    to: charging
    trigger: state

conditions:
  - condition: time
    after: "22:30:00" 
  - condition: state
    entity_id: sensor.kansaigaijinpc_monitorpowerstate
    state: PowerOff
  - condition: state
    entity_id: sensor.jamies_mobile_ibeacon
    state: bedroom
   - condition: or
    conditions:
      - condition: state
        entity_id: sensor.harukas_mobile_ibeacon
        state: charging
      - condition: state
        entity_id: sensor.haruka_location
        state: not_home

actions:
  - target:
      entity_id: group.house_lights
    action: homeassistant.turn_off
    data: {}```
this still throws up `Message malformed: required key not provided @ data['actions']`
dapper reef
#

That simplifies to "you are charging the phone (handled by the trigger anyway) AND you are in the bedroom and it's after 10.30pm AND (she is also charging OR she is not home)"

upbeat rock
#

wait hold up i think its because haruka_location isnt a sensor? maybe let me check im using the right thing

dapper reef
#

that looks like an action issue

#

what does the trace say?

upbeat rock
dapper reef
#

i see

#

So OR: (AND: she is charging, is in the bedroom), she is not home

upbeat rock
#
description: >-
  Lights turn off after 10:30pm when my phone is charging and either Haruka and I are in the bedroom or just I am and Haruka is not home. 
triggers:
  - entity_id: sensor.jamie_mobile_battery_state
    to: charging
    trigger: state

conditions:
  - condition: time
    after: "22:30:00" 
  - condition: state
    entity_id: sensor.kansaigaijinpc_monitorpowerstate
    state: PowerOff
  - condition: state
    entity_id: sensor.jamies_mobile_ibeacon
    state: bedroom
  - condition: or
    conditions:
        condition: and
        conditions:
          - condition: state
            entity_id: sensor.haruka_mobile_battery_state
            state: charging
          - condition: state
            entity_id: sensor.harukas_mobile_ibeacon
            state: bedroom
      - condition: state
        entity_id: sensor.harukas_mobile_ibeacon
        state: not_home

actions:
  - target:
      entity_id: group.house_lights
    action: homeassistant.turn_off
    data: {}```

Like that? despite fixing the location, it's still havign issues.
I can't check the trace because this won't save it won't run it
dapper reef
#

does an error message show up when it doesn't save?

upbeat rock
#

it saved when i removed - condition: or conditions: condition: and conditions: - condition: state entity_id: sensor.haruka_mobile_battery_state state: charging - condition: state entity_id: sensor.harukas_mobile_ibeacon state: bedroom - condition: state entity_id: sensor.harukas_mobile_ibeacon state: not_home

#

yeah, the required key error that ive posted a couple of times

#

but with it saving aftewr removing the above, it leads me to believe the formatting is incorrect for the and/or conditionals

dapper reef
#

try building it in the UI

upbeat rock
#

cant do and conditions within the or condition section

dapper reef
#

that's.. strange

upbeat rock
#

oh wait theres a button i hadnt noticed before let me play around

#
description: >-
  Lights turn off after 10:30pm when my phone is charging and either Haruka and
  I are in the bedroom or just I am and Haruka is not home.
triggers:
  - entity_id: sensor.jamie_mobile_battery_state
    to: charging
    trigger: state
conditions:
  - condition: time
    after: "22:30:00"
  - condition: state
    entity_id: sensor.kansaigaijinpc_monitorpowerstate
    state: PowerOff
  - condition: state
    entity_id: sensor.jamies_mobile_ibeacon
    state: bedroom
  - condition: or
    conditions:
      - condition: state
        entity_id: sensor.harukas_mobile_ibeacon
        state: not_home
      - condition: and
        conditions:
          - condition: state
            entity_id: sensor.harukas_mobile_ibeacon
            state: bedroom
          - condition: state
            entity_id: sensor.haruka_mobile_battery_state
            state: charging
actions:
  - target:
      entity_id: group.house_lights
    action: homeassistant.turn_off
    data: {}```

I think I missed a single - on the `conditions: and` line
dapper reef
#

ahhh

#

looks good

upbeat rock
dapper reef
#

no worries! now you've just got to sort out it working when she plugs it in and you're not home 😛

upbeat rock
#

Nah she hates automations so I don't want it to happen liek that lol she can switch things off. I had to buy some zigbee switches so she can manually turn the lights off without actually turning the power switches off and then stopping me from using automations or even HA ingeneral ahah