Creating an Automation that activates an inching relay at a set time for a set period

I have an electric gate across my drive and the installation engineers provided me with an external connection to use with a switch or relay. Momentary closing of the switch/relay causes the gate to open.
I have connected a Sonoff inching relay to the provided connection and can control the gate using HA and Alexa voice control.
I am confirming with the installation company that increasing the period the contact is closed will have the effect of keeping the gate open for that period and not damage the controller.
I would like to create an automation that I can use to operate the relay at a set time and keep the relay closed for a set period e.g. 1 hour.
I don’t want to change the default inching period of 1s or add a timer but want to interact with the relay outside of the initial configuration.
the entities exposed are:

  • Drive Gate: - On or Off
  • Inching Mode: Enabled or Disabled (I think??)
  • Inching Duration: Time (currently 1 second)
  • Initial State: On, Off or Memory (currently Memory)
  • Switch Type: Flip, Sync or Button (currently se to button)
  • Timer: Time duration in Hours and Minutes (currently unset)
    Is this possible and can someone point me in the right direction to start. I am happy just to get it working but ideally would like a quick way to set up the date time and duration from the HA home screen or even via a reminder through Alexa

What have you done so far? How to help us help you - or How to ask a good question
I’m sure that can be done. Also having someone or something writing it for you means the second it misbehaves, you will be struggling back to find someone to fix it for you.
The best way to learn is to just try. Run thru the docs on getting started with the automation editor. If you get stuck, come back with what you have done.
Understanding automations - Home Assistant
and
The Home Assistant Cookbook - Index.

Many thanks @Sir_Goodenough . I was not expecting someone to do it for me as I need to learn. I was just after some tips on what elements to use. Unless I misunderstand, its not a straight forward automation.

I was hoping someone may have done something similar which I could adapt. I have searched through the Blueprints and seen a couple of instances that could be adapted but I don’t understand fully how blueprints work. I assume they are a Template but unfortunately although contributors take a lot of time and effort in creating them they don’t document them fully for others to understand how they work. Unless you have programming background its difficult to work out the logic.

I will read though the cookbook and automations sources to try and get my head around how they work. I did do some internet searches and I understand that I need a combination of some helpers, a script and dashboard tile to achieve what I want, but each of these need reading about on how and where to create them. :wink:

A blueprint is basically an automation (or a script or a template) that has variables instead of hard values. I will assume the rest of this you are talking about an automation blueprint.

If you see a blueprint that will do close to what you think, click to import it then in the auttomation editor add a new automation using the blueprint. It will prompt you with questions about what values or entities to use to make it work.

Blueprints are also good sources of understanding how other do code here. You can push the take control button after you have created an automation using the blueprint, then in the automation editor you can see all the authors code with your values added. Just remember that any automation that is in there will try to run, so only 1 version with the same variables should be left to run.

I’m still struggling with this. After a lot of reading of automations and searching though this forum I thought the answer was to create a helper and automation. I therefore created a toggle input-boolean helper and used this in an automation linked this to the inching relay as follows:

alias: Drive Gate Hold Open
description: ""
triggers:
  - trigger: state
    entity_id:
      - input_boolean.front_gate_hold
    for:
      hours: 0
      minutes: 2
      seconds: 0
conditions: []
actions:
  - type: turn_on
    device_id: 9a1b1251d6b45706f034e2eeeaf524eb
    entity_id: 8a797e3e25845658a5fd808f5f407ddb
    domain: switch
mode: single

First I associated the routine with the “Toggle Drive Gate” entity and then “Turn on Drive Gate” entity but neither achieve the gate opening for 2 minutes. The boolean helper has a time of 2 minutes but the gate still only opens for its default period of 30 seconds as triggered by inching mode. I really don’t know what I am doing wrong. Am i going about this all wrong. I just want a button or toggle on the dashboard which I can action that opens the gate for a set period.

You’re delaying the switch by 2 minutes.
That is all you do.

As I understand you want to be able to keep the gate open for a variable time by having this switch turned on for the same amount of time?
How do you want to interact with this?
Do you want to hold a button for the amount of time or do you want a number entity where you set it to x seconds and an automation does the rest?

If you want to test your automation you can remove the for part of the trigger.
Make sure the trigger is set to to: on.

Then after your turn on action, add a delay of 2 minutes, then a switch turn off [this entity].
I also would recommend you to not use device triggers/conditions/actions.
Use switch.turn on action instead and chose the entity id.
It becomes far more readable

Thanks for responding @Hellis81
As I understand you want to be able to keep the gate open for a variable time by having this switch turned on for the same amount of time?
Yes that is correct. I want to leave the current inching time of 1 second for normal operation but be able to override this default by a set time e.g. 2 minutes to keep the gate open longer. (The gate controller has a built in 30 second delay before automatically closing the gate. However it is safe to increase the inching time as long as I need as it wont damage the gate.)
“How do you want to interact with this?”
“Do you want to hold a button for the amount of time or do you want a number entity where you set it to x seconds and an automation does the rest?” The latter. I want a button or switch on the overview page as a favourite so that when I click or toggle it the gate remains open for the programmed time period.

The next part is where I get stuck. I don’t want to change the existing inching mode so thought I needed to create a virtual switch or button to use as the Action for the routine but cant work out how to do that. Secondly I can work out how to set a delay after the action but it doesn’t effect the time period the gate remains open.
Here is a screenshot of the automation GUI


If I run the automation it completes successfully but the gate only opens for the default duration of 30 seconds rather than 2 minutes??
I am beginning to think that you cannot use an inching relay by trying to latch it. I have proved that the gate will stay open longer if I increase the inching period from 1 second to 2 minutes. This makes me think the automation needs to interact with the inching duration entity not the on off entity??.

Could be that it will not work.
Looking at the logo, I’m not surprised stuff doesn’t work.
Do you have any control of this inching time entity?
If so then you can have an automation that resets it to 1 after usage.

That’s a good idea. Yes you can adjust the inching period. I don’t think its necessarily the hardware as I had the same issues with a shelly device. Its my very limited understanding of HA and how to create automations that’s the sticking point. Apart from ChatGPT and this forum there is nowhere else to get specific help.
Do you by any chance have any suggestions how to create an automation that does temporarily changes the inching time entity?

Obviously the target entity is “Inching Duration” and I need a trigger which should ideally be a button press or switch toggle but do I need to create a virtual switch for that?
I have no programming background and it’s the starting point where I get stuck.

What I would do is to create an automation that has a state trigger on this duration entity.
Leave both to and from empty.
This will make the automation trigger on any value.
Set a for time just as you did before.
Say 5 minutes.

Condition is a state condition, should be the duration entity not_to 1. You need to edit the yaml manually. Just add not_ to the to.
That means it will trigger and pass the condition whenever the duration is any other value than 1 second.

Action is to set the duration to 1.