home-assistant / home-assistant.io

:blue_book: Home Assistant User documentation
https://www.home-assistant.io
Other
5.04k stars 7.32k forks source link

User automation cookbook #61

Closed balloob closed 9 years ago

balloob commented 9 years ago

Automation component documentation will be revamped and put front and center in the getting started. I want to include a cookbook with awesome recipes for people to easily copy-paste-adjust. Please post your real life examples here and get some good ones!

For each automation you post, include a title and an optional description if a complex setup. It is okay to include configuration for scripts and scenes too.

I am looking for simple and complex examples!

Example:

Turn on the living room lights 45 minutes before sunset if anyone home

automation:
  trigger:
    platform: sun
    event: sunset
    offset: "-00:45:00"
  condition:
    platform: state
    entity_id: group.all_devices
    state: home
  action:
    service: homeassistant.turn_on
    entity_id: group.living_room_lights
balloob commented 9 years ago

Natural wake up light

Note, Philips Hue is currently the only light platform that support transitions.

automation:
  trigger:
    platform: time
    after: "07:15:00"
  action:
    service: light.turn_on
    entity_id: light.bedroom
    data:
      # 900 seconds = 15 minutes
      transition: 900
CCOSTAN commented 9 years ago

RE: https://github.com/balloob/home-assistant.io/issues/61#issuecomment-141684477

@balloob, I agree - Deleted the future recipe. Will keep this one for verified working recipes.

stefan-jonasson commented 9 years ago

Turn on lights with a resettable off timer

This recipe will turn on a light when there is motion and turn off the light when ten minutes has passed without any motion events .

automation:
  alias: Turn on kitchen lights when there is movement 
  trigger:
    - platform: state
      entity_id: sensor.motion_sensor
      to: 'on'
  action:
    service: homeassistant.turn_on
    entity_id: script.timed_lamp

script:
  timed_lamp:
    alias: "Turn on lamp and set timer"
    sequence:
      # Cancel ev. old timers 
      - execute_service: script.turn_off
        service_data: 
           entity_id: script.timer_off
      - execute_service: light.turn_on
        service_data:
          entity_id: light.kitchen
      # Set new timer 
      - execute_service: script.turn_on
        service_data:
          entity_id: script.timer_off

  timer_off:
    alias: "Turn off lamp after 10 minutes"
    sequence:
      - delay:
          minutes: 10
      - execute_service: light.turn_off
        service_data: 
          entity_id: light.kitchen
stefan-jonasson commented 9 years ago

Last recipe requires PR #403 to be merged to it to work

stefan-jonasson commented 9 years ago

Basic example for use_trigger_values

Turn on lights during daytime when it's dark enough < 200 lux.

automation:
  - alias: 
    trigger:
      - platform: numeric_state
        entity_id: sensor.sensor_luminance
        below: 200
      - platform: time
        after: "08:00"
        before: "23:00"
    condition: use_trigger_values
    action:
      service: homeassistant.turn_on
      entity_id: group.basic_lights

automation 2:
  - alias: 
    trigger:
      - platform: numeric_state
        entity_id: sensor.sensor_luminance
        above: 200
      - platform: time
        after: "23:00"
    action:
      service: homeassistant.turn_off
      entity_id: group.basic_lights
balloob commented 9 years ago

@CCOSTAN this issue is only for recipes that already work, not for feature requests

CCOSTAN commented 9 years ago

Rainy Day Light This requires the forecast.io component to be loaded and uses the sensor weather_precip to tell if it's raining.

Turn on a light in the living room when it starts raining, someone is home and it's afternoon or later.

automation:
  alias: 'Rainy Day'

  trigger:
       - platform: state
         entity_id: sensor.weather_precip
         state: 'rain'
       - platform: state
         entity_id: group.all_devices
         state: 'home'
       - platform: time
         after: '14:00'
         before: '23:00'

  condition: use_trigger_values

  action:
    execute_service: light.turn_on
    service_entity_id: light.couch_lamp

And then of course turn off the lamp when it stops raining but only if it's within an hour before sunset.

  alias: 'Rain is over'
  trigger:
       - platform: state
         entity_id: sensor.weather_precip
         state: 'None'
       - platform: sun
         event: 'sunset'
         offset: '-01:00:00'

  condition: use_trigger_values
  action:
    execute_service: light.turn_off
    service_entity_id: light.couch_lamp
CCOSTAN commented 9 years ago

Entry way light when you get home

Uses the presence awareness to turn on a house light if it's nighttime but only during reasonable hours'. (to guard against iPhones dropping on/off wifi in the middle of the night)

  alias: 'Kitchen Light Helper'

  trigger:
   - platform: state
     entity_id: group.all_devices
     state: 'home'

  condition:
   - platform: state
     entity_id: group.all_devices
     state: 'home'
   - platform: state
     entity_id: sun.sun
     state: 'below_horizon'
   - platform: time
     after: '16:00'
     before: '00:00'

  action:
     service: light.turn_on
     entity_id: light.fan_bulb_1
gartkb commented 9 years ago

Light slow-brightness alarm

This script and trigger produce a sequence of brightness increases 3 minutes apart. This approximates a slowly brightening light alarm. If more divisions are required simply duplicate the last section and iterate the values. Actual results will be far better with ~ 10 divisions.

This awkward method is required since currently there is no way to use "transition" property for wink or bulbs other than hue.

automation:
  alias: wakeup alarm trigger
  trigger:
    - platform: time
      after: "07:30"    
  action:
    service: script.turn_on
    entity_id: script.wakeup  

script:
   wakeup:
     alias: Wake Up
     sequence:
       - alias: Bedroom Alarm 1
         execute_service: light.turn_on
         service_data:
           entity_id: light.bedroom
           brightness: 10 
       - delay:
           minutes: 3

       - alias: Bedroom Alarm 2
         execute_service: light.turn_on
         service_data:
           entity_id: light.bedroom
           brightness: 80 
       - delay:
           minutes: 3

       - alias: Bedroom Alarm 3
         execute_service: light.turn_on
         service_data:
           entity_id: light.bedroom
           brightness: 150 
       - delay:
           minutes: 3
gartkb commented 9 years ago

Automatic dim level based on time of day respecting lights that are off This switches the dim level if a light is on when the threshold time is crossed, but also automatically changes the dim level when a light goes from off to on. Importantly, if lights are off, they stay off.

automation 4:
  alias: "Set dim level daytime"
  trigger:
  - platform: time
    after: "07:00"   #instantaneously at 7am only, not 'after'
  - platform: state   #implicit OR betwen the two conditions
    entity_id: light.kitchen
    from: 'off'
    to: 'on'

  condition:
  - platform: state
    entity_id: light.kitchen
    state: 'on'
  - platform: time    #implicit AND
    after: "07:00"
    before: "19:59"

  action:
    service: light.turn_on
    entity_id: light.kitchen
    data:
      brightness: 255
kwetiaw commented 9 years ago

Hi all, Love HASS!

I wish there's a button that you can activate to trigger an adjustable timer that will kick off based on time selection. Like an alarm clock that trigger a switch at a given time and day. Preferably that can be adjusted via HASS web interface.

For example in my case I can turn on my washing machine automatically via RF 433mhz switch (i loaded the dirty clothes and the detergent the night before I go to sleep) and in the morning when I wake up I switch it on, by the time I have breakfast and coffee, the laundry is done and I just take it out and hang them up. Unfortunately, if I overslept and the button didnt get activated, I will miss the wash.

Cheers!!!