Need help with automations

Hi All,

I am trying to configure 2 different automations and I have tried several different configurations and searched the forums with no luck

  1. I have 3 different sensors in one room I would like to turn off the light when there is no motion for 3 minutes for the 3 of them:

Pseudo code:

IF sensor1.state = off AND sensor2.state = off AND sensor3.state = off FOR 3 minutes THEN “do something”

- alias: 'Study room Turn Off Light'
  initial_state: 'on'
  trigger:
    platform: state
    entity_id: binary_sensor.study_room_motion_sensor
    to: 'off'
    for:
      minutes: 3
  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: binary_sensor.study_room_pir_sensor
        to: 'off'
        for:
          minutes: 3
      - condition: state
        entity_id: binary_sensor.study_room_camera_motion
        to: 'off'
        for:
         minutes: 3  
 action:
   - service: switch.turn_off
     entity_id: switch.studyroom_light

Get an error:

Error loading /home/homeassistant/.homeassistant/configuration.yaml: while parsing a block collection
  in "/home/homeassistant/.homeassistant/automations.yaml", line 4, column 1
expected <block end>, but found '<block mapping start>'
  in "/home/homeassistant/.homeassistant/automations.yaml", line 1729, column 2

Second automation:

I want to turn on the tv back led light even if the harmony state is already on (not when turning on the harmony remote) when it’s dark outside

IF harmony.remote.state = on AND sun = after_sunset OR sun = before_sunrise THEN “do some thing”

Do I need to scan for changes ? how would you create such automation ?

Thanks!

you can’t use the to: in a condition as you’re checking a current status, not what status an entity will change from or to (this is where the trigger comes into play)
by default conditions are “AND” so you can simply list them one after the other.
What you need is 3 triggers (one for each entity) and 3 conditions:

- alias: 'Study room Turn Off Light'
  initial_state: 'on'
  trigger:
    - platform: state
      entity_id: binary_sensor.study_room_motion_sensor
      to: 'off'
      for:
        minutes: 3
    - platform: state
      entity_id: binary_sensor.study_room_camera_motion
      to: 'off'
      for:
        minutes: 3
    - platform: state
      entity_id: binary_sensor.name_of_your_3rd_sensor
      to: 'off'
      for:
        minutes: 3
  condition:
    - condition: template
      value_template: '{{(as_timestamp(now()) - as_timestamp(states.binary_sensor.study_room_motion_sensor.last_updated | default(0)) | int > 180 )}}'
    - condition: template
      value_template: '{{(as_timestamp(now()) - as_timestamp(states.binary_sensor.study_room_camera_motion.last_updated | default(0)) | int > 180 )}}'
    - condition: template
      value_template: '{{(as_timestamp(now()) - as_timestamp(states.binary_sensor.name_of_your_3rd_sensor.last_updated | default(0)) | int > 180 )}}'
 action:
   - service: switch.turn_off
     entity_id: switch.studyroom_light

of course replace name_of_your_3rd_sensor with the actual name of your 3rd sensor

Thanks @lolouk44 Appreciate the help!

1 Like