Okay, as promised : -
Notes,
- the day segments are basically repeated code to ensure they never clash (I’ll combine these into one sensor, when I can be bothered)
- the ‘groups’ are just lists of light (I like to see what I’m working with and can move them easily (cut/paste & reload)
homeassistant:
customize:
input_number.in_aalight_day:
unit_of_measurement: '°'
input_number.in_aalight_evening:
unit_of_measurement: '°'
binary_sensor:
- platform: template
sensors:
## day segment bs
bs_light_day:
entity_id: sensor.time
value_template: >
{% set rising = state_attr('sun.sun', 'rising') %}
{% set elevation = state_attr('sun.sun', 'elevation') | float %}
{% set daystart = states('input_number.in_aalight_day') | float %}
{% set eveningstart = states('input_number.in_aalight_evening') | float %}
{% set day = (rising and elevation > daystart) or (not rising and elevation > eveningstart) %}
{{ day }}
friendly_name: Day Lights
icon_template: "{{ 'mdi:white-balance-sunny' }}"
## evening segment bs
bs_light_evening:
entity_id: sensor.time
value_template: >
{% set time = states('sensor.time') %}
{% set rising = state_attr('sun.sun', 'rising') %}
{% set elevation = state_attr('sun.sun', 'elevation') | float %}
{% set daystart = states('input_number.in_aalight_day') | float %}
{% set eveningstart = states('input_number.in_aalight_evening') | float %}
{% set nightstart = states('input_datetime.id_aalight_night') [0:5] %}
{% set nightstart = '23:59' if nightstart == '00:00' else nightstart %}
{% set day = (rising and elevation > daystart) or (not rising and elevation > eveningstart) %}
{% if '12:00' < nightstart <= '24:00' %}
{% set r1 = time >= nightstart %}
{% set r2 = elevation <= daystart and time < '12:00'%}
{% else %}
{% set r1 = false %}
{% set r2 = elevation <= daystart and time >= nightstart %}
{% endif %}
{% set night = r1 or r2 %}
{% set evening = not (day or night) %}
{{ evening }}
friendly_name: Evening Lights
icon_template: "{{ 'mdi:weather-sunset-down' }}"
## night segment bs
bs_light_night:
entity_id: sensor.time, binary_sensor.bs_light_day, binary_sensor.bs_light_evening
value_template: >
{% set time = states('sensor.time') %}
{% set elevation = state_attr('sun.sun', 'elevation') | float %}
{% set daystart = states('input_number.in_aalight_day') | float %}
{% set nightstart = states('input_datetime.id_aalight_night') [0:5] %}
{% set nightstart = '23:59' if nightstart == '00:00' else nightstart %}
{% if '12:00' < nightstart <= '24:00' %}
{% set r1 = time >= nightstart %}
{% set r2 = elevation <= daystart and time < '12:00'%}
{% else %}
{% set r1 = false %}
{% set r2 = elevation <= daystart and time >= nightstart %}
{% endif %}
{% set night = r1 or r2 %}
{{ night }}
friendly_name: Night Lights
icon_template: "{{ 'mdi:weather-night' }}"
## night slot for external lights
bs_aalight_extlights_nightslot:
entity_id: sensor.time
value_template: >
{% set elevation = state_attr('sun.sun', 'elevation') | float %}
{% set nightstart = states('input_number.in_light_flood_on_elev_offset') | float %}
{% set nightstop = states('input_number.in_light_flood_off_elev_offset') | float %}
{{ elevation <= nightstart and not rising or elevation <= nightstop and rising }}
friendly_name: External Light Night Slot
icon_template: "{{ 'mdi:weather-night' }}"
#### end of template stuff
input_boolean:
ib_aalight_transition_enable:
name: Segment Transition Enable
#initial: off
icon: mdi:power
ib_aalight_stop_adjust:
name: Stop Level Adjustment
initial: off
icon: mdi:lightbulb-off
input_datetime:
id_aalight_night:
name: Night Transition (time)
has_time: true
#initial: 0
icon: mdi:transition
input_number:
in_aalight_normal_transition:
name: Normal Transition Time (s)
#initial: 0
min: 1
max: 10
step: 1
mode: box
icon: mdi:transition
in_aalight_segment_transition:
name: Segment Transition Time (s)
#initial: 0
min: 1
max: 200
step: 1
mode: box
icon: mdi:transition
in_aalight_all_lvl:
name: All Remaining Level
#initial: 0
min: 1
max: 100
step: 1
#mode: box
icon: mdi:numeric
in_aalight_all_dlvl:
name: All Remaining Day Level
#initial: 0
min: 1
max: 100
step: 1
mode: box
icon: mdi:numeric
in_aalight_all_elvl:
name: All Remaining Evening Level
#initial: 0
min: 1
max: 100
step: 1
mode: box
icon: mdi:numeric
in_aalight_all_nlvl:
name: All Remaining Night Level
#initial: 0
min: 1
max: 100
step: 1
mode: box
icon: mdi:numeric
in_aalight_bed4_lvl:
name: Bed 4 Level
#initial: 0
min: 1
max: 100
step: 1
#mode: box
icon: mdi:numeric
in_aalight_bth_lvl:
name: Bath Room Level
#initial: 0
min: 1
max: 100
step: 1
#mode: box
icon: mdi:numeric
in_aalight_bth_dlvl:
name: Bath Room Day Level
#initial: 0
min: 1
max: 100
step: 1
mode: box
icon: mdi:numeric
in_aalight_bth_elvl:
name: Bath Room Evening Level
#initial: 0
min: 1
max: 100
step: 1
mode: box
icon: mdi:numeric
in_aalight_bth_nlvl:
name: Bath Room Night Level
#initial: 0
min: 1
max: 100
step: 1
mode: box
icon: mdi:numeric
in_aalight_out_lvl:
name: Outside Level
#initial: 0
min: 1
max: 100
step: 1
#mode: box
icon: mdi:numeric
in_aalight_out_alvl:
name: Outside Level All Segments
#initial: 0
min: 1
max: 100
step: 1
mode: box
icon: mdi:numeric
in_aalight_day:
name: Day Transition (horizon ° offset)
#initial: 0
min: -12
max: 12
step: 0.1
mode: box
icon: mdi:transition
in_aalight_evening:
name: Evening Transition (horizon ° offset)
#initial: 0
min: -12
max: 12
step: 0.1
mode: box
icon: mdi:transition
in_aalight_kit_lvl:
name: Kitchen Level
#initial: 0
min: 1
max: 100
step: 1
#mode: box
icon: mdi:numeric
in_aalight_kit_dlvl:
name: Kitchen Day Level
#initial: 0
min: 1
max: 100
step: 1
mode: box
icon: mdi:numeric
in_aalight_kit_elvl:
name: Kitchen Evening Level
#initial: 0
min: 1
max: 100
step: 1
mode: box
icon: mdi:numeric
in_aalight_kit_nlvl:
name: Kitchen Night Level
#initial: 0
min: 1
max: 100
step: 1
mode: box
icon: mdi:numeric
input_select:
is_aalight_segment:
name: Light Level Selector
options:
- Day
- Evening
- Night
automation:
#name: Check Light 'Just' Switched OFF
- alias: au_aalight_light_swoff_que
trigger:
- platform: state
entity_id: light.fibdim2_kitf_level, light.fibdim2_kitr_level, light.fibdim2_bath_level, light.fibdim2_ensu_level, light.fibdim2_wc_level, light.fibdim2_bed4_level, light.fibdim2_bed1_level, light.fibdim2_bed2_level, light.fibdim2_bed3_level, light.fibdim2_frtr_level, light.fibdim2_hall_level, light.fibdim2_ldg1_level, light.fibdim2_ldg2_level, light.fibdim2_lvgr_level, light.fibdim2_ptio_level, light.fibdim2_prch_level, light.fibdim2_lmp1_level
from: 'on'
to: 'off'
action:
- service: input_boolean.turn_on
entity_id: input_boolean.ib_aalight_stop_adjust
- delay: "00:00:05"
- service: input_boolean.turn_off
entity_id: input_boolean.ib_aalight_stop_adjust
#name: Light Transition To Day
- alias: au_aalight_to_day
trigger:
- platform: state
entity_id: binary_sensor.bs_light_day
to: 'on'
condition:
- condition: state
entity_id: input_boolean.ib_aalight_transition_enable
state: 'on'
action:
- service: input_select.select_option
data:
entity_id: input_select.is_aalight_segment
option: 'Day'
#name: Light Transition To Evening
- alias: au_aalights_to_evening
trigger:
- platform: state
entity_id: binary_sensor.bs_light_evening
to: 'on'
condition:
- condition: state
entity_id: input_boolean.ib_aalight_transition_enable
state: 'on'
action:
- service: input_select.select_option
data:
entity_id: input_select.is_aalight_segment
option: 'Evening'
#name: Light Transition To Night
- alias: au_aalights_to_night
trigger:
- platform: state
entity_id: binary_sensor.bs_light_night
to: 'on'
condition:
- condition: state
entity_id: input_boolean.ib_aalight_transition_enable
state: 'on'
action:
- service: input_select.select_option
data:
entity_id: input_select.is_aalight_segment
option: 'Night'
#name: Light Day Segment
- alias: au_aalight_dayseg
trigger:
- platform: state
entity_id: input_select.is_aalight_segment
to: 'Day'
action:
- service: input_number.set_value
data_template:
entity_id: input_number.in_aalight_kit_lvl
value: "{{ states('input_number.in_aalight_kit_dlvl') | int }}"
- service: input_number.set_value
data_template:
entity_id: input_number.in_aalight_bth_lvl
value: "{{ states('input_number.in_aalight_bth_dlvl') | int }}"
- service: input_number.set_value
data_template:
entity_id: input_number.in_aalight_all_lvl
value: "{{ states('input_number.in_aalight_all_dlvl') | int }}"
- service: input_number.set_value
data_template:
entity_id: input_number.in_aalight_out_lvl
value: "{{ states('input_number.in_aalight_out_alvl') | int }}"
- service: input_number.set_value
data_template:
entity_id: input_number.in_aalight_bed4_lvl
value: "{{ states('input_number.in_aalight_bed4_alvl') | int }}"
#name: Light Evening Segment
- alias: au_aalight_eveseg
trigger:
- platform: state
entity_id: input_select.is_aalight_segment
to: 'Evening'
action:
- service: input_number.set_value
data_template:
entity_id: input_number.in_aalight_kit_lvl
value: "{{ states('input_number.in_aalight_kit_elvl') | int }}"
- service: input_number.set_value
data_template:
entity_id: input_number.in_aalight_bth_lvl
value: "{{ states('input_number.in_aalight_bth_elvl') | int }}"
- service: input_number.set_value
data_template:
entity_id: input_number.in_aalight_all_lvl
value: "{{ states('input_number.in_aalight_all_elvl') | int }}"
- service: input_number.set_value
data_template:
entity_id: input_number.in_aalight_out_lvl
value: "{{ states('input_number.in_aalight_out_alvl') | int }}"
- service: input_number.set_value
data_template:
entity_id: input_number.in_aalight_bed4_lvl
value: "{{ states('input_number.in_aalight_bed4_alvl') | int }}"
#name: Light Night Segment
- alias: au_aalight_ngtseg
trigger:
- platform: state
entity_id: input_select.is_aalight_segment
to: 'Night'
action:
- service: input_number.set_value
data_template:
entity_id: input_number.in_aalight_kit_lvl
value: "{{ states('input_number.in_aalight_kit_nlvl') | int }}"
- service: input_number.set_value
data_template:
entity_id: input_number.in_aalight_bth_lvl
value: "{{ states('input_number.in_aalight_bth_nlvl') | int }}"
- service: input_number.set_value
data_template:
entity_id: input_number.in_aalight_all_lvl
value: "{{ states('input_number.in_aalight_all_nlvl') | int }}"
- service: input_number.set_value
data_template:
entity_id: input_number.in_aalight_out_lvl
value: "{{ states('input_number.in_aalight_out_alvl') | int }}"
- service: input_number.set_value
data_template:
entity_id: input_number.in_aalight_bed4_lvl
value: "{{ states('input_number.in_aalight_bed4_alvl') | int }}"
#name: if any kitchen light turns on
- alias: au_aalight_lghtonkit
trigger:
- platform: state
entity_id: light.fibdim2_kitf_level, light.fibdim2_kitr_level
from: 'off'
to: 'on'
condition:
- condition: state
entity_id: input_boolean.ib_aalight_stop_adjust
state: 'off'
action:
- service: light.turn_on
data_template:
entity_id: "{{ trigger.entity_id }}"
brightness_pct: "{{ states('input_number.in_aalight_kit_lvl') | int }}"
transition: "{{ states('input_number.in_aalight_normal_transition') | int }}"
#name: if any bathroom light turns on
- alias: au_aalight_lghtonbth
trigger:
- platform: state
entity_id: light.fibdim2_bath_level, light.fibdim2_ensu_level, light.fibdim2_wc_level
from: 'off'
to: 'on'
condition:
- condition: state
entity_id: input_boolean.ib_aalight_stop_adjust
state: 'off'
action:
- service: light.turn_on
data_template:
entity_id: "{{ trigger.entity_id }}"
brightness_pct: "{{ states('input_number.in_aalight_bth_lvl') | int }}"
transition: "{{ states('input_number.in_aalight_normal_transition') | int }}"
#name: if bed 4 light turns on
- alias: au_aalight_lghtonbed4
trigger:
- platform: state
entity_id: light.fibdim2_bed4_level
from: 'off'
to: 'on'
condition:
- condition: state
entity_id: input_boolean.ib_aalight_stop_adjust
state: 'off'
action:
- service: light.turn_on
data_template:
entity_id: light.fibdim2_bed4_level
brightness_pct: "{{ states('input_number.in_aalight_bed4_lvl') | int }}"
transition: "{{ states('input_number.in_aalight_normal_transition') | int }}"
#name: if an outside light turns on
- alias: au_aalight_lghtonout
trigger:
- platform: state
entity_id: light.fibdim2_ptio_level, light.fibdim2_prch_level
from: 'off'
to: 'on'
condition:
- condition: state
entity_id: input_boolean.ib_aalight_stop_adjust
state: 'off'
action:
- service: light.turn_on
data_template:
entity_id: "{{ trigger.entity_id }}"
brightness_pct: "{{ states('input_number.in_aalight_out_lvl') | int }}"
transition: "{{ states('input_number.in_aalight_normal_transition') | int }}"
#name: if any remaining light turns on
- alias: au_aalight_lghtonall
trigger:
- platform: state
entity_id: light.fibdim2_bed1_level, light.fibdim2_bed2_level, light.fibdim2_bed3_level, light.fibdim2_frtr_level, light.fibdim2_hall_level, light.fibdim2_ldg1_level, light.fibdim2_ldg2_level, light.fibdim2_lvgr_level, light.fibdim2_lmp1_level
####, light.fibdim2_ptio_level, light.fibdim2_prch_level
from: 'off'
to: 'on'
condition:
- condition: state
entity_id: input_boolean.ib_aalight_stop_adjust
state: 'off'
action:
- service: light.turn_on
data_template:
entity_id: "{{ trigger.entity_id }}"
brightness_pct: "{{ states('input_number.in_aalight_all_lvl') | int }}"
transition: "{{ states('input_number.in_aalight_normal_transition') | int }}"
Then here’s an example of the lights, this is bath room (a slightly different profile), it also includes a delay off timer
input_boolean:
ib_light_bath_timer_enable:
name: Bath Timer Enable
#initial: on
icon: mdi:timer
input_number:
in_light_bath_timer:
name: Bath On Timer (mins)
#initial: 80
min: 10
max: 120
step: 1
mode: box
icon: mdi:alarm
in_switch_bath_fan_timer:
name: Bath Fan On Timer (mins)
#initial: 10
min: 1
max: 30
step: 1
mode: box
icon: mdi:alarm
automation:
#name: Light Bath Off Delay
- alias: au_light_bath_offdelay
trigger:
- platform: state
entity_id: light.fibdim2_bath_level
from: 'off'
to: 'on'
condition:
- condition: state
entity_id: input_boolean.ib_light_bath_timer_enable
state: 'on'
action:
- service: light.turn_on
entity_id: light.fibdim2_bath_level
data_template:
brightness_pct: >
{{ states('input_number.in_aalight_bth_lvl') | int }}
transition: >
{{ states('input_number.in_aalight_segment_transition') | int }}
- service: script.turn_off
entity_id: script.sc_light_bath_timer
- service: script.sc_light_bath_timer
#name: Switch Bath Off Cancels Timer
- alias: au_switch_bath_offcancelstimer
trigger:
- platform: state
entity_id: light.fibdim2_bath_level
to: 'off'
action:
- service: script.turn_off
entity_id: script.sc_light_bath_timer
#force fan off
- alias: au_bath_fan_force_off
trigger:
- platform: state
entity_id: binary_sensor.bs_global_noise_permissive
to: 'off'
action:
- service: script.turn_off
entity_id: script.sc_switch_bath_fan_timer
- service: switch.turn_off
entity_id: switch.fibsw_bthf_sw
#fan on link to light on
- alias: au_switch_bath_fan_on
trigger:
- platform: state
entity_id: light.fibdim2_bath_level
to: 'on'
condition:
- condition: state
entity_id: binary_sensor.bs_global_noise_permissive
state: 'on'
action:
- service: switch.turn_on
entity_id: switch.fibsw_bthf_sw
#fan off link to light off
- alias: au_switch_bath_fan_off
trigger:
- platform: state
entity_id: light.fibdim2_bath_level
to: 'off'
action:
- service: script.turn_off
entity_id: script.sc_switch_bath_fan_timer
- service: script.sc_switch_bath_fan_timer
#name: Adjust Brightness On Segment Change
- alias: au_light_adjust_brightness_bthr
trigger:
- platform: state
entity_id: input_number.in_aalight_bth_lvl
condition:
- condition: state
entity_id: light.fibdim2_bath_level
state: 'on'
action:
- service: light.turn_on
entity_id: light.fibdim2_bath_level
data_template:
brightness_pct: "{{ states('input_number.in_aalight_bth_lvl') | int }}"
transition: "{{ states('input_number.in_aalight_segment_transition') | int }}"
script:
sc_light_bath_timer:
alias: Light Bath Timer Script
sequence:
- delay: "00:{{ states('input_number.in_light_bath_timer') | int }}:00"
- service: light.turn_off
entity_id: light.fibdim2_bath_level
sc_switch_bath_fan_timer:
alias: Switch Bath Fan Timer Script
sequence:
- delay: "00:{{ states('input_number.in_switch_bath_fan_timer') | int }}:00"
- service: switch.turn_off
entity_id: switch.fibsw_bthf_sw
You will see that most of the settings are adjustable from the front end (but hidden away on a maintenance tab)