Access Automations from custom components?

Hello,

Simple question: Is possible to access the Automation Rules or an instance of the Automation Editor from within a platform or a component?

I ask this because, I’d like to access it via Python and create an automation rule when run HA for a custom component that i’m doing.

Sorry if this can be a stupid question but, after some Googling and research on the home assistant docs I couldn’t find anything about it.

Cheers

If you are looking to trigger something on home assistant starting (or stopping) see here https://www.home-assistant.io/docs/automation/trigger#home-assistant-trigger

Although it is hard to tell what you mean by “when run HA”.

Hello @nickrout and thanks for you reply.

Let me explain better.

What i’m searching for is, in a custom_component, something like this:
hass.services.register(DOMAIN, NAME, FUNCTION, SCHEMA)

but instead of service call do it for automations, similar to this:
hass.automation.register(...SOME PARAMETERS FOR AUTOMATION RULES HERE...)

In short, can I access the automation rules from python script?

In theory it may be possible by using stuff from https://github.com/home-assistant/home-assistant/blob/c2f1c4b981a173b3e8953ddc92b02d28df7c1959/homeassistant/components/automation/__init__.py.

If your component is form automations only and you want to use python AppDaemon might be better.

What are you trying to do?

Hello @ludeeus and thanks for your reply.

The component that i’m tryng to do is a set of let’s encrypt certificate creation and update services that (currently) use the DuckDNS provider.

For this purpose, the component is not for automations only.
Thus, i think the best choice is the automation module from the link that you shared.

I’ve tried a bit in this hours to find how to use the class/method to add a rule, but the automation module seem a bit complicated to use in a python script (mainly for the absence of docs or examples for this purpose).

Thus, my conclusion is to add/retrieve a rule to the automations.yaml from python.
Do you know if there is a “standard” approach or module to read/write yaml file from home assistant?

Thanks in advance