Esphome with sonoff and PIR (solved)

Question:

I have a sonoff basic with a pir sensor on GPIO14.

Normally the automation is done by HomeAssistant but if its down ( rebooting / wifi down or what ever) the automation isn’t there anymore. So the lights wont go on.
The automation in HA is like this :

  - alias: '[PIR] Kledingkast on'
    trigger:
      - platform: state
        entity_id: binary_sensor.kledingkast_pir
        to: 'on'
    action:
      - service: switch.turn_on
        entity_id:
          - switch.kledingkast



  - alias: '[PIR] Kledingkast off after 50 seconds'
    trigger:
      - platform: state
        entity_id: binary_sensor.kledingkast_pir
        to: 'off'
        for:
          seconds: 50
    condition:
      - condition: state
        entity_id: switch.kledingkast
        state: 'on'

    action:
      - service: switch.turn_off
        entity_id:
          - switch.kledingkast

How can I make this work in esphome so that the automation is done within esphome-sonoff?
The thing is that in esphome the relay is acting like a toggle switch. So every time there is movement its toggling the relay on and off…

what I need is a if then else I guess… and some sort of dummy sensor with will be on or off

this is my esphome yaml :

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    name: "Sonoff Basic Button"
    on_press:
      - switch.turn_on: relay
  - platform: gpio
    pin: GPIO14
    name: "PIR Sensor"
    device_class: motion
    id: my_motion
    on_press:
      - switch.turn_on: relay
  - platform: template
    name: temp_motion
    lambda: 'return id(my_motion).state;'
    filters:
      - delayed_off: 1min
    on_release:
      - switch.turn_off: relay

switch:
  - platform: gpio
    name: "Sonoff Basic Relay"
    pin: GPIO12
    id: relay

status_led:
  pin:
    number: GPIO13
    inverted: yes

but thats not working as I want it to work

update:
had to make it switch.turn_on/off instead of toggle :slight_smile:

6 Likes

great
I learned a lot from your sharing

thanks for the share !!