|
| 1 | +# adapted from https://github.com/iainsmacleod/Home-Assistant-Blueprints |
| 2 | +blueprint: |
| 3 | + name: Motion- or sensor- activated light with brightness and temperature |
| 4 | + description: Turn on lights when motion is detected, with brightness and temperature depending on sunrise/sunset (with offsets). |
| 5 | + domain: automation |
| 6 | + input: |
| 7 | + motion_sensors: |
| 8 | + name: Motion and Occupancy Sensors |
| 9 | + description: Select one or more motion or occupancy sensors. |
| 10 | + selector: |
| 11 | + entity: |
| 12 | + domain: binary_sensor |
| 13 | + device_class: |
| 14 | + - motion |
| 15 | + - occupancy |
| 16 | + - door |
| 17 | + multiple: true |
| 18 | + entity_target: |
| 19 | + name: Lights and Switches |
| 20 | + description: Select one or more lights or switches to control. |
| 21 | + selector: |
| 22 | + target: |
| 23 | + entity: |
| 24 | + domain: |
| 25 | + - light |
| 26 | + - switch |
| 27 | + no_motion_wait: |
| 28 | + name: Wait Time |
| 29 | + description: Time to leave the light on after last motion is detected. |
| 30 | + default: 120 |
| 31 | + selector: |
| 32 | + number: |
| 33 | + min: 0 |
| 34 | + max: 3600 |
| 35 | + unit_of_measurement: seconds |
| 36 | + use_custom_settings: |
| 37 | + name: Use Changing Brightness and Temperature |
| 38 | + description: Enable to use brightness and temperature settings based on surrounding lights and light level. |
| 39 | + default: true |
| 40 | + selector: |
| 41 | + boolean: |
| 42 | + brightness_bright: |
| 43 | + name: Brightness (bright setting) |
| 44 | + description: Set the brightness level (0-255) used when high brightness is set. |
| 45 | + default: 255 |
| 46 | + selector: |
| 47 | + number: |
| 48 | + min: 0 |
| 49 | + max: 255 |
| 50 | + brightness_dim: |
| 51 | + name: Brightness (dim setting) |
| 52 | + description: Set the brightness level (0-255) used when low brightness is set. |
| 53 | + default: 150 |
| 54 | + selector: |
| 55 | + number: |
| 56 | + min: 0 |
| 57 | + max: 255 |
| 58 | + sun_offset_brightness: |
| 59 | + name: Sun Offset for Brightness (Optional) |
| 60 | + description: Offset from sunrise/sunset in format 'HH:MM' (e.g., '01:00' or '-01:00') at which light brightness reduces. |
| 61 | + default: "00:00" |
| 62 | + selector: |
| 63 | + text: |
| 64 | + temperature_cool: |
| 65 | + name: Cool temperature |
| 66 | + description: A cooler colour temperature, used during the day. |
| 67 | + default: 250 |
| 68 | + selector: |
| 69 | + number: |
| 70 | + min: 1.0 |
| 71 | + max: 600.0 |
| 72 | + step: 1.0 |
| 73 | + mode: slider |
| 74 | + temperature_warm: |
| 75 | + name: Warm temperature |
| 76 | + description: A warmer colour temperature, used at night. |
| 77 | + default: 375 |
| 78 | + selector: |
| 79 | + number: |
| 80 | + min: 1.0 |
| 81 | + max: 600.0 |
| 82 | + step: 1.0 |
| 83 | + mode: slider |
| 84 | + sun_offset_temperature: |
| 85 | + name: Sun Offset for Temperature (Optional) |
| 86 | + description: Offset from sunrise/sunset in format 'HH:MM' (e.g. '01:00' or '-01:00') at which light temperature turns warm. |
| 87 | + default: "00:00" |
| 88 | + selector: |
| 89 | + text: |
| 90 | + |
| 91 | +mode: restart |
| 92 | +max_exceeded: silent |
| 93 | + |
| 94 | +trigger: |
| 95 | + - platform: state |
| 96 | + entity_id: !input motion_sensors |
| 97 | + to: "on" |
| 98 | + |
| 99 | +variables: |
| 100 | + use_custom_settings: !input use_custom_settings |
| 101 | + entity_target: !input entity_target |
| 102 | + |
| 103 | +action: |
| 104 | + - choose: |
| 105 | + - conditions: |
| 106 | + - condition: template |
| 107 | + value_template: "{{ use_custom_settings }}" |
| 108 | + sequence: |
| 109 | + - choose: |
| 110 | + - conditions: |
| 111 | + - condition: template |
| 112 | + value_template: "{{ 'light.' in entity_target.entity_id|string }}" |
| 113 | + sequence: |
| 114 | + |
| 115 | + - if: |
| 116 | + - condition: sun |
| 117 | + after: sunrise |
| 118 | + after_offset: !input sun_offset_brightness |
| 119 | + before: sunset |
| 120 | + before_offset: !input sun_offset_brightness |
| 121 | + then: |
| 122 | + - variables: |
| 123 | + brightness: !input brightness_bright |
| 124 | + else: |
| 125 | + - variables: |
| 126 | + brightness: !input brightness_dim |
| 127 | + - if: |
| 128 | + - condition: sun |
| 129 | + after: sunrise |
| 130 | + after_offset: !input sun_offset_temperature |
| 131 | + before: sunset |
| 132 | + before_offset: !input sun_offset_temperature |
| 133 | + then: |
| 134 | + - variables: |
| 135 | + temperature: !input temperature_cool |
| 136 | + else: |
| 137 | + - variables: |
| 138 | + temperature: !input temperature_warm |
| 139 | + |
| 140 | + - service: light.turn_on |
| 141 | + target: !input entity_target |
| 142 | + data: |
| 143 | + brightness: "{{ brightness }}" |
| 144 | + color_temp: "{{ temperature }}" |
| 145 | + - conditions: |
| 146 | + - condition: template |
| 147 | + value_template: "{{ 'switch.' in entity_target.entity_id|string }}" |
| 148 | + sequence: |
| 149 | + - service: switch.turn_on |
| 150 | + target: !input entity_target |
| 151 | + default: |
| 152 | + - choose: |
| 153 | + - conditions: |
| 154 | + - condition: template |
| 155 | + value_template: "{{ 'light.' in entity_target.entity_id|string }}" |
| 156 | + sequence: |
| 157 | + - service: light.turn_on |
| 158 | + target: !input entity_target |
| 159 | + - conditions: |
| 160 | + - condition: template |
| 161 | + value_template: "{{ 'switch.' in entity_target.entity_id|string }}" |
| 162 | + sequence: |
| 163 | + - service: switch.turn_on |
| 164 | + target: !input entity_target |
| 165 | + - wait_for_trigger: |
| 166 | + platform: state |
| 167 | + entity_id: !input motion_sensors |
| 168 | + to: "off" |
| 169 | + - delay: !input no_motion_wait |
| 170 | + - choose: |
| 171 | + - conditions: |
| 172 | + - condition: template |
| 173 | + value_template: "{{ 'light.' in entity_target.entity_id|string }}" |
| 174 | + sequence: |
| 175 | + - service: light.turn_off |
| 176 | + target: !input entity_target |
| 177 | + - conditions: |
| 178 | + - condition: template |
| 179 | + value_template: "{{ 'switch.' in entity_target.entity_id|string }}" |
| 180 | + sequence: |
| 181 | + - service: switch.turn_off |
| 182 | + target: !input entity_target |
0 commit comments