I have a working automation, when pushing a button on my wallmote the lamp turning on however I would like it to turn off after x minutes. I tried a lot but cannot find the solution.
What exactly do you mean by it doesn’t work? Is it possible you’re trying to trigger the automation again while it’s still running? (E.g., with the delay set to 3 hours, are you pushing the button again on your wallmote before the 3 hours has expired?)
I’d suggest putting the actions into a script, and using the automation to run the script. And, specifically, like this:
The idea is, if you push the button again before the script is done (i.e., it’s still sitting in the delay), the automation will first make sure the script is stopped. Then it can be sure to be able to start it (from the beginning. Note that a running script can’t be started/restarted. It has to be stopped first. I believe the same applies to the actions of an automation.)
Also note that you should probably use the switch.toggle service instead of the homeassistant.toggle service, since you know the entity is a switch. Generally you only need to use a homeassistant.xxx service when you want to run that service with a heterogeneous set of entities. (In your case homeassistant.toggle will just turn around and call switch.toggle, so you might as well call switch.toggle directly, which is slightly more efficient.)
I mean that it isn’t operating when I setup to turn it off after 3 hours. Your suggestion works perfect, I never worked with a script so it was a challenge but both of your suggestion works fine.
I think there is still some possible glitch and in some cases you have to switch to Yaml and edit it and (Last picture) and sometimes it works in webGUI.
This method works really well for me.