Send a raspberry pulse to open a door

Hello people. I need to send just one pulse to a specific raspberry port and go back to the initial state.

This setting would be to open my gate.

This pulse should last 1 second. I am using rpi_gpio with a switch button.

MY CODE:

switch:
 - platform: rpi_gpio
   invert_logic: true
   ports:
     18: Open the door 

This should do it:

trigger:
  platform: state
  entity_id: switch.open_the_door
  to: 'on'
  for:
    seconds: 1
action:
  service: switch.turn_off
  entity_id: switch.open_the_door

Add your own alias / id for the automation.

Note: home assistant is not a real time operating system. So your pulse could end up longer than one second if the system load is high.

If the pulse length is absolutely critical you should implement it in hardware with a 555 timer (non-retriggerable monostable) and have the gpio trigger that.

1 Like

hi,

Put this code inside my automations.yaml
but I can’t call this automation from my configuration.yaml file.

switch:
 - platform: rpi_gpio
   invert_logic: true
   ports:
     18: open_the_door

Do not put the switch in automations.yaml, it is not an automation.

Put it in configuration.yaml.

1 Like

Yes, I put it into configuration.yaml. I can’t call automation from my switch. :frowning:

I can’t make run from my switch.

Paste the code you are using and any relavent errors in the log.

1 Like

No log errors.

/config/automations.yaml

trigger:
  platform: state
  entity_id: switch.open_the_door
  to: 'on'
  for:
    seconds: 1
action:
  service: switch.turn_off
  entity_id: switch.open_the_door 

in /config/configuration.yaml

switch:
 - platform: rpi_gpio
   invert_logic: true
   ports:
     18: open_the_door

When creating the automation following your example appeared on the home screen:

The automation I posted only contained the important bits as I was in a hurry. You were supposed to add the other requirements, including correctly making it a list item.

Replace what you have with this:

- id: open_the_door
  alias: Open The Door
  initial_state: true
  trigger:
    platform: state
    entity_id: switch.open_the_door
    to: 'on'
    for:
      seconds: 1
  action:
    service: switch.turn_off
    entity_id: switch.open_the_door 
1 Like

Thanks a lot for the help. I am very happy to have helped me. thank you.