Skip to content

Powerful automatic light control for AppDaemon / Home Assistant

Notifications You must be signed in to change notification settings

melslenstra/autolight

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 

Repository files navigation

AutoLight

When you're automating your home or office, you'll often find you want to automate on/off control of light(s) based on one or more sensors, like motion sensors or door contacts.

With just one sensor, it's easy to write a native Home assistant automation to turn the light on and off. But when you want to use multiple door and motion sensors to control the state of one light, the automations start to become quite complex and repetetive. This AppDaemon app implements a configurable state machine that allows you to automate any number of lights based on the inputs from any number of different sensors.

Current features

  • Control any number of lights or other binary controllable entities
  • Use any combination of sensors to control the light:
    • Door sensors turn on the light when the door is opened, and immediately start a timer to turn off the light after a configured time period. This behavior works well with doors that are often left open for long periods of time, where you just want the door to serve as an instant trigger when you open it.
    • Closet door sensors are simpler: they turn on the light when the door is opened, and start the turn-off timer when closed. In combination with a delay_seconds value of 0, this makes the light turn on and off immediately when the door is opened or closed.
    • Motion sensors turn on the light when motion is detected. When motion is no longer detected on any of the connected sensors, the timer to turn off the light is started.
    • All sensors can be configured with a specific light sensor entity that gates the triggering of that sensor based on the local ambient light level. This can be useful if one light illuminates a large area and you want the sensor in a specific section to only trigger the light when that section is dark enough to need extra light.
  • Global light sensor: if you don't need specific light sensor configuration for each sensor, you can configure a global light sensor that is used to filter the triggers from all sensors.

Settings reference

Main app configuration

Parameter Required Description
module required Mandatory for AppDaemon. Set to "auto_light".
class required Mandatory for AppDaemon. Set to "AutoLight".
delay_seconds required The number of seconds to delay turning off the light after no more motion is detected on any sensor.
light_sensor optional Global light sensor configuration, see light sensor configuration section below. If omitted and also no sensor-specific light sensor is configured, the light will always trigger regardless of ambient light levels.
lights required List of light entities to control from this instance
sensors required List of sensors to connect to this instance. See sensor configuration section below

Sensor configuration

Parameter Required Description
entity_id required The entity ID of the sensor to use
type required The type of sensor (allowed values: "door" or "motion")
light_sensor optional The light sensor configuration to apply to this specific sensor. If omitted, global (app-level) light sensor configuration will be used.

Light sensor configuration

Parameter Required Description
entity_id required The entity ID of the light sensor to use
threshold required The light value threshold. The light will not trigger if the sensor reports a value above this threshold.

Configuration examples

Adjust these examples with your own preferences and add them to your AppDaemon apps.yaml configuration.

Simplest working instance

This is the minimum configuration. It controls a single light from a single motion sensor.

bathroom_light:
  module: auto_light
  class: AutoLight
  delay_seconds: 600
  lights:
    - entity_id: light.bathroom
  sensors: 
    - entity_id: binary_sensor.motion_sensor_bathroom
      type: motion

Multiple sensors

This example uses a motion sensor to trigger when someone walks into the bathroom (e.g. when the door was already open). When the door is opened, the door sensor triggers the light instantly.

bathroom_light:
  module: auto_light
  class: AutoLight
  delay_seconds: 600
  lights:
    - entity_id: light.bathroom
  sensors: 
    - entity_id: binary_sensor.motion_sensor_bathroom
      type: motion
    - entity_id: binary_sensor.door_window_sensor_bathroom_door
      type: door

Global light sensor threshold

This example uses a single global light sensor to control when the light can turn on. Only when the light level at the light sensor is lower than 10, will the light turn on.

bathroom_light:
  module: auto_light
  class: AutoLight
  delay_seconds: 600
  lights:
    - entity_id: light.bathroom
  light_sensor: 
    entity_id: sensor.illumination_bathroom
    threshold: 10
  sensors: 
    - entity_id: binary_sensor.motion_sensor_bathroom
      type: motion
    - entity_id: binary_sensor.door_window_sensor_bathroom_door
      type: door

Different light sensors for different sensors

In this example, a patio light is controlled by two motion sensors that each have their own corresponding light sensor with different thresholds. The porch motion sensor will only trigger when it's dark at the porch.

Note that the door sensor for the patio door has no configured light sensor. If a light sensor were configured on the global level, it would use that. Since that is not the case, the light will always turn on when the patio door is opened.

patio_light:
  module: auto_light
  class: AutoLight
  delay_seconds: 600
  lights:
    - entity_id: light.patio
  sensors: 
    - entity_id: binary_sensor.motion_sensor_porch
      type: motion
      light_sensor: 
        entity_id: sensor.illumination_porch
        threshold: 30
    - entity_id: binary_sensor.motion_sensor_patio_door
      type: motion
      light_sensor: 
        entity_id: sensor.illumination_patio_door
        threshold: 25
    - entity_id: binary_sensor.door_window_sensor_patio_door
      type: door

About

Powerful automatic light control for AppDaemon / Home Assistant

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages