Skip to content

Factory Automations

Leonard Sperry edited this page Feb 23, 2024 · 4 revisions

This page covers pre-built automations exposed by IAutomationFactory

Aside from the sun automations, the IAutomationFactory also exposes three other types of pre-built automation.

    ConditionalAutomation EntityAutoOff(string entity_id, TimeSpan timeToLeaveOn);
    ConditionalAutomation EntityAutoOff(string entity_id, int minutes);
    LightOnMotionAutomation LightOnMotion(string motionId, string lightId);
    LightOnMotionAutomation LightOnMotion(IEnumerable<string> motionId, IEnumerable<string> lightId);
    LightOffOnNoMotion LightOffOnNoMotion(string motionId, string lightId, TimeSpan duration);
    LightOffOnNoMotion LightOffOnNoMotion(IEnumerable<string> motionIds, IEnumerable<string> lightIds, TimeSpan duration);
    SchedulableAutomation DurableAutoOn(string entityId, TimeSpan timeToLeaveOff);
    SchedulableAutomation DurableAutoOff(string entityId, TimeSpan timeToLeaveOn);
    SchedulableAutomation DurableAutoOffOnEntityOff(string entityToTurnOff, string triggerEntity, TimeSpan timeToLeaveOn);

EntityAutoOff

This automation will turn entities off automatically after they turn on. There is no conditional way to prevent it turning off aside from disabling it in the dashboard or turning off the entity yourself. It can be used with any entity supporting On/Off states such as lights, switches, smart plugs, and more.

LightOnMotion

The first parameter is for motion/presence detectors or any entity exposing On/Off behavior. The second is for any lights/switches/etc. that you want to turn on when an entity from the first parameter reports "on".

LightOffOnNoMotion

The counterpart to LightOnMotion which behaves similarly in regards to the first and second parameters.

Durable automations

Durable automations will survive restarts. The DurableAutoOffOnEntityOff method is same as LightOffOnNoMotion except that it is durable and named more appropriately to its function. To turn a light off after not motion is detected, you would write this:

    _factory.DurableAutoOffOnEntityOff(
        "light.my_light", "binary_sensor.my_motion_sensor", 
        TimeSpan.FromMinutes(5));