Skip to content

Instantly share code, notes, and snippets.

@paxswill
Last active October 1, 2020 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paxswill/fee523718dbae00b673ccc8e13c6361c to your computer and use it in GitHub Desktop.
Save paxswill/fee523718dbae00b673ccc8e13c6361c to your computer and use it in GitHub Desktop.
A collection of Home Assistant w/ circadian_lighting configs
# Overview:
# Define two circadian_lighting switches, one controlling just brightness and the
# other just color. Add the real lights to these two switches, then define a
# template light that basically passes through any commands to the real lights,
# but also modifies a toggle that enables/disables circadian_lighting's brightness
# control.
input_boolean:
living_room_brightness_override:
name: "Living Room Brightness Override"
# I just copied this in from a separate config file, so there might be a file syntax error...
light:
- platform: group
name: "Living Room Lights"
entities:
# List all of the lights to be controlled here.
- light.living_room_floor
- light.living_room_ceiling_1
- light.living_room_ceiling_2
- light.living_room_table
switch:
- platform: circadian_lighting
name: "Living Room Circadian Color"
lights_ct:
# ...and list the lights again here...
- light.living_room_ceiling_1
- light.living_room_ceiling_2
- light.living_room_floor
- light.living_room_table
initial_transition: 1
disable_brightness_adjust: true
- platform: circadian_lighting
name: "Living Room Circadian Brightness"
lights_brightness:
# ...and one last time here.
# Doing something with YAML anchors would probably be nicer, but I'm not sure if HAss supports those.
- light.living_room_ceiling_1
- light.living_room_ceiling_2
- light.living_room_floor
- light.living_room_table
initial_transition: 1
disable_brightness_adjust: false
#min_brightness: 50
disable_entity: input_boolean.living_room_brightness_override
disable_state: "on"
# Masking lights
light:
- platform: template
lights:
circadian_living_room_lights:
friendly_name: "Living Room Masked Light"
entity_id: light.living_room_lights
value_template: "{{ is_state('light.living_room_lights', 'on') }}"
level_template: "{{ state_attr('light.living_room_lights', 'brightness') }}"
temperature_template: "{{ state_attr('light.living_room_lights', 'color_temp') }}"
turn_on:
- service: input_boolean.turn_off
entity_id: input_boolean.living_room_brightness_override
- service: light.turn_on
entity_id: light.living_room_lights
turn_off:
- service: input_boolean.turn_on
entity_id: input_boolean.living_room_brightness_override
- service: light.turn_off
entity_id: light.living_room_lights
set_level:
- service: input_boolean.turn_on
entity_id: input_boolean.living_room_brightness_override
- service: light.turn_on
data:
entity_id: light.living_room_lights
data_template:
brightness: "{{ brightness }}"
set_temperature:
- service: input_boolean.turn_on
entity_id: input_boolean.living_room_brightness_override
- service: light.turn_on
data:
entity_id: light.living_room_lights
data_template:
color_temp: "{{ color_temp }}"
# Some of the automation blocks in here look a bit weird, toggling a bunch of input_booleans,
# but they have a purpose. To work around the Hue integration having a bit of lag from
# polling the bridge, I'm hooking up my Hue switches with the HomeKit integration. I have an
# input_boolean for each button that is exposed through the HAss HomeKit integration to
# HomeKit, then add a HomeKit automation (i.e. one within the Home.app interface) that turns
# on the switch when the corresponding button is pushed. The delay is much better, with the
# added cost of a lot more complexity and a working HomeKit bridge.
# I've included a config fragment in another file with the actual entities defined for
# reference purposes
automation:
- alias: "Living Room On"
description: "When the lights are off, turn them on and disable the brightness override."
trigger:
platform: state
entity_id: input_boolean.hue_living_room_on
to: "on"
condition:
- condition: state
entity_id: light.living_room_lights
state: "off"
action:
- service: input_boolean.turn_off
data_template:
entity_id: "{{ trigger.entity_id }}"
- service: light.turn_on
entity_id: light.circadian_living_room_lights
- alias: "Living Room On - Circadian"
description: "When the lights are on and overridden, turn off the override."
trigger:
platform: state
entity_id: input_boolean.hue_living_room_on
to: "on"
condition:
- condition: state
entity_id: light.living_room_lights
state: "on"
- condition: state
entity_id: input_boolean.living_room_brightness_override
state: "on"
action:
- service: input_boolean.turn_off
data_template:
entity_id: "{{ trigger.entity_id }}"
- service: input_boolean.turn_off
entity_id: input_boolean.living_room_brightness_override
- alias: "Living Room Brighter"
trigger:
platform: state
entity_id: input_boolean.hue_living_room_bright
to: "on"
action:
- service: input_boolean.turn_off
data_template:
entity_id: "{{ trigger.entity_id }}"
- service: light.turn_on
data:
entity_id: light.circadian_living_room_lights
data_template:
brightness: >
{% set brightness = state_attr('light.circadian_living_room_lights', 'brightness')|default(0)|int %}
{{ ((brightness / 255 * 100 + 10) / 100 * 255)|int }}
- alias: "Living Room Dimmer"
trigger:
platform: state
entity_id: input_boolean.hue_living_room_dim
to: "on"
action:
- service: input_boolean.turn_off
data_template:
entity_id: "{{ trigger.entity_id }}"
- service: light.turn_on
data:
entity_id: light.circadian_living_room_lights
data_template:
brightness: >
{% set brightness = state_attr('light.circadian_living_room_lights', 'brightness')|default(0)|int %}
{{ ((brightness / 255 * 100 - 10) / 100 * 255)|int }}
- alias: "Living Room Off"
trigger:
platform: state
entity_id: input_boolean.hue_living_room_off
action:
- service: input_boolean.turn_off
data_template:
entity_id: "{{ trigger.entity_id }}"
- service: light.turn_off
entity_id: light.circadian_living_room_lights
# Workaround for accessing Hue switches through Homekit for the push interface
# instead of through Home Assistant's normal Hue integration which is pull based
# (with a polling frequecy of around 5 seconds).
# Technique introduced here:
# https://community.home-assistant.io/t/making-the-hue-motion-sensor-more-responsive-in-home-assistant/127284
input_boolean:
# Living Room 4 button switch
hue_living_room_on:
name: HAss Living Room On Button
hue_living_room_bright:
name: HAss Living Room Dimmer Up Button
initial: false
hue_living_room_dim:
name: HAss Living Room Dimmer Down Button
initial: false
hue_living_room_off:
name: HAss Living Room Off Button
initial: false
homekit:
auto_start: true
entity_config:
"light.circadian_living_room_lights":
name: "Living Room Lights"
filter:
# Filtering out the Hue devices that are already managed by HomeKit (as well
# as light groups covering only those devices).
exclude_entities:
# Living Room
- light.living_room_lights
- light.living_room_table
- light.living_room_floor
- light.living_room_ceiling_1
- light.living_room_ceiling_2
- sensor.living_room_switch_battery_level
include_entities:
# Expose the Masking Circadian lights
- light.circadian_living_room_lights
- light.circadian_wills_bedroom_lights
# Explicitly include the input_boolean entities for the push workaround
# Living Room 4 button switch
- input_boolean.hue_living_room_on
- input_boolean.hue_living_room_bright
- input_boolean.hue_living_room_dim
- input_boolean.hue_living_room_off
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment