Mixed and/or conditions

Hello,

Could someone help me please to validate this config?
I’m trying to power on a device when somebody is home, but only between certain hours.

’ ’ ’

- alias: "high umidity home"
  trigger:
    platform: numeric_state
    entity_id: sensor.bedroom_humidity
    above: 62
  action:
     service: switch.turn_on 
     entity_id: switch.prel_bedroom
condition:
      - condition: state
        entity_id: 'device_tracker.al_iphone'
        state: 'home'
  condition: and
  conditions:
      - condition: time
        after: ‘09:00:00’
      - condition: time
        before: ‘11:59:00’
      - condition: or
        conditions:
        - condition: time
          after: ‘17:00:00’
        - condition: time
          before: ‘19:20:00’

’ ’ ’

Thank you

If you want your automation to only run in the morning or evening, that won’t work the way you’ve written it.
Also remember that conditions are and by default so you’ll only really need to specify and and condition if you’ve specified an or condition first.
You have some weird single quotes. Make sure you use standard single quotes and avoid copying from web pages unless the code was correctly formatted.
Last but not least, watch your indentations. This is critical in yaml.

  condition:
    - condition: state
      entity_id: 'device_tracker.al_iphone'
      state: "home"
    - condition: or
      conditions:
      - condition: and
        conditions:
        - condition: time
          after: '09:00:00'
        - condition: time
          before: '12:00:00'
      - condition: and
        conditions:
        - condition: time
          after: '17:00:00'
        - condition: time
          before: '19:20:00'

Hello @lolouk44,

Thank you for the quick response. So, using your adapted code, the automation still will not working? I’m receiving this error using your code:

“[homeassistant.config] Invalid config for [automation]: expected a dictionary @ data[‘condition’][0]. Got None”

Have you checked your indentations? That’s probably what’s wrong.
Just double checked with a couple of online yaml checkers and got no errors
In your original code there were several indentation issues for the whole condition: block

This is the working version

- alias: alias
  trigger:
    - platform: numeric_state
      entity_id: sensor.humidity
      above: 62
  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: device_tracker.al
        state: 'home'
      - condition: or
        conditions:
        - condition: time
          after: '09:00:00'
          before: '12:00:00'
        - condition: time
          after: '17:00:00'
          before: '19:30:00'
  action:
    service: switch.turn_on
    entity_id: switch.pre
1 Like

Looking for similar assistance. I have several fire tablets around the house that we use as HA dashboards and for live camera feeds. I have multiple cameras and I am trying to get this script/automation to work correctly so that if multiple sensors/cameras are triggered that my “Index” Camera feed pops up which shows all the cameras. I have the individual cameras working correctly at this time.

The time a camera sensor is triggered for is 10 seconds, I can increase this. However my goal would be if a camera is triggered inside of 3 minutes of each other to show the “Index” All Camera feed. I need help with the time formatting on this as well.

Does this look correct for what I am attempting to accomplish?

#############################  Multi Sensor Triggered ########################  
  
- alias: Multi Sensor Triggered
  trigger:
    platform: state
    entity_id: binary_sensor.mqtt_front_door_motion
    to: 'on'
  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: binary_sensor.mqtt_gate_camera_motion
        state: "on"
      - condition: or
        conditions:
      - condition: state
        entity_id: binary_sensor.mqtt_car_garage_door_motion
        state: "on"
      - condition: or
        conditions:        
      - condition: state
        entity_id: binary_sensor.mqtt_driveway_camera_motion 
        state: "on"    
  action:
  - service: homeassistant.turn_on
    entity_id: script.multisensorimage
  - service: homeassistant.turn_on
    entity_id: script.motion_cameras_alexa
  - service: homeassistant.turn_on
    entity_id: script.camerasmotionlr
  - service: homeassistant.turn_on
    entity_id: script.camerasmotionbr
  - service: homeassistant.turn_on
    entity_id: script.camerasmotionmini
  id: d52c6fb9c7c046ab86e13cc99f184ff92  
  
  
#############################  Multi Sensor Triggered ########################  ## 

Conditions are “and” by default so you don’t need the initial and block
For each or block you’d need to get your indentation right
What is the logic that you’re after?
Do you want your automaton to run when mqtt_front_door_motion turns on AND any of the binary sensors in he above condition block is on?

Okay, thank you very much for your help.

I have a multi camera system and I am after a solution where if more than one sensor is triggered within 30 seconds that a different feed that includes all of my cameras (Index) displays up on my tablets.

Currently I have it set where if one of the various cameras is triggered the live feed will display on all my home tablets for 3 minutes, 3 minutes without motion it will return the Home Assistant Dashboard. Actual examples below.

####Motion Front Door
- alias: FD Motionn
  trigger:
    platform: state
    entity_id: binary_sensor.ring_front_door_motion
    to: 'on'
  action:
  - service: homeassistant.turn_on
    entity_id: script.fdimage
  - service: homeassistant.turn_on
    entity_id: script.motion_fd_alexa
  - service: homeassistant.turn_on
    entity_id: script.fdmotionlr
  - service: homeassistant.turn_on
    entity_id: script.fdmotionbr
  - service: homeassistant.turn_on
    entity_id: script.fdmotionmini


###Return to dashboard#####
- alias: All Camera Motion Off
  trigger:
    platform: state
    entity_id: group.camera_sensors
    to: 'off' 
    for:
      minutes: 3
  action:
    - service: display.load_url        
      entity_id: group.all_fully
      data:
        url: http://192.168.87.xx:8123/lovelace/Tablet

I want to include this previous logic so if one camera sensor is set off that that individual display pops up, but if multiple sensors are triggered within 30 seconds to display a different URL to all my tablets.

###Front Door Display Script
fdmotionlr:
  sequence:
    - service: display.turn_on
      entity_id: display.living_room_tablet
    - delay:
        seconds: .3    
    - service: fully_kiosk.screensaver_stop
      entity_id: display.living_room_tablet
    - delay:
        seconds: .3
    - service: display.load_url
      entity_id: display.living_room_tablet
      data:
        url: http://192.168.87.xx:81/mjpg/FD/video.mjpeg

So the answer is yes, I do want the AND, but also the OR to be 2+ sensors --> Index Display.

Thank you again for taking the time to help me!

It’s a little bit complex what you’re after :wink:
This what what I’d do:
Change the trigger to not be the group, but each camera:

  trigger:
    platform: state
    entity_id: binary_sensor.ring_front_door_motion, binary_sensor.ring_back_door_motion, binary_sensor.ring_side_door_motion, etc
    to: 'on'

For the life of me I can’t find the case/switch condition so for now I’d do something along those lines:

  action:
  - service: homeassistant.turn_on
    entity_id: script.fdimage
  - service: script.turn_on
    entity_id: >
      {% if trigger.entity_id == "binary_sensor.ring_front_door_motion" %}
      script.fdimage
      {% elif trigger.entity_id == "binary_sensor.back_door_motion" %}
      script.bdimage
      {% elif trigger.entity_id == "binary_sensor.side_door_motion" %}
      script.sdimage
      {% endif %}
  - wait_template: >
      {%- set camera_sensors = [
            states.binary_sensor.ring_front_door_motion,
            states.binary_sensor.ring_back_door_motion,
            states.binary_sensor.ring_side_door_motion] -%}
      {%- set camera_sensors_on = camera_sensors | selectattr('state','eq','on') | list -%}
      {{ ((camera_sensors_on | length) | int ) > 1}}
  
    timeout: '00:00:30'
    continue_on_timeout: false
  - service: script.turn_on
    entity_id: script.all_camera_feeds_to_show

Please note this is totally untested, but hopefully sets you on the “right” path (right in quotes as I’m sure some bright spark will come up with something better).

The case/switch function is actually called choose:

- choose:
    - conditions: "{{ is_state(trigger.entity_id, 'binary_sensor.ring_front_door_motion') }}"
      sequence:
       - ...