Automation for a gate opener

hi, I need to create an automation for a gate opener, using a sonoff mini zigbee with a relay, but since the inching cannot be changed I have to create the automation that allows the sonoff to activate and deactivate for a second

basically i should make it work like a button

is the automation correct?

automation:
  - alias: Accendi e spegni interruttore
    trigger:
      - platform: state
        entity_id: switch.mio_interruttore
        to: 'on'
    action:
      - service: switch.turn_on
        entity_id: switch.mio_interruttore
      - delay:
          seconds: 1
      - service: switch.turn_off
        entity_id: switch.mio_interruttore

Create a Button:

  1. Go to Settings > Devices & Services > Helpers
  2. Click Create Helper
  3. Click on Button
  4. Enter a name like Gate
  5. Click Create

You now have a new button entity called input_button.gate

Create the following automation:

alias: Accendi e spegni interruttore
trigger:
  - platform: state
    entity_id: input_button.gate
    to:
action:
  - service: switch.turn_on
    target:
      entity_id: switch.mio_interruttore
  - delay:
      seconds: 1
  - service: switch.turn_off
    target:
      entity_id: switch.mio_interruttore

it gives me an error

    alias: Accendi e spegni interruttore
    trigger:
      - platform: state
        entity_id: input_button.cancelletto
        to:
    action:
      - service: switch.turn_on
        target:
          entity_id: input_button.cancelletto
      - delay:
          seconds: 1
      - service: switch.turn_off
        target:
          entity_id: input_button.cancelletto

What’s the error?

BTW, you didn’t implement my example and created something very different, despite the very clear instructions I provided. For example, you’re using a switch.turn_on to try to turn on an input_button (an invalid operation). What was your reason for changing the example?

what should I put in place of “switch.my_switch” ? I only replaced the one from your example

I tried to insert a led light entity to see if it works, but it doesn’t work

  alias: Accendi e spegni interruttore
  trigger:
    - platform: state
      entity_id: input_button.cancelletto
      to:
  action:
    - service: switch.turn_on
      target:
        entity_id: light.led_cucina
    - delay:
        seconds: 1
    - service: switch.turn_off
      target:
        entity_id: light.led_cucina

Post the automation’s trace.

Triggered manually at 27 febbraio 2023 alle ore 22:40:14

Interruttore: Turn on Led

Delay for 1 second

1 secondo later

Interruttore: Turn off Led

Finished at 27 febbraio 2023 alle ore 22:40:15 (runtime: 1.04 seconds)

According to the trace you tested the automation by triggering it manually. That skips the automation’s trigger section and simply tests the action section.

Test the automation by finding the Button you just created, input_button.cancelletto, in your default Dashboard and clicking PRESS. For example, here’s one I have that’s called Test.

Screenshot_20230227-181531~2

If you can’t find it then create an Entities card containing input_button.cancelletto.

After you have done that, click PRESS (maybe it has a different name in your native language) and it will trigger the automation.

I found the button I created, but if I click it, nothing happens

Senza titolo3

I have this warning in the log

WARNING (MainThread) [homeassistant.helpers.service] Unable to find referenced entities light.led_cucina or it is/they are currently not available

when I click on the hash button

It’s becoming increasingly difficult to assist you because the examples you are testing aren’t what I have suggested (you’re substituting other entities for the actual switch that’s needed) and employing improper testing techniques (that don’t actually test the automation’s trigger). All of these deviations and improvisations are making this process much longer and more error prone.

I ask that you please tell me the entity_id of the Sonoff switch that you will be using for the gate opener. Then I ask that you please replace switch.sonoff in the following automation with the actual entity_id of your Sonoff switch.

  alias: Accendi e spegni interruttore
  trigger:
    - platform: state
      entity_id: input_button.cancelletto
      to:
  action:
    - service: switch.turn_on
      target:
        entity_id: switch.sonoff
    - delay:
        seconds: 1
    - service: switch.turn_off
      target:
        entity_id: switch.sonoff

This is an extremely simple automation and should take mere minutes to create and test if followed according to my instructions. Remember you have to click the button’s PREMI to trigger the automation. Afterwards, check the automation’s trace to confirm it was properly triggered and turned the Sonoff switch on and off

- id: '6'
  alias: Accendi e spegni interruttore
  trigger:
    - platform: state
      entity_id: input_button.cancelletto
      to:
  action:
    - service: switch.turn_on
      target:
        entity_id: light.cancelletto_monte
    - delay:
        seconds: 1
    - service: switch.turn_off
      target:
        entity_id: light.cancelletto_monte

I did what you asked me, but it still doesn’t work, the id of the sonoff open gate is: light.cancelletto_monte.

the log brings me this error:
Unable to find referenced entities light.cancelletto_monte or it is/they are currently not available

Originally you stated:

How can you have a relay that appears as a light entity in Home Assistant? A relay is an on/off device which is typically modeled as a switch in Home Assistant.

In addition, the error message indicates Home Assistant can’t even find an entity named light.cancelletto_monte.

Unable to find referenced entities light.cancelletto_monte or it is/they are currently not available

I really want to help you but you’re providing me with so much misleading information that it’s becoming exceedingly difficult to guess what is or isn’t true.

Let me know when you find the correct entity_id of what actually represents the Sonoff device.

@123 I had problems with the ZHA zigbee network, that’s why I couldn’t find the entity now I solved it, and transferred to zegbee2MQTT