fix nuc stuff
This commit is contained in:
@@ -43,7 +43,7 @@ in
|
||||
};
|
||||
};
|
||||
|
||||
supportedFilesystems = lib.mkDefault [ "bcachefs" ];
|
||||
supportedFilesystems = lib.mkOverride 90 [ "bcachefs" ];
|
||||
|
||||
consoleLogLevel = lib.mkDefault 0;
|
||||
bootspec.enable = (!isArm);
|
||||
|
||||
@@ -139,7 +139,7 @@ in
|
||||
)) { } "lightswitch automations";
|
||||
};
|
||||
|
||||
config = {
|
||||
config = lib.mkIf config.${namespace}.services.home-assistant.enable {
|
||||
environment.etc."hass/lightswitch-automations.yaml" = {
|
||||
text = lightswitchAutomations;
|
||||
user = "hass";
|
||||
162
modules/nixos/homeassistant/automations/motion-light/default.nix
Normal file
162
modules/nixos/homeassistant/automations/motion-light/default.nix
Normal file
@@ -0,0 +1,162 @@
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
namespace,
|
||||
...
|
||||
}:
|
||||
with lib;
|
||||
let
|
||||
inherit (lib.${namespace}) mkOpt mkBoolOpt;
|
||||
cfg = config.${namespace}.services.home-assistant.automation;
|
||||
|
||||
automationToYaml = mlcfg: ''
|
||||
- id: '${toString mlcfg.id}'
|
||||
alias: ${mlcfg.alias}
|
||||
description: '${mlcfg.description}'
|
||||
triggers:
|
||||
- device_id: ${mlcfg.motion-sensor.mqttDeviceId}
|
||||
entity_id: ${mlcfg.motion-sensor.mqttEntityId}
|
||||
domain: binary_sensor
|
||||
id: occupied
|
||||
subtype: on_press
|
||||
trigger: device
|
||||
type: occupied
|
||||
for:
|
||||
hours: 0
|
||||
minutes: 0
|
||||
seconds: 0
|
||||
- device_id: ${mlcfg.motion-sensor.mqttDeviceId}
|
||||
entity_id: ${mlcfg.motion-sensor.mqttEntityId}
|
||||
domain: binary_sensor
|
||||
id: vacant
|
||||
subtype: off_press
|
||||
trigger: device
|
||||
type: not_occupied
|
||||
for:
|
||||
hours: 0
|
||||
minutes: 0
|
||||
seconds: 5
|
||||
conditions: []
|
||||
actions:
|
||||
- choose:
|
||||
- conditions:
|
||||
- condition: trigger
|
||||
id:
|
||||
- occupied
|
||||
sequence:
|
||||
- action: light.turn_on
|
||||
data:
|
||||
brightness_pct: ${toString mlcfg.light.brightnessPercent}
|
||||
kelvin: ${toString mlcfg.light.lightTemperature}
|
||||
transition: ${toString mlcfg.light.transitionTime}
|
||||
metadata: {}
|
||||
target:
|
||||
entity_id:
|
||||
- ${mlcfg.light.entityId}
|
||||
- conditions:
|
||||
- condition: trigger
|
||||
id:
|
||||
- vacant
|
||||
sequence:
|
||||
- action: light.turn_off
|
||||
data:
|
||||
transition: ${toString mlcfg.light.transitionTime}
|
||||
metadata: {}
|
||||
target:
|
||||
entity_id:
|
||||
- ${mlcfg.light.entityId}
|
||||
mode: single
|
||||
'';
|
||||
|
||||
automationToYamlSwitch = mlcfg: ''
|
||||
- id: '${toString mlcfg.id}'
|
||||
alias: ${mlcfg.alias}
|
||||
description: '${mlcfg.description}'
|
||||
triggers:
|
||||
- device_id: ${mlcfg.motion-sensor.mqttDeviceId}
|
||||
entity_id: ${mlcfg.motion-sensor.mqttEntityId}
|
||||
domain: binary_sensor
|
||||
id: occupied
|
||||
subtype: on_press
|
||||
trigger: device
|
||||
type: occupied
|
||||
for:
|
||||
hours: 0
|
||||
minutes: 0
|
||||
seconds: 0
|
||||
- device_id: ${mlcfg.motion-sensor.mqttDeviceId}
|
||||
entity_id: ${mlcfg.motion-sensor.mqttEntityId}
|
||||
domain: binary_sensor
|
||||
id: vacant
|
||||
subtype: off_press
|
||||
trigger: device
|
||||
type: not_occupied
|
||||
for:
|
||||
hours: 0
|
||||
minutes: 0
|
||||
seconds: 5
|
||||
conditions: []
|
||||
actions:
|
||||
- choose:
|
||||
- conditions:
|
||||
- condition: trigger
|
||||
id:
|
||||
- occupied
|
||||
sequence:
|
||||
- type: turn_on
|
||||
device_id: ${mlcfg.switch.deviceId}
|
||||
entity_id: ${mlcfg.switch.entityId}
|
||||
domain: switch
|
||||
- conditions:
|
||||
- condition: trigger
|
||||
id:
|
||||
- vacant
|
||||
sequence:
|
||||
- type: turn_off
|
||||
device_id: ${mlcfg.switch.deviceId}
|
||||
entity_id: ${mlcfg.switch.entityId}
|
||||
domain: switch
|
||||
mode: single
|
||||
'';
|
||||
|
||||
motionLightAutomations = concatStringsSep "\n" (
|
||||
mapAttrsToList (_: automationToYaml) cfg.motion-light
|
||||
);
|
||||
in
|
||||
{
|
||||
options.${namespace}.services.home-assistant.automation = {
|
||||
motion-light = mkOpt (types.attrsOf (
|
||||
types.submodule {
|
||||
options = {
|
||||
id = mkOpt types.int 0 "Automation Id";
|
||||
alias = mkOpt types.str "" "Alias/Friendly Name";
|
||||
description = mkOpt types.str "" "Automation Description";
|
||||
motion-sensor = {
|
||||
mqttDeviceId = mkOpt types.str "" "mqtt device id of the motion sensor";
|
||||
mqttEntityId = mkOpt types.str "" "mqtt entity id of the motion sensor";
|
||||
};
|
||||
light = {
|
||||
entityId = mkOpt types.str "" "home assistant entity id for the lights";
|
||||
transitionTime = mkOpt types.int 2 "light transition time in seconds";
|
||||
brightnessPercent = mkOpt types.int 100 "brightness percentage when turned on";
|
||||
lightTemperature = mkOpt types.int 6000 "light temperature when turned on";
|
||||
brightnessStepPercent = mkOpt types.int 10 "dimmer step in brightness percent";
|
||||
};
|
||||
switch = {
|
||||
enable = mkBoolOpt false "is it a binary switch light";
|
||||
deviceId = mkOpt types.str "" "device id of the switch";
|
||||
entityId = mkOpt types.str "" "entity id of the switch";
|
||||
};
|
||||
};
|
||||
}
|
||||
)) { } "motion light automations";
|
||||
};
|
||||
|
||||
config = lib.mkIf config.${namespace}.services.home-assistant.enable {
|
||||
environment.etc."hass/motion-light-automations.yaml" = {
|
||||
text = motionLightAutomations;
|
||||
user = "hass";
|
||||
group = "hass";
|
||||
};
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user