diff options
author | tv <tv@krebsco.de> | 2021-05-20 11:08:58 +0200 |
---|---|---|
committer | tv <tv@krebsco.de> | 2021-05-20 11:08:58 +0200 |
commit | 5460255668f43ad1486c6ce0261aebe06d64857a (patch) | |
tree | 75e4f4b71c5636bb405b9ddbb30fdbeeffb4eced /makefu/2configs/home/ham/automation | |
parent | a5d9c02a937f577c0dc25b8e46142f9c9b1db534 (diff) | |
parent | da975042c505a2fa693677cbd10d8245c17b3570 (diff) |
Merge remote-tracking branch 'prism/master'
Diffstat (limited to 'makefu/2configs/home/ham/automation')
5 files changed, 296 insertions, 28 deletions
diff --git a/makefu/2configs/home/ham/automation/fenster_auf.nix b/makefu/2configs/home/ham/automation/fenster_auf.nix index ccebd5b00..871f248b9 100644 --- a/makefu/2configs/home/ham/automation/fenster_auf.nix +++ b/makefu/2configs/home/ham/automation/fenster_auf.nix @@ -1,3 +1,8 @@ +{ lib, ... }: +#uses: +# notify.signal +# binary_sensor.badezimmer_fenster_contact +# binary_sensor.dusche_fenster_contact let min = 20; fenster_offen = name: entity: @@ -13,21 +18,57 @@ let action = [ { - service = "notify.firetv_wohnzimmer"; + service = "notify.signal_home"; data = { - title = "${name} seit ${toString min} Minuten offen"; - message = "Bitte einmal checken ob das ok ist :)"; - data = { - interrupt = 1; - duration = 300; - }; + message= "${name} seit ${toString min} Minuten offen\nBitte einmal checken ob das ok ist :)"; }; } + { + service = "input_boolean.turn_on"; + target.entity_id = "input_boolean.${lib.toLower name}_lang_offen"; + } + ]; + }; + fenster_geschlossen_lang = name: entity: + { alias = "${name} wieder geschlossen"; + trigger = [ + { + platform = "state"; + entity_id = entity; + to = "off"; + } + ]; + condition = [ + { condition = "state"; + entity_id = "input_boolean.${lib.toLower name}_lang_offen"; + state = "on"; + } + ]; + action = + [ + { + service = "notify.signal_home"; + data = { + message= "${name} ist wieder geschlossen, Danke!"; + }; + } + { + service = "input_boolean.turn_off"; + target.entity_id = "input_boolean.${lib.toLower name}_lang_offen"; + } ]; }; in { - services.home-assistant.config.automation = [ - (fenster_offen "Badezimmerfenster" "binary_sensor.badezimmer_fenster_contact") - (fenster_offen "Duschfenster" "binary_sensor.dusche_fenster_contact") - ]; + services.home-assistant.config = { + input_boolean = { + badezimmerfinester_lang_offen.name = "Badezimmer lange offen"; + duschfenster_lang_offen.name = "Duschfenster lange offen"; + }; + automation = [ + (fenster_geschlossen_lang "Badezimmerfenster" "binary_sensor.badezimmer_fenster_contact") + (fenster_geschlossen_lang "Duschfenster" "binary_sensor.badezimmer_fenster_contact") + (fenster_offen "Badezimmerfenster" "binary_sensor.badezimmer_fenster_contact") + (fenster_offen "Duschfenster" "binary_sensor.dusche_fenster_contact") + ]; + }; } diff --git a/makefu/2configs/home/ham/automation/giesskanne.nix b/makefu/2configs/home/ham/automation/giesskanne.nix index 4b0fb61dd..b11fd9d52 100644 --- a/makefu/2configs/home/ham/automation/giesskanne.nix +++ b/makefu/2configs/home/ham/automation/giesskanne.nix @@ -5,9 +5,9 @@ let name = "chilicam"; camera = "camera.espcam_02"; light = "light.espcam_02_light"; - seconds = 60; # default shutoff to protect the LED from burning out + seconds = 90; # default shutoff to protect the LED from burning out }; - seconds = 60; + seconds = 70; # time for giesskanne pump = "switch.arbeitszimmer_giesskanne_relay"; # sensor = "sensor.statistics_for_sensor_crafting_brotbox_soil_moisture"; in diff --git a/makefu/2configs/home/ham/automation/lichter_dimmen.nix b/makefu/2configs/home/ham/automation/lichter_dimmen.nix new file mode 100644 index 000000000..4303cdfa5 --- /dev/null +++ b/makefu/2configs/home/ham/automation/lichter_dimmen.nix @@ -0,0 +1,135 @@ +# This module maps the RF433 Remote Control to zigbee and wifi lights +let + rf_turn_off = code: light: + { + alias = "Turn off ${light} via rf code ${code}"; + trigger = { + platform = "event"; + event_type = "esphome.rf_code_received"; + event_data.code = code; + }; + action = { + service = "light.turn_off"; + data.entity_id = light; + }; + }; + rf_turn_on = code: light: + { + alias = "Turn on ${light} via rf code ${code}"; + trigger = { + platform = "event"; + event_type = "esphome.rf_code_received"; + event_data.code = code; + }; + action = { + service = "light.turn_on"; + data.entity_id = light; + }; + }; + rf_state = code: light: halfbright: + let + maxbright = 255; + transition = 0.2; # seconds + in + # this function implements a simple state machine based on the state and brightness of the light (light must support brightness + { + alias = "Cycle through states of ${light} via rf code ${code}"; + trigger = { + platform = "event"; + event_type = "esphome.rf_code_received"; + event_data.code = code; + }; + action = { + choose = [ + { + # state 0: off to half + conditions = { + condition = "template"; + value_template = ''{{ states("${light}") == "off" }}''; + }; + sequence = [ + { + service = "light.turn_on"; + data = { + entity_id = light; + brightness = halfbright; + }; + } + ]; + } + { + # state 1: half to full + conditions = { + condition = "template"; + value_template = ''{{ states('${light}') == 'on' and ( ${toString (halfbright - 1)} <= state_attr("${light}","brightness") <= ${toString (halfbright + 1)})}}''; + }; + sequence = [ + { + service = "light.turn_on"; + data = { + entity_id = light; + brightness = maxbright; + }; + } + ]; + } + { + # state 2: full to off + conditions = { + condition = "template"; + # TODO: it seems like the devices respond with brightness-1 , maybe off-by-one somewhere? + value_template = ''{{ states("${light}") == "on" and state_attr("${light}","brightness") >= ${toString (maxbright - 1)}}}''; + }; + sequence = [ + { + service = "light.turn_off"; + data = { + entity_id = light; + }; + } + ]; + } + ]; + # default: on to off + # this works because state 0 checks for "state == off" + default = [{ + service = "light.turn_off"; + data = { + entity_id = light; + }; + }]; + }; + } +; + rf_toggle = code: light: + { + alias = "Toggle ${light} via rf code ${code}"; + trigger = { + platform = "event"; + event_type = "esphome.rf_code_received"; + event_data.code = code; + }; + action = { + service = "light.toggle"; + data.entity_id = light; + }; + }; +in +{ + services.home-assistant.config.automation = [ + (rf_toggle "400551" "light.wohnzimmer_fernseher_led_strip") # A + (rf_state "401151" "light.wohnzimmer_stehlampe_osram" 128) # B + (rf_state "401451" "light.wohnzimmer_komode_osram" 128) # C + (rf_state "401511" "light.wohnzimmer_schrank_osram" 128) # D + + # OFF Lane + (rf_turn_off "400554" "all") # A + (rf_toggle "401154" "light.wohnzimmer_fenster_lichterkette_licht") # B + (rf_toggle "401454" "light.wohnzimmer_fernsehwand_led") # C + # (rf_toggle "401514" "") # D + ]; + # "400554" # A OFF + # "401154" # B OFF + # "401454" # C OFF + # "401514" # D OFF +} diff --git a/makefu/2configs/home/ham/automation/light_buttons.nix b/makefu/2configs/home/ham/automation/light_buttons.nix index 32d134ecc..89caf1a41 100644 --- a/makefu/2configs/home/ham/automation/light_buttons.nix +++ b/makefu/2configs/home/ham/automation/light_buttons.nix @@ -1,22 +1,77 @@ -# light.wohnzimmerbeleuchtung -# light.wohnzimmer_deko -# light.arbeitszimmerbeleuchtung -# light.arbeitszimmer_deko -# light.schlafzimmerbeleuchtung let - toggle = light: btn: + btn_state = light: btn: halfbright: + let + maxbright = 255; + transition = 0.2; # seconds + in + # this function implements a simple state machine based on the state and brightness of the light (light must support brightness { - alias = "Toggle Light ${light} via ${btn}"; + alias = "Cycle through states of ${light} via button ${btn}"; trigger = { platform = "state"; entity_id = "sensor.${btn}_click"; to = "single"; }; action = { - service = "light.toggle"; - data.entity_id = light; - data.transition = 0; + choose = [ + { + # state 0: off to half + conditions = { + condition = "template"; + value_template = ''{{ states("${light}") == "off" }}''; + }; + sequence = [ + { + service = "light.turn_on"; + data = { + entity_id = light; + brightness = halfbright; + }; + } + ]; + } + { + # state 1: half to full + conditions = { + condition = "template"; + value_template = ''{{ states('${light}') == 'on' and ( ${toString (halfbright - 1)} <= state_attr("${light}","brightness") <= ${toString (halfbright + 1)})}}''; + }; + sequence = [ + { + service = "light.turn_on"; + data = { + entity_id = light; + brightness = maxbright; + }; + } + ]; + } + { + # state 2: full to off + conditions = { + condition = "template"; + # TODO: it seems like the devices respond with brightness-1 , maybe off-by-one somewhere? + value_template = ''{{ states("${light}") == "on" and state_attr("${light}","brightness") >= ${toString (maxbright - 1)}}}''; + }; + sequence = [ + { + service = "light.turn_off"; + data = { + entity_id = light; + }; + } + ]; + } + ]; + # default: on to off + # this works because state 0 checks for "state == off" + default = [{ + service = "light.turn_off"; + data = { + entity_id = light; + }; + }]; }; }; turn_off_all = btn: @@ -34,11 +89,9 @@ let }; in { services.home-assistant.config.automation = [ - (toggle "light.arbeitszimmerbeleuchtung" "arbeitszimmer_btn1") - (toggle "light.schlafzimmerbeleuchtung" "schlafzimmer_btn2") - (toggle "light.wohnzimmerbeleuchtung" "wohnzimmer_btn3") - (turn_off_all "arbeitszimmer_btn1") + # (btn_state "light.arbeitszimmerbeleuchtung" "arbeitszimmer_btn1") + (btn_state "light.schlafzimmer_komode_osram" "schlafzimmer_btn2" 128) + # (btn_state "light.wohnzimmerbeleuchtung" "wohnzimmer_btn3") (turn_off_all "schlafzimmer_btn2") - (turn_off_all "wohnzimmer_btn3") ]; } diff --git a/makefu/2configs/home/ham/automation/pflanzen_giessen_erinnerung.nix b/makefu/2configs/home/ham/automation/pflanzen_giessen_erinnerung.nix new file mode 100644 index 000000000..3aaa57bd6 --- /dev/null +++ b/makefu/2configs/home/ham/automation/pflanzen_giessen_erinnerung.nix @@ -0,0 +1,39 @@ +let + notify_felix = message: { + service = "notify.signal_felix"; + data.message = message; + }; + notify_home = message: { + service = "notify.signal_home"; + data.message = message; + }; +in +{ + services.home-assistant.config.automation = + [ + { + alias = "Pflanzen Giessen Erinnerung Daily"; + trigger = { + platform = "time"; + at = "12:15:00"; + }; + action = [ + (notify_felix "Es ist Mittagszeit und du kannst ruhig einmal alle Blumen im Zimmer giessen") + ]; + } + { + alias = "Pflanzen Giessen Erinnerung Weekly"; + trigger = { + platform = "time"; + at = "12:15:00"; + }; + condition = { + condition = "time"; + weekday = [ "sat" ]; + }; + action = [ + (notify_home "Es ist Wochenende und die Pflanzen würden sich über ein bisschen Wasser freuen.") + ]; + } + ]; +} |