Hello,
I have an ESP32 with ESPHome where I have two PIRs connected.
I now have an automation in HA that detects the walking direction of a person by the PIRs, of which one is mounted on the outside of a room door and the other on the inside.
It does this by detecting which of the PIRs triggered first, and then waiting for the other one to trigger within 5 seconds, if it does, it increments (if the outer sensor triggered first) or decrements (if the inner one triggered first) an input_number (which I would replace with a template number on the ESP).
HA Automation code
I currently have the following Home assistant Automation code:
alias: PZ Ergänzung
description: ""
trigger:
- platform: state
entity_id:
- binary_sensor.door_personcounter_bwm_aussen
id: Aussen
to: "on"
- platform: state
entity_id:
- binary_sensor.door_personcounter_bwm_innen
id: Innen
to: "on"
condition:
- condition: or
conditions:
- condition: state
entity_id: binary_sensor.door_personcounter_bwm_innen
state: "on"
- condition: state
state: "on"
entity_id: binary_sensor.door_personcounter_bwm_aussen
action:
- choose:
- conditions:
- condition: trigger
id: Aussen
sequence:
- choose:
- conditions:
- condition: state
entity_id: binary_sensor.door_personcounter_bwm_innen
state: "off"
sequence:
- wait_for_trigger:
- platform: state
entity_id:
- binary_sensor.door_personcounter_bwm_innen
for:
hours: 0
minutes: 0
seconds: 0
from: "off"
to: "on"
continue_on_timeout: false
timeout:
hours: 0
minutes: 0
seconds: 10
milliseconds: 0
- service: input_number.increment
data: {}
target:
entity_id: input_number.pz_pirs
- conditions:
- condition: trigger
id: Innen
sequence:
- choose:
- conditions:
- condition: state
entity_id: binary_sensor.door_personcounter_bwm_aussen
state: "off"
sequence:
- wait_for_trigger:
- platform: state
entity_id:
- binary_sensor.door_personcounter_bwm_aussen
for:
hours: 0
minutes: 0
seconds: 0
from: "off"
to: "on"
continue_on_timeout: false
timeout:
hours: 0
minutes: 0
seconds: 10
milliseconds: 0
- service: input_number.decrement
data: {}
target:
entity_id: input_number.pz_pirs
mode: restart
Could you please help me with how to do that in ESPHome (directly on the ESP with the sensors) as I don’t quite understand the ESPHome way of creating automations like this?
Best regards
Aaron