ma ham: reenabel giesskanne

This commit is contained in:
makefu 2022-06-06 21:07:52 +02:00
parent 54869b752d
commit 2047429a2e
No known key found for this signature in database
GPG Key ID: 36F7711F3FC0F225
9 changed files with 241 additions and 90 deletions

View File

@ -3,7 +3,7 @@ let
light = "light.arbeitszimmer_onebutton_led"; light = "light.arbeitszimmer_onebutton_led";
at_work = "input_boolean.felix_at_work"; at_work = "input_boolean.felix_at_work";
lib = import ../lib; lib = import ../lib;
say = lib.say.living_room; say = lib.say.office;
in in
{ {
services.home-assistant.config.input_boolean.felix_at_work.name = "Felix auf Arbeit"; services.home-assistant.config.input_boolean.felix_at_work.name = "Felix auf Arbeit";
@ -37,7 +37,16 @@ in
{ service = "homeassistant.turn_on"; { service = "homeassistant.turn_on";
entity_id = at_work; entity_id = at_work;
} }
] ++ (say "Willkommen auf Arbeit"); ] ++ (say "Willkommen auf Arbeit") ++
[
{ service = "media_player.play_media";
data = {
media_content_id = "https://radio.lassul.us/radio.mp3";
media_content_type = "music";
};
target.entity_id = "media_player.office";
}
];
} }
{ {
conditions = { conditions = {

View File

@ -1,56 +1,57 @@
let let
licht = [ "light.flur_statuslight" "light.wohnzimmer_status_led" ]; nachtlicht = [ "light.flur_statuslight" "light.wohnzimmer_status_led" ];
kehrwoche_color = [ 204 0 255 ]; # pink
nachtlicht_color = [ 255 190 0 ]; # ein dunkles rot # flurlicht an
lightcond = name: conditions: rgb_color: brightness:
{
inherit conditions;
sequence = {
service = "light.turn_on";
target.entity_id = nachtlicht;
data = {
inherit rgb_color brightness;
};
};
};
in in
{ {
services.home-assistant.config.automation = services.home-assistant.config.automation =
[ [
{ alias = "Nachtlicht im Flur an"; { alias = "Nachtlicht trigger";
trigger = { trigger = [
platform = "sun"; { platform = "sun"; event = "sunset"; }
event = "sunset"; { platform = "sun"; event = "sunrise"; }
}; { platform = "state"; entity_id = [
action = "calendar.kehrwoche_kehrwoche"
[ "binary_sensor.badezimmer_fenster_contact"
{ "binary_sensor.dusche_fenster_contact"
service = "light.turn_on"; ];
target.entity_id = licht;
data = {
brightness = 87;
rgb_color = nachtlicht_color;
#effect = "None";
};
} }
]; ];
}
{ alias = "Nachtlicht in Flur aus, Kehrwoche an";
trigger = {
platform = "sun";
event = "sunrise";
};
action = action =
[ [
{ choose = [ { choose = [
{ (lightcond "Badezimmer Fenster Auf"
conditions = { { condition = "state"; entity_id = "binary_sensor.badezimmer_fenster_contact"; state = "on"; }
condition = "state"; [ 64 207 255 ] 255 # helblau
entity_id = "calendar.kehrwoche_kehrwoche"; )
state = "on"; (lightcond "Duschenster auf"
}; { condition = "state"; entity_id = "binary_sensor.dusche_fenster_contact"; state = "on"; }
sequence = { [ 64 207 255 ] 255 # helblau
service = "light.turn_on"; )
target.entity_id = licht; (lightcond "Nachtlicht"
data = { { condition = "state"; entity_id = "sun.sun"; state = "below_horizon"; }
brightness = 190; [ 255 190 0 ] 90 # red
rgb_color = kehrwoche_color; # pink )
}; (lightcond "Kehrwoche"
}; { condition = "state"; entity_id = "calendar.kehrwoche_kehrwoche"; state = "on"; }
}]; [ 204 0 255 ] 128 # pink
)
];
default = { default = {
service = "light.turn_off"; service = "light.turn_off";
entity_id = licht; entity_id = nachtlicht;
}; };
} }
]; ];
} }

View File

@ -7,8 +7,10 @@ let
light = "light.espcam_02_light"; light = "light.espcam_02_light";
seconds = 90; # default shutoff to protect the LED from burning out seconds = 90; # default shutoff to protect the LED from burning out
}; };
seconds = 70; # time for giesskanne seconds = 60*5; # time for giesskanne - 5 minutes
pump = "switch.arbeitszimmer_giesskanne_relay"; pump = "switch.arbeitszimmer_giesskanne_relay";
light = "switch.terrasse_plug_relay";
# sensor = "sensor.statistics_for_sensor_crafting_brotbox_soil_moisture"; # sensor = "sensor.statistics_for_sensor_crafting_brotbox_soil_moisture";
in in
{ {
@ -26,19 +28,27 @@ in
[ [
##### brotbox ##### brotbox
{ alias = "Water the plant for ${toString seconds} seconds"; { alias = "Water the plant for ${toString seconds} seconds and turn on the light";
trigger = [ trigger = [
{ # trigger at 23:15 no matter what { # trigger at 23:15 no matter what
# TODO: retry or run only if switch.wasser is available # TODO: retry or run only if switch.wasser is available
platform = "time"; platform = "sun";
at = "23:15:00"; event = "sunrise";
} }
]; ];
action = action =
[ [
{ # take a snapshot before watering
{ # now turn on the pumping services
# i do not start hte pump and light before the snapshot because i do
# not know how long it takes (do not want to water the plants for too long)
service = "homeassistant.turn_on"; service = "homeassistant.turn_on";
entity_id = [ cam.light ]; entity_id = [ pump light ];
}
{ delay.seconds = seconds; }
{
service = "homeassistant.turn_off";
entity_id = [ pump cam.light ];
} }
{ # TODO: we could also create a recording with camera.record { # TODO: we could also create a recording with camera.record
service = "camera.snapshot"; service = "camera.snapshot";
@ -48,34 +58,21 @@ in
filename = "/var/lib/hass/cam/${cam.name}_{{ now().strftime('%Y%m%d-%H%M%S') }}.jpg"; filename = "/var/lib/hass/cam/${cam.name}_{{ now().strftime('%Y%m%d-%H%M%S') }}.jpg";
}; };
} }
{ # now turn on the pumping services
# i do not start hte pump and light before the snapshot because i do
# not know how long it takes (do not want to water the plants for too long)
service = "homeassistant.turn_on";
entity_id = [ pump ];
}
{ delay.seconds = seconds; }
{
service = "homeassistant.turn_off";
entity_id = [ pump cam.light ];
}
]; ];
} }
{ alias = "Always turn off the light after ${toString (cam.seconds)}s"; { alias = "Turn off the light at sunset";
trigger = [ trigger = [
{ {
platform = "state"; platform = "sun";
entity_id = cam.light; event = "sunset";
to = "on"; # offset = "+02:00:00";
for.seconds = cam.seconds;
} }
]; ];
action = action =
[ [
{ {
service = "homeassistant.turn_off"; service = "homeassistant.turn_off";
entity_id = [ pump cam.light ]; entity_id = [ light ];
} }
]; ];
} }
@ -93,7 +90,7 @@ in
[ [
{ {
service = "homeassistant.turn_off"; service = "homeassistant.turn_off";
entity_id = [ pump cam.light ]; entity_id = [ pump ];
} }
]; ];
} }

View File

@ -7,12 +7,26 @@ let
schranklicht = "light.wohnzimmer_schrank_osram"; schranklicht = "light.wohnzimmer_schrank_osram";
weihnachtslicht = "light.wohnzimmer_fenster_lichterkette_licht"; weihnachtslicht = "light.wohnzimmer_fenster_lichterkette_licht";
fernsehlicht = "light.wled"; fernsehlicht = "light.wled";
all_lights = [
schranklicht weihnachtslicht fernsehlicht
# extra lights to also turn off
# wohnzimmer
"light.wohnzimmer_komode_osram"
"light.wohnzimmer_stehlampe_osram"
# arbeitszimmer
"light.wled_4"
"light.arbeitszimmer_schrank_dimmer"
"light.arbeitszimmer_pflanzenlicht"
];
final_off = "00:37"; final_off = "00:37";
turn_on = entity_id: at: turn_on = entity_id: offset:
{ alias = "Turn on ${entity_id} at ${at}"; # negative offset => before sunset
{ alias = "Turn on ${entity_id} at sunset ${offset}";
trigger = [ trigger = [
{ platform = "time"; inherit at; } { platform = "sun"; event = "sunset"; inherit offset; }
]; ];
action = action =
[ [
@ -25,9 +39,9 @@ in
{ {
automation = automation =
[ [
(turn_on schranklicht "17:30") (turn_on schranklicht "-00:30:00")
(turn_on weihnachtslicht "17:30") #(turn_on weihnachtslicht "-00:30:00")
(turn_on fernsehlicht "19:00") (turn_on fernsehlicht "-00:00:00")
{ alias = "Always turn off the urlaub lights at ${final_off}"; { alias = "Always turn off the urlaub lights at ${final_off}";
trigger = [ trigger = [

View File

@ -31,15 +31,16 @@ in {
./media/firetv.nix ./media/firetv.nix
./media/sonos.nix ./media/sonos.nix
./media/remote_sound_wohnzimmer.nix ./media/remote_sound_wohnzimmer.nix
./media/remote_sound_arbeitszimmer.nix
./automation/check-in.nix ./automation/check-in.nix
./automation/fenster_auf.nix ./automation/fenster_auf.nix
./automation/firetv_restart.nix ./automation/firetv_restart.nix
./automation/light_buttons.nix ./automation/light_buttons.nix
./automation/wohnzimmer_rf_fernbedienung.nix ./automation/wohnzimmer_rf_fernbedienung.nix
./automation/ladestecker_timer.nix # ./automation/ladestecker_timer.nix
./automation/flurlicht.nix ./automation/flurlicht.nix
#./automation/giesskanne.nix ./automation/giesskanne.nix
./automation/pflanzen_giessen_erinnerung.nix ./automation/pflanzen_giessen_erinnerung.nix
./automation/urlaub.nix ./automation/urlaub.nix
./automation/moodlight.nix ./automation/moodlight.nix
@ -59,7 +60,7 @@ in {
extraPackages = p: [ extraPackages = p: [
(p.callPackage ./deps/dwdwfsapi.nix {}) (p.callPackage ./deps/dwdwfsapi.nix {})
(p.callPackage ./signal-rest/pkg.nix {}) (p.callPackage ./signal-rest/pkg.nix {})
#(p.callPackage ./deps/pykodi.nix {}) (p.callPackage ./deps/pykodi.nix {})
]; ];
}; };
@ -141,11 +142,11 @@ in {
retain = true; retain = true;
}; };
}; };
luftdaten = { #luftdaten = {
show_on_map = true; # show_on_map = true;
sensor_id = 10529; # sensor_id = 10529;
sensors.monitored_conditions = [ "P1" "P2" ]; # sensors.monitored_conditions = [ "P1" "P2" ];
}; #};
#binary_sensor = #binary_sensor =
# flurlicht.binary_sensor; # flurlicht.binary_sensor;

View File

@ -25,19 +25,20 @@ let
default_scene_1 = "Solid"; default_scene_1 = "Solid";
default_color_1 = "Default"; default_color_1 = "Default";
main_color_select_1 = "select.wled_color_palette"; main_color_select_1 = "select.wled_color_palette";
light_group_1.entity_id = [ light_group_1.entity_id = [
main_light_1 main_light_1
]; ];
# contains only the actually changeable lights # contains only the actually changeable lights
light_group_2.entity_id = [ light_group_2 = { entity_id = [
"light.wohnzimmer_komode_osram" "light.wohnzimmer_komode_osram"
"light.wohnzimmer_schrank_osram" "light.wohnzimmer_schrank_osram"
"light.wohnzimmer_fenster_lichterkette_licht" "light.wohnzimmer_fenster_lichterkette_licht"
]; ];
light_group_3.entity_id = [ };
light_group_3 = { entity_id = [
"light.wohnzimmer_stehlampe_osram" "light.wohnzimmer_stehlampe_osram"
]; ]; };
statecond = cond: { # cond must be a list statecond = cond: { # cond must be a list
condition = "template"; condition = "template";

View File

@ -0,0 +1,107 @@
{ lib, ...}:
let
statecond = cond: { # cond must be a list
condition = "template";
value_template = "{{ trigger.to_state.state in ( " +
(lib.concatMapStringsSep "," (x: "'${x}'") cond) + ") }}";
};
vol_change = 0.030;
max_repeat = "30"; # max loops to repeat before bailing out
remote = "sensor.arbeitszimmer_sound1_action";
player = "media_player.office";
last_state_sensor_name = "last_rotation_action_arbeitszimmer";
last_state_sensor = "input_text.${last_state_sensor_name}";
# - service: media_player.volume_set
# target:
# entity_id: media_player.kitchen
# data:
# volume_level: {{ state_attr('media_player.kitchen', 'volume_level') + 0.02 }}
rotate_stop = "brightness_stop";
rotate_right = "brightness_move_up";
rotate_left = "brightness_move_down" ;
single_click = "toggle";
double_click = "brightness_step_up";
triple_click = "brightness_step_down";
in {
services.home-assistant.config.input_text."${last_state_sensor_name}".name = "Last action of the arbeitszimmer";
services.home-assistant.config.automation = [
{
trigger = {
platform = "state";
entity_id = remote;
to = [ rotate_stop ];
};
action = [
{ service = "input_text.set_value";
target.entity_id = last_state_sensor;
data.value = "stop";
}
];
}
{
alias = "Perform Actions with ${remote}";
trigger = {
platform = "state";
entity_id = remote;
to = [ single_click double_click triple_click rotate_left rotate_right ];
};
#mode = "queued";
#max = 5;
mode = "single";
#max_exceeded = "silent";
action = [
{
choose = [
{
conditions = statecond [ single_click ];
sequence = [
{ service = "media_player.media_play_pause";
target.entity_id = player;
}
];
}
{
conditions = statecond [ rotate_left rotate_right ];
sequence = let
vol_up = toString vol_change;
vol_down = toString (-1 * vol_change);
in [
{
variables.nextvol = ''{% if trigger.to_state.state in ( "${rotate_left}" ) -%} ${vol_down} {% else -%} ${vol_up} {% endif -%}'';
variables.state = ''{% if trigger.to_state.state in ( "${rotate_left}" ) -%} left {% else -%} right {% endif -%}'';
}
{ service = "input_text.set_value";
target.entity_id = last_state_sensor;
data.value = ''{{ state }}'';
}
{
repeat = {
sequence = [
{ service = "media_player.volume_set";
target.entity_id = player;
data.volume_level = ''{{ state_attr("${player}","volume_level") + (nextvol|float) }}'';
}
{ delay.milliseconds = "150"; }
];
while = [
{
condition = "template";
value_template = ''{{ states("${last_state_sensor}") == state }}'';
}
{
condition = "template";
value_template = "{{ repeat.index <= ${max_repeat}}}";
}
];
};
}
];
}
];
}
];
}
];
}

View File

@ -2,6 +2,7 @@
services.home-assistant.config.sonos.media_player.hosts = [ services.home-assistant.config.sonos.media_player.hosts = [
"192.168.111.30" "192.168.111.30"
"192.168.111.31" "192.168.111.31"
"192.168.111.32"
]; ];
} }

View File

@ -0,0 +1,20 @@
{config, ... }:
{
services.home-assistant.config.person = [
{
name = "Felix";
id = 1;
device_trackers = [
"device_tracker.felix_phone"
"device_tracker.x"
];
}
{
name = "Misa";
id = 2;
device_trackers = [
"device_tracker.misa_phone"
];
}
];
}