When i trigger a relay on.. cant work out how to delay 15 secs then turn off

Hi ya all.

so im quite new to home assistant and I am having issues with a relay and door lock.

ok so i can control the door lock via mqtt, i can manually turn it on and off. i am now trying to configure HA to turn the relay off after 15 seconds.

i am using a esp-01 to control a relay that runs to a door latch.

the entity is switch.shed_door

i just cant work the code out at all. I could change the arduino code on the esp but down the track its easier to mod the HA config rather than the arduino code.

automation:

  • alias: Turn off relay after a delay
    trigger:
    platform: state
    entity_id:switch.shed_door
    to: ‘off’
    for:
    seconds: 15
    action:
    service: homeassistant.turn_off
    entity_id: switch.shed_door

seems not to work. i guess i got it wrong somewhere :stuck_out_tongue:

any assistance would be great

thanks in advance :slight_smile:

In your automation, nothing will happen. That’s because you are waiting 15 seconds after the switch.shed_door is turned OFF, then telling HA to turn OFF the same switch.

Assuming that something else is turning ON the switch, change your trigger to ON instead of OFF.

1 Like

thanks :slight_smile: yeah when i manually flip the switch on my phone its ment to flip the relay for 15 secs then turn it back off. I built a 12v - 3.3 to control the esp-01 and i just dont wana get the voltage reg to hot (only blown one cap so far lol. forgot to swap out a 10v cap for a 16 when i changed incoming psu)

You need another automation to reset the relay. I have one here

sweet. thanks for that :slight_smile: