Automation issue - sensor door + motion + light

Hi
I want to create automation
when the:
door sensor on AND shower lamp light off AND motion sensor on
then
turn on shower lamp light

what wrong in the code?

- id: '1578843093281'
  alias: new automation
  description: ''
  trigger:
  - entity_id: binary_sensor.door_window_sensor_158d00042e4298
    from: 'on'
    platform: state
  condition:
  - condition: and
    conditions:
    - condition: state
      entity_id: binary_sensor.motion_sensor_158d0003956207
      state: 'on'
    - condition: and
      conditions:
      - condition: state
        entity_id: light.showerlamp
        state: 'off'
  action:
  - data:
      entity_id: light.showerlamp
    service: light.turn_on

No need for these nested AND conditions, conditions are anyway AND by default.
Are you sure that you want the door to trigger the automation? Is your motion sensor already β€œon” when you open the door? If the motion sensor turns β€œon” after the door sensor turns β€œon”, this will not work, because at the moment the door sensor triggers the automation, the motion sensor is not β€œon” and therefore it will not fire.

The door sensor is on (open)
light is off
when the motion sensor change off to on
I want the trigger will work

In that case you would want the trigger to be the motion sensor to β€˜on’ and use the door sensor and light state as conditions.

I change the code to this
And still not work

- id: '1578843093281'
  alias: new automation
  description: ''
  trigger:
  - platform: template
    value_template: "{{ is_state('binary_sensor.door_window_sensor_158d00042e4298', 'on')\
      \ and\n   is_state('binary_sensor.motion_sensor_158d0003956207', 'on')\
	  \ and\n   is_state('light.showerlamp', 'off')\
      \ }}\n"
  action:
  - data:
      entity_id: light.showerlamp
    service: light.turn_on
	
	

Why are you using a template now?

Try like this:

- id: '1578843093281'
  alias: new automation
  description: ''
  trigger:
  - platform: state
    entity_id: binary_sensor.motion_sensor_158d0003956207
    from: 'off'
    to: 'on'
  condition:
  - condition: state
    entity_id: binary_sensor.door_window_sensor_158d00042e4298
    state: 'on'
  - condition: state
    entity_id: light.showerlamp
    state: 'off'
  action:
  - service: light.turn_on
    entity_id: light.showerlamp
    
1 Like