Creating an MQTT auto on/off for sonoff

Hi I Have a project i’m planing to do but I have one problem with it

My project is

~~ I have a door that has an unlock mechanisim by pressing a button when that button is pressed it gives a tiny bit of current for the door to open

I have a sonoff pow flashed with tasmota that I want to hook up to that door
so I can control the door with my phone

as I said I have one problem that I haven’t figured out yet

when I trigger the one switch on the sonoff
it makes the door open until I hit off

when it was just a button , it just gave the door current for like 1 second maybe less and automaticly turned off

Can I do a thing with home assistant that says

when door is on (IF DOOR IS “ON”)
Then wait 1 second and change state to off

Do like an IF/ELESE And ELSEiF with home assistant

You can just write a simple automation triggered by sensing the switch changes to on, then delay for however long you want and then turn the switch off. I have one that senses the shed light state changes to on, waits five minutes, then turns the switch off, same principle as what you’re after.

thank you

I’m new to home assistant so I don’t know how to do that

can you give me a link for the documentation for that

Just read through the basic HA automation docs to get the gist and then you can simply modify my shed one below to suit, light.shed is a Sonoff Basic…

- id: shed_light_timer
  alias: Shed light timer
  hide_entity: false
    platform: state
    entity_id: light.shed
    from: 'off'
    to: 'on'
      minutes: 5
  - entity_id: light.shed
    service: homeassistant.turn_off

I think there is a tasmota solution for that.
See here

1 Like

As @datamonkey says, the way forward is to use Tasmota’s pulsetime command. I use this with a Sonoff to open/close garage doors and an outside gate, all of which respond to a momentary circuit close.

There is one “gotcha” to watch out for: usually when specifying a switch in HA yaml files I set retain: true to allow for the open/close state to be retained in MQTT over power outages. Do not do this for these momentary switches. If you do then they will open/switch on whenever HA restarts.

Here’s a sample yaml of mine:

- platform: mqtt
  name: "Gate"
  state_topic: "cmnd/sonoff-015-Gate/POWER4"
  command_topic: "cmnd/sonoff-015-Gate/POWER"
  availability_topic: "tele/sonoff-015-Gate/LWT"
  qos: 1
  payload_on: "ON"
  payload_off: "OFF"
  payload_available: "Online"
  payload_not_available: "Offline"
  retain: false # NB FALSE here - we do not want to retain the ON flag posted to open

(Note that the state topic here is based on a reed switch sensor being attached to GPIO pins on the Sonoff.)

Oh der! Sorry, I hadn’t spotted that it was my post that @datamonkey quoted!!

1 Like