Automation does not work

On a Raspberry Pi, I used automation with HA in config.yaml ,it was working good, and now it doesn’t work at all ,I think that is happened after updating HA from 0.86 to 0.91.3, and I don’t know what is the wrong
that’s the code I’m using

automation:
- alias: 'turn on light if distance is less than 5cm.'
  initial_state: 'on'
  trigger:
    platform: state
    entity_id: sensor.distance
    below: 5
    for:
      seconds: 3
  action:
    service: switch.turn_on
    entity_id: switch.pir

- alias: 'Turn on hall light when there is movement.'
  initial_state: 'on'
  trigger:
    platform: state
    entity_id: binary_sensor.pir1
    from: 'off'
    to: 'on'
    for:
      seconds: 5
  action:
    service: switch.turn_on
    entity_id: switch.electricvalve

the first part was working good, after I use the second part only, it didn’t work, I back to the first one, and found that it’s not working too, if any one have an idea about what is happening here ?

Does it work if you comment the 'for: seconds: ’ lines out?

Not sure about the first one, but my PIR will not keep an ‘on’ state for 5 secondes, so in my case it would never trigger.

1 Like

I put that code in automation.yaml ,and it works :grinning: ,it was just a problem with trigger ,should start automation manually after updating HA ,thanks for your support, I appreciate that
here’s the code of automation.yaml

- id: '1'
  alias: 'Turn on hall light when there is movement.'
  initial_state: True
  trigger:
    platform: state
    entity_id: binary_sensor.pir1
    from: 'off'
    to: 'on'
  action:
    service: switch.turn_on
    entity_id: switch.electricvalve


- id: '2'
  alias: 'Turn off hall light when there is no movement.'
  initial_state: True
  trigger:
    platform: state
    entity_id: binary_sensor.pir1
    from: 'on'
    to: 'off'
    for:
      seconds: 5
  action:
    service: switch.turn_off
    entity_id: switch.electricvalve


- id: '3'
  alias: 'turn on light if distance is less than 5cm.'
  initial_state: True
  trigger:
    platform: numeric_state
    entity_id: sensor.distance
    above: 1
    below: 5
    for:
      seconds: 3
  action:
    service: switch.turn_on
    entity_id: switch.pir

- id: '4'
  alias: 'turn off light if distance is more than 5cm.'
  initial_state: True
  trigger:
    platform: numeric_state
    entity_id: sensor.distance
    above: 5
  action:
    service: switch.turn_off
    entity_id: switch.pir