71 lines
2.5 KiB
Python
71 lines
2.5 KiB
Python
from ha_deconz_bridge.automation import ActionSpec, automation_rules
|
|
|
|
|
|
def kelvin_to_mireds(kelvin: int) -> int:
|
|
return int(round(1_000_000 / kelvin))
|
|
|
|
|
|
def scene(target: str, *, brightness: int, kelvin: int) -> ActionSpec:
|
|
return ActionSpec(
|
|
"set_scene",
|
|
target=target,
|
|
brightness=brightness,
|
|
color_temp=kelvin_to_mireds(kelvin),
|
|
)
|
|
|
|
|
|
def all_lights_scene(*, brightness: int, kelvin: int) -> tuple[ActionSpec, ...]:
|
|
return (
|
|
scene("Living Room", brightness=brightness, kelvin=kelvin),
|
|
scene("Hallway", brightness=brightness, kelvin=kelvin),
|
|
scene("Kitchen", brightness=brightness, kelvin=kelvin),
|
|
scene("Bathroom", brightness=brightness, kelvin=kelvin),
|
|
scene("Bedroom", brightness=brightness, kelvin=kelvin),
|
|
)
|
|
|
|
|
|
def all_lights_off() -> tuple[ActionSpec, ...]:
|
|
return (
|
|
ActionSpec("turn_off", target="Living Room"),
|
|
ActionSpec("turn_off", target="Hallway"),
|
|
ActionSpec("turn_off", target="Kitchen"),
|
|
ActionSpec("turn_off", target="Bathroom"),
|
|
ActionSpec("turn_off", target="Bedroom"),
|
|
)
|
|
|
|
|
|
def room_automation(room: str) -> dict[str, dict[str, tuple[ActionSpec, ...]]]:
|
|
return {
|
|
"top": {
|
|
"single": (scene(room, brightness=255, kelvin=4000),),
|
|
"double": (scene(room, brightness=255, kelvin=5500),),
|
|
"hold": all_lights_scene(brightness=255, kelvin=4000),
|
|
"double_hold": all_lights_scene(brightness=255, kelvin=5500),
|
|
},
|
|
"up": {
|
|
"single": (scene(room, brightness=153, kelvin=3000),),
|
|
"double": (scene(room, brightness=204, kelvin=3500),),
|
|
"hold": (ActionSpec("brightness_step", target=room, brightness_step=26),),
|
|
},
|
|
"down": {
|
|
"single": (scene(room, brightness=51, kelvin=2200),),
|
|
"double": (scene(room, brightness=102, kelvin=2500),),
|
|
"hold": (ActionSpec("brightness_step", target=room, brightness_step=-26),),
|
|
},
|
|
"bottom": {
|
|
"single": (ActionSpec("turn_off", target=room),),
|
|
"hold": all_lights_off(),
|
|
},
|
|
}
|
|
|
|
|
|
AUTOMATION_CONFIG = {
|
|
"example_living_remote": room_automation("Living Room"),
|
|
"example_kitchen_remote": room_automation("Kitchen"),
|
|
"example_hall_remote": room_automation("Hallway"),
|
|
"example_bathroom_remote": room_automation("Bathroom"),
|
|
"example_bedroom_remote": room_automation("Bedroom"),
|
|
}
|
|
|
|
AUTOMATIONS = automation_rules(AUTOMATION_CONFIG)
|