diff --git a/configs/pepe/home-assistant.nix b/configs/pepe/home-assistant.nix index 8047a2b..96f8af1 100644 --- a/configs/pepe/home-assistant.nix +++ b/configs/pepe/home-assistant.nix @@ -56,33 +56,6 @@ in { # ]; #} - #{ - # alias = "Küchen Sensor An"; - # trigger = { - # platform = "state"; - # entity_id = [ "binary_sensor.motion_1" ]; - # to = "on"; - # }; - # action = { - # service = "switch.turn_on"; - # entity_id = "group.kitchen"; - # }; - #} - - #{ - # alias = "Küchen Sensor aus"; - # trigger = { - # platform = "state"; - # entity_id = [ "binary_sensor.motion_1" ]; - # to = "off"; - # for = "00:00:25"; - # }; - # action = { - # service = "switch.turn_off"; - # entity_id = "group.kitchen"; - # }; - #} - ]; group = { @@ -106,7 +79,6 @@ in { control = "hidden"; name = "Today"; view = false; - entities = [ "sensor.weather_temperature" "sun.sun" ]; }; all_lights = { name = "All Lights"; @@ -136,8 +108,6 @@ in { }; - sun = { }; - script.turn_all_off.sequence = [ ]; script.turn_all_on.sequence = [ ]; diff --git a/configs/pepe/home-assistant/sonoff.nix b/configs/pepe/home-assistant/sonoff.nix index 818ccb4..fabc326 100644 --- a/configs/pepe/home-assistant/sonoff.nix +++ b/configs/pepe/home-assistant/sonoff.nix @@ -44,16 +44,49 @@ in { services.homeAssistantConfig = { - homeassistant = { - customize = lib.mapAttrs' (entity: value: { + # nicer names + # ----------- + homeassistant.customize = lib.mapAttrs' (entity: + { label, icon, ... }: { name = toSwitch entity; value = { - friendly_name = value.label; - icon = value.icon; + friendly_name = label; + icon = icon; }; }) sonoffSwitches; - }; + # define switches + # --------------- + switch = builtins.map (name: { + name = name; + platform = "mqtt"; + command_topic = "cmnd/${lib.toUpper name}/POWER"; + state_topic = "stat/${lib.toUpper name}/POWER"; + payload_on = "ON"; + payload_off = "OFF"; + state_on = "ON"; + state_off = "OFF"; + }) (builtins.attrNames sonoffSwitches); + + # discover state on init + # ---------------------- + automation = [{ + alias = "Sonoff initial Power state"; + trigger = { + platform = "homeassistant"; + event = "start"; + }; + action = builtins.map (name: { + service = "mqtt.publish"; + data = { + topic = "cmnd/${lib.toUpper name}/power"; + payload = ""; + }; + }) (builtins.attrNames sonoffSwitches); + }]; + + # append to scripts + # ----------------- script.turn_all_off.sequence = [ { alias = "turn off sonoff"; @@ -66,13 +99,14 @@ in { data.entity_id = "group.tv"; } ]; - script.turn_all_on.sequence = [{ alias = "turn on all lights"; service = "switch.turn_on"; data.entity_id = "group.all_lights"; }]; + # append to groups + # ---------------- group = { bed_room = { entities = builtins.map toSwitch [ "pal01" "pal02" ]; }; living_room = { entities = builtins.map toSwitch [ "pal03" "pal04" ]; }; @@ -91,34 +125,6 @@ in { }; }; - switch = let - sonoffConfigurations = builtins.map (name: { - name = name; - platform = "mqtt"; - command_topic = "cmnd/${lib.toUpper name}/POWER"; - state_topic = "stat/${lib.toUpper name}/POWER"; - payload_on = "ON"; - payload_off = "OFF"; - state_on = "ON"; - state_off = "OFF"; - }) (builtins.attrNames sonoffSwitches); - in sonoffConfigurations; - - # discover state on init - automation = [{ - alias = "Sonoff initial Power state"; - trigger = { - platform = "homeassistant"; - event = "start"; - }; - action = builtins.map (name: { - service = "mqtt.publish"; - data = { - topic = "cmnd/${lib.toUpper name}/power"; - payload = ""; - }; - }) (builtins.attrNames sonoffSwitches); - }]; }; } diff --git a/configs/pepe/home-assistant/weather.nix b/configs/pepe/home-assistant/weather.nix index 40bfc5a..48c857b 100644 --- a/configs/pepe/home-assistant/weather.nix +++ b/configs/pepe/home-assistant/weather.nix @@ -9,7 +9,9 @@ } ]; - group = { overview.entities = [ "sensor.weather" ]; }; + sun = { }; + + group.today.entities = [ "sensor.weather_temperature" "sun.sun" ]; }; diff --git a/configs/pepe/home-assistant/workday.nix b/configs/pepe/home-assistant/workday.nix index 18e1bc9..971258c 100644 --- a/configs/pepe/home-assistant/workday.nix +++ b/configs/pepe/home-assistant/workday.nix @@ -23,20 +23,17 @@ homeassistant.customize = { "binary_sensor.workday" = { icon = "mdi:calendar"; - friendly_name = "Today?"; + friendly_name = "Workday?"; }; "binary_sensor.before_workday" = { icon = "mdi:calendar"; - friendly_name = "Tomorrow?"; + friendly_name = "Workday Tomorrow?"; }; }; group = { - is_workday = { - name = "Workday"; - control = "hidden"; - entities = [ "binary_sensor.before_workday" "binary_sensor.workday" ]; - }; + today.entities = + [ "binary_sensor.before_workday" "binary_sensor.workday" ]; view_overview.entities = [ "group.is_workday" ]; };