diff --git a/configs/pepe/home-assistant.nix b/configs/pepe/home-assistant.nix index d435134..1fcf891 100644 --- a/configs/pepe/home-assistant.nix +++ b/configs/pepe/home-assistant.nix @@ -115,13 +115,13 @@ in { control = "hidden"; name = "Not Used"; view = false; + entities = [ ]; }; }; script.turn_all_off.sequence = [ ]; - - script.turn_all_on.sequence = [ ]; + script.turn_all_lights_off.sequence = [ ]; }; diff --git a/configs/pepe/home-assistant/kodi.nix b/configs/pepe/home-assistant/kodi.nix index b668ae9..b0f6dcb 100644 --- a/configs/pepe/home-assistant/kodi.nix +++ b/configs/pepe/home-assistant/kodi.nix @@ -70,7 +70,8 @@ }; }; - group.tv.entities = [ "script.watch_tv" "script.stop_watch_tv" ]; + group.tv.entities = + [ "script.watch_tv" "script.stop_watch_tv" "script.test_display" ]; }; diff --git a/configs/pepe/home-assistant/sonoff.nix b/configs/pepe/home-assistant/sonoff.nix index 204c0c1..9743f21 100644 --- a/configs/pepe/home-assistant/sonoff.nix +++ b/configs/pepe/home-assistant/sonoff.nix @@ -102,19 +102,19 @@ in { # ----------------- script.turn_all_off.sequence = [ { - alias = "turn off sonoff"; + alias = "turn off sonoff lights"; service = "switch.turn_off"; data.entity_id = "group.all_lights"; } { - alias = "turn off sonoff"; + alias = "turn off tv"; service = "switch.turn_off"; data.entity_id = "group.tv"; } ]; - script.turn_all_on.sequence = [{ - alias = "turn on all lights"; - service = "switch.turn_on"; + script.turn_all_lights_off.sequence = [{ + alias = "turn off sonoff lights"; + service = "switch.turn_off"; data.entity_id = "group.all_lights"; }]; @@ -125,16 +125,15 @@ in { flatSonoffSwitches = lib.mapAttrsToList (name: values: { name = name; } // values) sonoffSwitches; - allRooms' = - lib.groupBy ({ room ? "unknown", ... }: room) flatSonoffSwitches; - allRooms = lib.mapAttrs (_: devices: { - entities = map ({ name, ... }: "switch.${name}") devices; - }) allRooms'; allLights' = lib.filter ({ type ? "unknown", ... }: type == "light") flatSonoffSwitches; allLights = { all_lights.entities = map ({ name, ... }: "switch.${name}") allLights'; }; + allRooms' = lib.groupBy ({ room ? "unknown", ... }: room) allLights'; + allRooms = lib.mapAttrs (_: devices: { + entities = map ({ name, ... }: "switch.${name}") devices; + }) allRooms'; in allRooms // allLights // { # this is a quick hack. it should not be the norm to define this stuff down here tv = { entities = builtins.map toSwitch [ "pal05" ]; }; diff --git a/configs/pepe/home-assistant/zigbee2mqtt.nix b/configs/pepe/home-assistant/zigbee2mqtt.nix index 0b15aac..f3f4e00 100644 --- a/configs/pepe/home-assistant/zigbee2mqtt.nix +++ b/configs/pepe/home-assistant/zigbee2mqtt.nix @@ -262,8 +262,23 @@ in { # todo : this belongs in the home-assistant.nix automation = let - lights = map (button: { - alias = "Toggle all lights, on click"; + # hold, turn off the lights everywhere + all_lights_off = map (button: { + alias = "turn all lights off on holding a button"; + trigger = { + platform = "mqtt"; + topic = "zigbee2mqtt/${button}"; + }; + condition = { + condition = "template"; + value_template = ''{{ "hold" == trigger.payload_json.action }}''; + }; + action = { service = "script.turn_all_off"; }; + }) [ "button_1" "button_2" "button_3" ]; + + # one click, turn on the light in the room + room_lights_on = map ({ button, room }: { + alias = "turn on lights in ${room}, on ${button} click"; trigger = { platform = "mqtt"; topic = "zigbee2mqtt/${button}"; @@ -273,32 +288,32 @@ in { value_template = ''{{ "single" == trigger.payload_json.click }}''; }; action = { - service = "switch.toggle"; - entity_id = "group.all_lights"; + service = "switch.turn_on"; + entity_id = "group.${room}"; }; - }) [ "button_1" "button_2" "button_3" ]; + }) [ + { + button = "button_1"; + room = "living_room"; + } + { + button = "button_2"; + room = "bed_room"; + } + { + button = "button_3"; + room = "bed_room"; + } + ]; - #mpd = map (button: { - # alias = "Toggle mpd, on double click"; - # trigger = { - # platform = "mqtt"; - # topic = "zigbee2mqtt/${button}"; - # }; - # condition = { - # condition = "template"; - # value_template = ''{{ "double" == trigger.payload_json.click }}''; - # }; - # action = { - # service = "media_player.toggle"; - # # todo use a group here - # entity_id = "media_player.mpd"; - # }; - #}) [ "button_1" "button_2" "button_3" ]; + # todo : double click, turn on the light in this room and every where else turn it off + # kitchen light automation + # ------------------------ # https://www.home-assistant.io/integrations/binary_sensor.template/ kitchen_lights = map (motion: [ { - alias = "turn on lights, on motion"; + alias = "turn on kitchen lights, on motion detected"; trigger = { platform = "state"; entity_id = "binary_sensor.${motion}"; @@ -307,11 +322,11 @@ in { }; action = { service = "switch.turn_on"; - entity_id = "group.kitchen"; + entity_id = "group.kitchen_room"; }; } { - alias = "turn off lights, on no motion"; + alias = "turn off kitchen lights, on motion clear"; trigger = { platform = "state"; entity_id = "binary_sensor.${motion}"; @@ -320,12 +335,12 @@ in { }; action = { service = "switch.turn_off"; - entity_id = "group.kitchen"; + entity_id = "group.kitchen_room"; }; } ]) [ "motion_sensor_1" ]; - in lib.flatten (lights ++ kitchen_lights); + in lib.flatten (kitchen_lights ++ all_lights_off ++ room_lights_on); # click = double => music an aus