Hi, i am currently trying to find a (nearly) perfect automation for my motion activated lights.
I only want the automation to get triggered when its dark (or when i really need some lighting)
I have some aqara, hue und ikea motion sensors. Aqara und Hue have an illuminance sensor so this could be a thing. But i’m confused with a illuminance sensor which triggers a light in the same room. Will all automations still work?
Ikea has no illuminance so i need some tips if i need to stick with the built in illuminance sensors.
Here is my automation for a light. The illuminance condition should be only for turning on, but not for turning off otherwise the light will never be turned off because its lighter in my room?
alias: Flur Licht Motion
trigger:
- platform: state
entity_id: binary_sensor.motion_flur_presenz
from: 'off'
to: 'on'
id: 'on'
- platform: state
entity_id: binary_sensor.motion_flur_presenz
from: 'on'
to: 'off'
for: '00:00:30'
id: off_30
- platform: state
entity_id: binary_sensor.motion_flur_presenz
from: 'on'
to: 'off'
for: '00:01:30'
id: off_50
condition:
- condition: or
conditions:
- condition: numeric_state
entity_id: sensor.sunlight_pct
below: '20'
action:
- variables:
entity: light.extended_color_light_1_2
light_on: '{{ is_state(entity, ''on'') }}'
- choose:
- conditions:
- condition: template
value_template: '{{ trigger.id == ''on''}}'
sequence:
- service: light.turn_on
target:
entity_id: '{{ entity }}'
data:
brightness_pct: 75
- conditions:
- condition: template
value_template: '{{ trigger.id == ''off_30'' and light_on }}'
sequence:
- service: light.turn_on
target:
entity_id: '{{ entity }}'
data:
brightness_pct: 25
- conditions:
- condition: template
value_template: '{{ trigger.id == ''off_50'' and light_on }}'
sequence:
- service: light.turn_off
target:
entity_id: '{{ entity }}'
default: []
mode: single
I also tried to get a dark outside template with these templates:
- platform: template
sensors:
dark_outside:
value_template: >-
{%- if (states.sun.sun.attributes.elevation | int < 7.5 ) -%}
True
{%- elif ( (states.sun.sun.attributes.elevation | int < 25) and (states.sensor.openweathermap_cloud_coverage.state | int > 70)) -%}
True
{%- elif (states.sensor.openweathermap_cloud_coverage.state | int > 95) -%}
True
{%- else -%}
False
{%- endif -%}
and
- platform: template
sensors:
## Calculates daylight brightness out of 100%
sunlight_pct:
value_template: >-
{%- set elevation = state_attr('sun.sun','elevation') | float %}
{%- set cloud_coverage = states('sensor.openweathermap_cloud_coverage') | float %}
{%- set cloud_factor = (1 - (0.75 * ( cloud_coverage / 100) ** 3 )) %}
{%- set min_elevation = -12 %}
{%- set max_elevation = 60 %}
{%- set adjusted_elevation = elevation - min_elevation %}
{%- set adjusted_elevation = [adjusted_elevation,0] | max %}
{%- set adjusted_elevation = [adjusted_elevation,max_elevation - min_elevation] | min %}
{%- set adjusted_elevation = adjusted_elevation / (max_elevation - min_elevation) %}
{%- set adjusted_elevation = adjusted_elevation %}
{%- set adjusted_elevation = adjusted_elevation * 100 %}
{%- set brightness = adjusted_elevation * cloud_factor %}
{{ brightness | round }}
unit_of_measurement: '%'
device_class: 'illuminance'
## Daylight brightness converted to opacity for CSS
sunlight_opacity:
value_template: >-
{%- set sunpct = states('sensor.sunlight_pct') | float %}
{%- set opacity = sunpct / 100 | float %}
{{ opacity }}
But this is not as i need it. I think its a bit dark in my apartment. One site has a tree infront. So one site is brighter than ther other. I currently trigger the light with an offset after sunrise and before sunset.
The automation should work in summer and winter.
Do you have any tips? How other guys are handling with this? What would the best option to have a sensor/entity to know if its dark?