summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hostnix/elmo/home-assistant.nix80
1 files changed, 45 insertions, 35 deletions
diff --git a/hostnix/elmo/home-assistant.nix b/hostnix/elmo/home-assistant.nix
index d97e7a1..db270dd 100644
--- a/hostnix/elmo/home-assistant.nix
+++ b/hostnix/elmo/home-assistant.nix
@@ -1,4 +1,4 @@
-{ pkgs, ... }:
+{ lib, pkgs, ... }:
{
services.postgresql = {
@@ -28,7 +28,36 @@
tuya_local
];
- config = {
+ config = let
+
+ ha = {
+ trigger = {
+ at = time: {
+ platform = "time";
+ at = time;
+ };
+ };
+
+ action = {
+ on = entity: {
+ service = "${lib.head (lib.strings.splitString "." entity)}.turn_on";
+ target.entity_id = entity;
+ };
+
+ off = entity: {
+ service = "${lib.head (lib.strings.splitString "." entity)}.turn_off";
+ target.entity_id = entity;
+ };
+
+ toggle = entity: {
+ service = "${lib.head (lib.strings.splitString "." entity)}.toggle";
+ target.entity_id = entity;
+ };
+ };
+ };
+
+ in
+ {
default_config = { };
http = {
server_host = "::1";
@@ -77,12 +106,7 @@
};
}
];
- turn_off = [
- {
- service = "climate.turn_off";
- target.entity_id = "climate.air_conditioner_1";
- }
- ];
+ turn_off = [ (ha.action.off "climate.air_conditioner_1") ];
};
};
}
@@ -424,17 +448,9 @@
};
};
- service = service: target_id: {
- inherit service;
- target.entity_id = target_id;
- };
-
- setTemperatureAt = at: temperature: {
- alias = "Thermostat ${at}";
- trigger = {
- inherit at;
- platform = "time";
- };
+ setTemperatureAt = time: temperature: {
+ alias = "Thermostat ${time}";
+ trigger = [ (ha.trigger.at time) ];
action = [
{
service = "climate.set_temperature";
@@ -455,8 +471,8 @@
event = "leave";
};
action = [
- (service "light.turn_off" "light.panel_light")
- (service "climate.turn_off" "climate.bedroom_cool")
+ (ha.action.off "light.panel_light")
+ (ha.action.off "climate.bedroom_cool")
];
}
@@ -482,34 +498,28 @@
}
];
action = [
- (service "light.turn_on" "light.panel_light")
+ (ha.action.on "light.panel_light")
];
}
{
alias = "Grow light morning";
- trigger = {
- platform = "time";
- at = "08:00";
- };
+ trigger = [ (ha.trigger.at "08:00") ];
action = [
- (service "switch.turn_on" "light.grow_light")
- (service "switch.turn_on" "switch.wakko")
+ (ha.action.on "light.grow_light")
+ (ha.action.on "switch.wakko")
];
}
{
alias = "Grow light night";
- trigger = {
- platform = "time";
- at = "20:00";
- };
- action = [ (service "switch.turn_off" "switch.wakko") ];
+ trigger = [ (ha.trigger.at "20:00") ];
+ action = [ (ha.action.off "switch.wakko") ];
}
(button "binary_sensor.bedroom_button_1"
- (service "switch.toggle" "switch.wakko"))
+ (ha.action.toggle "switch.wakko"))
(button "binary_sensor.bedroom_button_2"
- (service "light.toggle" "light.panel_light"))
+ (ha.action.toggle "light.panel_light"))
(setTemperatureAt "06:00" 71)
(setTemperatureAt "12:00" 70)