|
| 1 | +--- |
| 2 | +layout: page |
| 3 | +title: "Examples using first light" |
| 4 | +description: "Automation examples that trigger lights in the morning." |
| 5 | +date: 2016-10-08 19:05 |
| 6 | +sidebar: true |
| 7 | +comments: false |
| 8 | +sharing: true |
| 9 | +footer: true |
| 10 | +ha_category: Automation Examples |
| 11 | +--- |
| 12 | + |
| 13 | +#### {% linkable_title Create an input_boolean in your configuration.yaml %} |
| 14 | + |
| 15 | +```yaml |
| 16 | +input_boolean: |
| 17 | + trigger_first_morning: |
| 18 | + name: Waiting for first morning motion |
| 19 | + icon: mdi:kettle |
| 20 | +``` |
| 21 | + |
| 22 | +#### {% linkable_title The Main Automation %} |
| 23 | + |
| 24 | +```yaml |
| 25 | +## These first two control t input_boolean that allows the "first morning action" to occur |
| 26 | +## If the action is triggered, it will also disable this boolean. This assumes you have the sun platform enabled. |
| 27 | + |
| 28 | +automation: |
| 29 | +#turns it on at 5am |
| 30 | + - alias: Enable First Morning Trigger |
| 31 | + trigger: |
| 32 | + - platform: time |
| 33 | + after: '5:00' |
| 34 | + action: |
| 35 | + service: homeassistant.turn_on |
| 36 | + entity_id: input_boolean.trigger_first_morning |
| 37 | + |
| 38 | +# turns it off an hour after sunrise |
| 39 | + - alias: Disable First Morning Trigger |
| 40 | + trigger: |
| 41 | + - platform: sun |
| 42 | + event: sunrise |
| 43 | + offset: "01:00:00" |
| 44 | + action: |
| 45 | + service: homeassistant.turn_off |
| 46 | + entity_id: input_boolean.trigger_first_morning |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | +# This is the main automation. It triggers when my motion sensor is triggered |
| 51 | +# (in this case, a motion sensor from a security system attached to my Vera) |
| 52 | + - alias: First Morning Motion |
| 53 | + trigger: |
| 54 | + platform: state |
| 55 | + entity_id: binary_sensor.livingroom_motion |
| 56 | + to: 'on' |
| 57 | + # only complete the automation if we're still waiting for the first motion |
| 58 | + condition: |
| 59 | + condition: state |
| 60 | + entity_id: input_boolean.trigger_first_morning |
| 61 | + state: 'on' |
| 62 | + |
| 63 | + action: |
| 64 | + # turn off the "waiting" boolean regardless of whether lights will turn on |
| 65 | + # so that this happens only once |
| 66 | + - service: homeassistant.turn_off |
| 67 | + entity_id: input_boolean.trigger_first_morning |
| 68 | + |
| 69 | + # But only turn on lights if the living room and kitchen lights are off or dimmed |
| 70 | + # If a condition tests false, the automation will end |
| 71 | + - condition: and |
| 72 | + conditions: |
| 73 | + - condition: numeric_state |
| 74 | + entity_id: light.livingroom_ec |
| 75 | + # if light is off, force a 0, otherwise use the brightness value |
| 76 | + value_template: {% raw %}'{% if states.light.livingroom_ec.state == "on" %}{{ states.light.livingroom_ec.attributes.brightness }}{% else %}0{% endif %}'{% endraw %} |
| 77 | + # brightness below 50% (255 = 100%) |
| 78 | + below: 127 |
| 79 | + - condition: numeric_state |
| 80 | + entity_id: light.kitchen_bar |
| 81 | + value_template: {% raw %}'{% if states.light.kitchen_bar.state == "on" %}{{ states.light.kitchen_bar.attributes.brightness }}{% else %}0{% endif %}'{% endraw %} |
| 82 | + below: 127 |
| 83 | + - condition: numeric_state |
| 84 | + entity_id: light.kitchen_ceiling |
| 85 | + value_template: {% raw %}'{% if states.light.kitchen_ceiling.state == "on" %}{{ states.light.kitchen_ceiling.attributes.brightness }}{% else %}0{% endif %}'{% endraw %} |
| 86 | + below: 127 |
| 87 | + |
| 88 | + # Trigger a scene |
| 89 | + # You could add as many services or scenes as you'd like |
| 90 | + - service: scene.turn_on |
| 91 | + entity_id: scene.morning_first_motion |
| 92 | + |
| 93 | + |
| 94 | +``` |
| 95 | + |
| 96 | +#### {% linkable_title The Scene %} |
| 97 | + |
| 98 | +Here is the Scene that is called via the Automations above. |
| 99 | + |
| 100 | +```yaml |
| 101 | +# here's the scene that gets called. Lights in |
| 102 | +# my living room and kitchen turn on. |
| 103 | +scene: |
| 104 | + - name: Morning First Motion |
| 105 | + entities: |
| 106 | + light.kitchen_ceiling: |
| 107 | + state: on |
| 108 | + brightness: 127 |
| 109 | + light.kitchen_bar: |
| 110 | + state: on |
| 111 | + brightness: 178 |
| 112 | + light.kitchen_above_cabinet: |
| 113 | + state: on |
| 114 | + brightness: 178 |
| 115 | + light.livingroom_ec: |
| 116 | + state: on |
| 117 | + brightness: 153 |
| 118 | + light.livingroom_track: |
| 119 | + state: on |
| 120 | + brightness: 153 |
| 121 | +``` |
0 commit comments