ma ham: commit open changes

This commit is contained in:
makefu 2022-01-30 23:51:32 +01:00
parent a721b7ad9b
commit 965a6c96c3
No known key found for this signature in database
GPG Key ID: 36F7711F3FC0F225
15 changed files with 410 additions and 78 deletions

View File

@ -0,0 +1,62 @@
let
button = "binary_sensor.arbeitszimmer_onebutton_button";
light = "light.arbeitszimmer_onebutton_led";
at_work = "input_boolean.felix_at_work";
lib = import ../lib;
say = lib.say.living_room;
in
{
services.home-assistant.config.input_boolean.felix_at_work.name = "Felix auf Arbeit";
services.home-assistant.config.automation =
[
{ alias = "Push Check-in Button Felix with button";
trigger = [
{
platform = "state";
entity_id = button;
to = "on";
for.seconds = 1;
}
];
condition = [
];
action =
[
{ choose = [
{
conditions = {
condition = "state";
entity_id = at_work;
state = "off";
};
sequence = [
{ service = "light.turn_on";
target.entity_id = light;
data.brightness = 200;
}
{ service = "homeassistant.turn_on";
entity_id = at_work;
}
] ++ (say "Willkommen auf Arbeit");
}
{
conditions = {
condition = "state";
entity_id = at_work;
state = "on";
};
sequence = [
{ service = "light.turn_off";
target.entity_id = light;
}
{ service = "homeassistant.turn_off";
entity_id = at_work;
}
] ++ (say "Endlich ist Pappa fertig mit arbeit!");
}
];
}
];
}
];
}

View File

@ -1,5 +1,7 @@
let
licht = "light.flur_statuslight";
licht = [ "light.flur_statuslight" "light.wohnzimmer_status_led" ];
kehrwoche_color = [ 204 0 255 ]; # pink
nachtlicht_color = [ 255 190 0 ]; # ein dunkles rot
in
{
services.home-assistant.config.automation =
@ -16,22 +18,39 @@ in
target.entity_id = licht;
data = {
brightness = 87;
rgbw_color = [ 255 190 0 0 ]; # ein dunkles rot
rgb_color = nachtlicht_color;
#effect = "None";
};
}
];
}
{ alias = "Nachtlicht in Flur aus";
{ alias = "Nachtlicht in Flur aus, Kehrwoche an";
trigger = {
platform = "sun";
event = "sunrise";
};
action =
[
{ choose = [
{
conditions = {
condition = "state";
entity_id = "calendar.kehrwoche_kehrwoche";
state = "on";
};
sequence = {
service = "light.turn_on";
target.entity_id = licht;
data = {
brightness = 190;
rgb_color = kehrwoche_color; # pink
};
};
}];
default = {
service = "light.turn_off";
entity_id = licht;
};
}
];
}

View File

@ -0,0 +1,48 @@
let
btn = "sensor.arbeitszimmer_btn1_action";
all_lights = [
# Wohnzimmer
"light.wled"
"light.wled_2"
"light.wohnzimmer_komode_osram"
"light.wohnzimmer_schrank_osram"
"light.wohnzimmer_fenster_lichterkette_licht"
# Arbeitszimmer
"light.wled_3"
"light.wled_4"
"light.arbeitszimmer_schrank_dimmer"
"light.arbeitszimmer_pflanzenlicht"
"light.wohnzimmer_stehlampe_osram"
# Keller
"light.keller_osram"
];
all_media_player = [
"media_player.living_room"
"media_player.office"
];
in {
services.home-assistant.config.automation =
[
{ alias = "Wohnung shutdown single click";
trigger = [
{
platform = "state";
entity_id = btn;
to = "on";
}
];
condition = [ ];
action = [
{
service = "home_assistant.turn_off";
target.entity_id = all_lights;
}
{ service = "media_player.media_stop";
target.entity_id = all_media_player;
}
];
}
];
}

View File

@ -5,8 +5,9 @@
let
schranklicht = "light.wohnzimmer_schrank_osram";
fernsehlicht = "light.wohnzimmer_fernseher_led_strip";
final_off = "01:00";
weihnachtslicht = "light.wohnzimmer_fenster_lichterkette_licht";
fernsehlicht = "light.wled";
final_off = "00:37";
turn_on = entity_id: at:
{ alias = "Turn on ${entity_id} at ${at}";
@ -25,6 +26,7 @@ in
automation =
[
(turn_on schranklicht "17:30")
(turn_on weihnachtslicht "17:30")
(turn_on fernsehlicht "19:00")
{ alias = "Always turn off the urlaub lights at ${final_off}";
@ -35,7 +37,7 @@ in
[
{
service = "light.turn_off";
entity_id = [ schranklicht fernsehlicht ];
entity_id = [ schranklicht weihnachtslicht fernsehlicht ];
}
];
}

View File

@ -135,7 +135,7 @@ in
data.entity_id = [
"light.wohnzimmer_fernseher_led_strip" "light.wohnzimmer_stehlampe_osram"
"light.wohnzimmer_komode_osram" "light.wohnzimmer_schrank_osram"
"light.wohnzimmer_fenster_lichterkette_licht" "light.wohnzimmer_fernsehwand_led"
"light.wohnzimmer_fenster_lichterkette_licht" "light.wled"
];
};
})

View File

@ -8,8 +8,6 @@ in
platform = "caldav";
inherit (cred) username password;
url = "https://o.euer.krebsco.de/remote.php/dav";
# make calendars "all-day" before uploading:
# sed -i -e 's/^\(DTSTART;.*\)T......\r$/\1\r/' -e # 's/^\(DTEND;.*\)T......\r$/\1\r/' abfall.ical
custom_calendars = [
{
name = "Gelbersack";

View File

@ -4,7 +4,6 @@
##
let
prefix = (import ./lib).prefix;
firetv_stick = "192.168.111.24";
hassdir = "/var/lib/hass";
unstable = import <nixpkgs-unstable> {};
@ -29,6 +28,11 @@ in {
./calendar/nextcloud.nix
./media/firetv.nix
./media/sonos.nix
./media/remote_sound_wohnzimmer.nix
./automation/check-in.nix
./automation/fenster_auf.nix
./automation/firetv_restart.nix
./automation/light_buttons.nix
@ -37,16 +41,19 @@ in {
./automation/flurlicht.nix
#./automation/giesskanne.nix
./automation/pflanzen_giessen_erinnerung.nix
#./automation/urlaub.nix
./automation/urlaub.nix
./automation/moodlight.nix
./automation/shutdown_button.nix
./light/arbeitszimmer.nix
./light/schlafzimmer.nix
./light/wohnzimmer.nix
./tts/google.nix
];
services.home-assistant = {
package = (unstable.home-assistant.overrideAttrs (old: {
package = (pkgs.home-assistant.overrideAttrs (old: {
doInstallCheck = false;
})).override {
extraPackages = p: [
@ -88,13 +95,6 @@ in {
default = "info";
};
rest_command = {};
tts = [
{ platform = "google_translate";
language = "de";
time_memory = 57600;
service_name = "google_say";
}
];
api = {};
esphome = {}; # fails
camera = [];
@ -108,16 +108,6 @@ in {
# (builtins.readFile <secrets/hass/telegram-bot.json>))
#];
notify = [
#{
# platform = "kodi";
# name = "Kodi Wohnzimmer";
# host = firetv_stick;
#}
{
platform = "nfandroidtv";
name = "FireTV Wohnzimmer";
host = firetv_stick;
}
#{
# platform = "telegram";
# name = "telegrambot";
@ -128,19 +118,6 @@ in {
];
sun.elevation = 247;
recorder = {};
media_player = [
{ platform = "kodi";
name = "FireTV Stick kodi";
host = firetv_stick;
}
{ platform = "androidtv";
name = "FireTV Stick";
device_class = "firetv";
# adb_server_ip = firetv_stick;
host = firetv_stick;
port = 5555;
}
];
mqtt = {
broker = "localhost";
discovery = true; #enable esphome discovery

View File

@ -0,0 +1,42 @@
# Begin
let
in {
services.home-assistant.config.automation =
[
];
}
# example automation
{ alias = "";
trigger = [
{
platform = "state";
entity_id = "";
to = "on";
for.seconds = 0;
}
];
condition = [
{ condition = "state";
entity_id = "";
state = "off";
}
];
action =
[
{ choose = [
{
conditions = {
condition = "state";
entity_id = "";
state = "on";
};
sequence = [{
service = "home_assistant.turn_on";
target.entity_id = "";
}];
}];
default = { };
}
];
}

View File

@ -8,36 +8,50 @@ in
tts = { message, entity }:
[
{
service = "media_player.turn_on";
data.entity_id = entity;
service = "sonos.snapshot";
target.entity_id = entity;
}
{
service = "media_player.play_media";
service = "tts.google_say";
data = {
entity_id = entity;
media_content_type = "playlist";
media_content_id = "ansage";
};
}
{
service = "media_player.turn_on";
data.entity_id = entity;
}
{ delay.seconds = 8; }
{
service = "tts.say";
entity_id = entity;
data_template = {
inherit message;
language = "de";
};
}
#{ wait_template = "{{ is_state('${entity}' , 'playing') }}";
# timeout = "00:00:02";
#}
#{ wait_template = "{{ not is_state('${entity}' , 'playing') }}";
# timeout = "00:01:00";
#}
{ delay.seconds = 1; }
{ delay = ''
{% set duration = states.${entity}.attributes.media_duration %}
{% if duration > 0 %}
{% set duration = duration - 1 %}
{% endif %}
{% set seconds = duration % 60 %}
{% set minutes = (duration / 60)|int % 60 %}
{% set hours = (duration / 3600)|int %}
{{ "%02i:%02i:%02i"|format(hours, minutes, seconds)}}
'';
}
{
service = "sonos.restore";
target.entity_id = entity;
}
];
in
{
firetv = message: tts {
living_room = message: tts {
inherit message;
entity = "firetv";
entity = "media_player.living_room";
};
office = message: tts {
inherit message;
entity = "media_player.office";
};
};

View File

@ -11,14 +11,17 @@ let
default_scene_1 = "Solid";
default_color_1 = "Default";
main_color_select_1 = "select.wled_color_palette_4";
light_group_1 = { entity_id = [ main_light_1 ];};
light_group_1.entity_id = [
main_light_1
];
# contains only the actually changeable lights
light_group_2 = { entity_id = [
light_group_2.entity_id = [
"light.arbeitszimmer_schrank_dimmer"
];
};
light_group_3 = { entity_id = [ "light.arbeitszimmer_pflanzenlicht" ]; };
light_group_3.entity_id = [
"light.arbeitszimmer_pflanzenlicht"
];
statecond = cond: { # cond must be a list
condition = "template";

View File

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

View File

@ -0,0 +1,32 @@
let
firetv_stick = "192.168.111.24";
in {
services.home-assistant.config = {
notify = [
#{
# platform = "kodi";
# name = "Kodi Wohnzimmer";
# host = firetv_stick;
#}
{
platform = "nfandroidtv";
name = "FireTV Wohnzimmer";
host = firetv_stick;
}
];
media_player = [
#{
# platform = "kodi";
# name = "FireTV Stick kodi";
# host = firetv_stick;
#}
{ platform = "androidtv";
name = "FireTV Stick";
device_class = "firetv";
# adb_server_ip = firetv_stick;
host = firetv_stick;
port = 5555;
}
];
};
}

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.wohnzimmer_sound1_action";
player = "media_player.living_room";
last_state_sensor_name = "last_rotation_action";
last_state_sensor = "input_text.last_rotation_action";
# - 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 wohnzimmer";
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

@ -0,0 +1,7 @@
{
services.home-assistant.config.sonos.media_player.hosts = [
"192.168.111.30"
"192.168.111.31"
];
}

View File

@ -0,0 +1,18 @@
let
in {
services.home-assistant.config.tts = [
{ platform = "google_translate";
language = "de";
time_memory = 57600;
service_name = "google_say";
}
#{ platform = "google_cloud";
# key_file = toString <secrets/googlecloud.json>;
# service_name = "cloud_say";
# language = "de-DE";
# voice = "de-DE-Wavenet-B";
# profiles = [ "medium-bluetooth-speaker-class-device" ];
#}
];
}