Blueprint with OR Condition

Relative newbie here trying to edit a working blueprint to include an OR condition.

Basically the objective is that I want a light to turn one when either of the two sets of states exist:

1… Motion Sensor Triggered and Light sensor below a specified level

– OR –

2… Motion Sensor Triggered and Binary Sensor is True

The idea is that once a light turns on, the light sensor picks up that luminance and sets the light lux higher so if someone leaves a room and then comes back in after the light turns off but before the light level has a chance to reset, the light will not turn on. Therefore, i want it to turn on no matter what the light level is if that light was recently (within the last 3 minutes) turned off.

First I created binary_sensors with the following as one example:

- binary_sensor:  
- name: light_hall_down_recent  
state: "{{ now() - states('sensor.light_hall_down_off_time') | as_datetime < timedelta(minutes=3) }}"

Then I took a known working Blueprint (it’s what I am currently using) and copied the file but gave it a different name - then I edited it.

The Blueprint shows up in the list in the UI, but when I go to save an automation I get:

“Message malformed: Unexpected value for condition: ‘None’. Expected and, device, not, numeric_state, or, state, sun, template, time, trigger, zone, a list of conditions or a valid template @ data[‘action’][0]”

Pretty sure I have a simple mistake somewhere in the YAML I added in this section:

action:
  - choose:
    - conditions:
      - condition: state
        entity_id: !input motion_entity
        state: 'on'
      - condition: numeric_state
        entity_id: !input illuminance_entity
        below: !input lux_trigger_value
    or:
    - conditions:
      - condition: state
        entity_id: !input motion_entity
        state: 'on'
      - condition: state
        entity_id: !input recent_off_sensor
        state: 'on'
      sequence:
        - service: homeassistant.turn_on
          target:
            entity_id: !input light_target
    - conditions:
      - condition: state
        entity_id: !input motion_entity
        state: 'off'
      sequence:
        - service: homeassistant.turn_off
          target:
            entity_id: !input light_target

As far as i know, you can not use an or in the choose part of an automation.
Here you have to make a “path” for every set of conditions and every part has to have a sequence.
EDIT: See below how to use an or in the conditions of the choose part. This here works but is only one way to solve the problem.

Understanding it right, this should work:

action:
  - choose:
    - conditions:
      - condition: state
        entity_id: !input motion_entity
        state: 'on'
      - condition: numeric_state
        entity_id: !input illuminance_entity
        below: !input lux_trigger_value
      sequence:
        - service: homeassistant.turn_on
          target:
            entity_id: !input light_target
    - conditions:
      - condition: state
        entity_id: !input motion_entity
        state: 'on'
      - condition: state
        entity_id: !input recent_off_sensor
        state: 'on'
      sequence:
        - service: homeassistant.turn_on
          target:
            entity_id: !input light_target
    - conditions:
      - condition: state
        entity_id: !input motion_entity
        state: 'off'
      sequence:
        - service: homeassistant.turn_off
          target:
            entity_id: !input light_target

So the light goes on if the motion_entity is on and the recent_off_sensor is on, OR the motion_entity is on and the illuminance_entity is below your value.
Is it that what you wanted?

Your statement is correct as to the objective

Then give it a try, it should throw no more errors :wink:

Got this:

Message malformed: Unexpected value for condition: ‘None’. Expected and, device, not, numeric_state, or, state, sun, template, time, trigger, zone, a list of conditions or a valid template @ data[‘action’][0]

Then please post the whole blueprint to have a look at

Starting to question whether this is my problem:

recent_off_sensor:
  name: Recent Off Sensor
  description:  The name of the Binary Sensor that was created to determine if the switch was recently on
  selector:
    entity:
      domain: 
        - input_boolean
        - binary_sensor

Hang on, I found that there was a problem with the nut behind the HID - I had saved the file to my local drive to cut and paste it and so it was that file I was editing and not the one on HA - let me try again and let you know in a few

Got a slightly different error message now:

Message malformed: Entity light_hall_down_recent is neither a valid entity ID nor a valid UUID for dictionary value @ data[‘action’][0][‘choose’][1][‘conditions’][1][‘entity_id’]

…off to go figure that one out now - no doubt a simple mistake too.

Found a typo - and once corrected that will now save as a new automation - off to go test it now

Here is one of my blueprints with both ‘or’ and ‘and’ conditions in choose statements. You can nest these as well, just keep indenting the same format.

https://github.com/SirGoodenough/HA_Blueprints/blob/c05d6fb431c1d84cb145c7d6dd5ffe5a60b1d9e2/Automations/AutoFanControl_HA_fan.yaml.

Works like a charm - thank you for your help.

So to your original comment about an OR being used, I could have implemented an OR in the ‘condition’ section under the ‘trigger’ part of the automation - though I am not sure how I could have done that with this use case - is that correct?

Individual triggers are ‘or’-ed without doing anything.

If one of the suggestions listed solves your problem, please consider clicking the solution button to close the thread.
\

Its never to late to learn, thanks for clearing!
So with an or in the conditions it would have to look like this:

action:
  - choose:
    - conditions:
      and:
      - condition: state
        entity_id: !input motion_entity
        state: 'on'
      - or:
        - condition: numeric_state
          entity_id: !input illuminance_entity
          below: !input lux_trigger_value
        - condition: state
          entity_id: !input recent_off_sensor
          state: 'on'
      sequence:
        - service: homeassistant.turn_on
          target:
            entity_id: !input light_target
    - conditions:
      - condition: state
        entity_id: !input motion_entity
        state: 'off'
      sequence:
        - service: homeassistant.turn_off
          target:
            entity_id: !input light_target

Yup, that’s an item ‘and’ -ed with the ‘or’ of 2 other items.

The “And” condition is unnecessary in that case. “And” is only really necessary within an “Or” or “Not” condition when you need multiple individual conditions to act as a single logical clause.

True. But I didn’t correct it because when you are trying to sort this in your head and you are unfamiliar with it, this spells out exactly what is happening.

But yes, the assumption in conditions is ‘and’, as opposed to the assumption in triggers being ‘or’.

I would disagree with the post you picked as a solution, as what is stated there is not true. Perhaps Mike’s other post would be more suitable.

I already marked an answer as Solved previously - the same that whas then corrected. Either way, it got me a working Blueprint.

As always, the assistance is greatly appreciated.

1 Like