Need Lights
Home Assistant Automation
Automation to set a Input Boolean based on the sun elevation and light readings. The boolean can then be used in all motion triggered lighting automations allowing easy update of settings as requirements change.
Requires to be set up in Configuration Helpers:
- Input Boolean
- Input Number for each Sensor, if you want to be able to adjust from the UI


Averaging Sensor Readings
Experience found that light readings can vary a great deal so to stabilise the reading, a sensor which averages the last twenty minutes improved the reading.

sensor: - platform: statistics name: piz_average_light entity_id: sensor.pizlivingroom_lux sampling_size: 5 max_age: minutes: 20
Automation
alias: Do We Need Lights? description: '' trigger: - platform: state entity_id: sensor.sun_elevation - platform: state entity_id: input_number.min_light_level - platform: state entity_id: sensor.study_illuminance - platform: state entity_id: sensor.lumi_living_room_illuminance - platform: state entity_id: input_number.min_living_room_light_level condition: [] action: - choose: - conditions: - condition: or conditions: - condition: template value_template: >- {{states.sensor.study_illuminance.state|float < states.input_number.min_light_level.state | float}} - condition: template value_template: '{{state_attr(''sun.sun'', ''elevation'')|float < 4}}' - condition: template value_template: >- {% set excess = 0 %} {% if states.light.wall1.state == 'on' %} {% set excess = 15 %} {% endif %} {% set brightness = states('sensor.lumi_living_room_illuminance')|float %} {% set min = states('input_number.min_living_room_light_level')|float %} {% set level = brightness - excess %} {{level < states.input_number.min_living_room_light_level | float}} sequence: - service: input_boolean.turn_on data: {} entity_id: input_boolean.need_lights default: - service: input_boolean.turn_off data: {} entity_id: input_boolean.need_lights mode: single