I am a bit of an amateur using Home Assistant but I understand the concepts and have had great help automising my home and keeping track of energy uses. Big shout out to all involved in developing this platform.
My issue to-day? In northern Europe the transition between day and night can be a drawn out process. Depending on various factors it can sometimes be quite dark an hour or so before sundown and sometimes the opposite. I wanted a system to turn on my house lighting at sundown but which would also take into consideration the ambient outdoor light value. I want the lights to be switched on during the period one hour prior to sundown and sundown if the light level is low and always at sundown irrespective. So I created three automations the first uses the ambient light value (measured in w/m2) and it triggers when the light value gets below 6 w/m2. I have used a template which gives a “True” result during the time period between 1 hour prior to sundown and sundown, finally various lights ar switched on and a notification is sent to my iPhone. I have also included a boolean switch which is set to “on” after the automation has run.
The second automation is triggered solely by sundown and switches on the same lights and also sends a notification to my iPhone. This automation checks that the boolean switch has status “Off” to ensure that the automation is not run incase the lights have already been switched on du to low ambient lighting.
I have in face a third automation which runs after sundown to reset the boolean switch to off in preparation for the following days activities.
My feeling is that although these automations work the whole process could be dealt with with a single automation and would be very grateful for all and any criticism and/or suggestions to optimize this routine
Automation controlled by ambient outdoor light:
alias: Switch on lights at sundown low light
description: >-
Turning on evening lights at sundown or up to 1 hour before if light is below
6 w/m2
trigger:
- platform: numeric_state
entity_id: sensor.lallerod_562_orust_solar_rad
below: 6
condition:
- condition: template
value_template: >
{% set sunset = state_attr('sun.sun', 'next_setting')|as_datetime|as_local
%} {{ sunset - timedelta(hours=1) < now() <= sunset }}
action:
- service: switch.turn_on
data: {}
target:
entity_id:
- switch.nisse_socket_1
- switch.parkeringen
- switch.fonsterbelysning
- switch.sonoff_1000ac5b30
- switch.v_rumlights_socket
- switch.houselights
- service: notify.mobile_app_peter_iphone_11
data:
message: >-
Solnedgång idag är
{{as_timestamp(state_attr('sun.sun','next_setting'))|timestamp_custom('%H:%M')}}
och dagsljus värdet är nu
{{states('sensor.lallerod_562_orust_solar_rad')}} w/m2. Skickat pga
ljusnivån <6 vid solnedgång oavsett ljusvärde. Tiden är
{{as_timestamp(now()) | timestamp_custom('%H:%M') }}
data:
push: null
sound: US-EN-Morgan-Freeman-Turning-On-The-Lights.wav
- service: input_boolean.turn_on
data: {}
target:
entity_id: input_boolean.evening_lights_switched_on
mode: single
Automation fired at sundown:
alias: Switch on lights at sundown
description: "Turning on evening lights at sundown "
trigger:
- platform: sun
event: sunset
offset: 0
condition:
- condition: state
entity_id: input_boolean.evening_lights_switched_on
state: "off"
action:
- service: switch.turn_on
data: {}
target:
entity_id:
- switch.nisse_socket_1
- switch.parkeringen
- switch.fonsterbelysning
- switch.sonoff_1000ac5b30
- switch.v_rumlights_socket
- switch.houselights
- service: notify.mobile_app_peter_iphone_11
data:
message: >-
Solnedgång idag är
{{as_timestamp(state_attr('sun.sun','next_setting'))|timestamp_custom('%H:%M')}}
och dagsljus värdet är nu
{{states('sensor.lallerod_562_orust_solar_rad')}} w/m2. Skickat pga
solnedgång oavsett ljusvärde. Tiden är
{{as_timestamp(now()) | timestamp_custom('%H:%M') }}
data:
push: null
sound: US-EN-Morgan-Freeman-Turning-On-The-Lights.wav
mode: single
Automation resetting boolean switch
alias: Resetting evening lights on switch
description: ""
trigger:
- platform: sun
event: sunset
offset: "+02:00:00"
condition: []
action:
- service: input_boolean.turn_off
data: {}
target:
entity_id: input_boolean.evening_lights_switched_on
mode: single
Look forward to reading your thoughts.