binary_sensor:
- platform: gpio
pin:
number: GPIO4
name: "Cat repellor 1 PIR"
id: pir
device_class: motion
on_press:
if:
condition:
switch.is_off: switch.sonar
then:
- switch.turn_on: sonar
- delay: 10s
- switch.turn_off: sonar
switch:
- platform: gpio
name: "Cat repellor 1 Switch"
id: sonar
pin:
number: GPIO27
inverted: False
I aim to turn on (and 10 seconds later off) the switch only if the current state of the switch is off.
I’m getting this error:
INFO Reading configuration...
Failed config
binary_sensor.gpio: [source /config/esphome/esp32dev01.yaml:40]
platform: gpio
pin:
number: GPIO4
name: Cat repellor 1 PIR
id: pir
device_class: motion
on_press: [source /config/esphome/esp32dev01.yaml:47]
[if] is an invalid option for [on_press]. Please check the indentation.
if: [source /config/esphome/esp32dev01.yaml:48]
condition:
switch.is_off: switch.sonar
then:
- switch.turn_on:
id: sonar
- delay: 10s
- switch.turn_off:
id: sonar
```