ma ham: add keller button logic
This commit is contained in:
parent
57bf42286d
commit
2c9923264e
@ -15,6 +15,12 @@ let
|
||||
for.minutes = min;
|
||||
}
|
||||
];
|
||||
condition = [
|
||||
{ condition = "state";
|
||||
entity_id = "input_boolean.ist_sommer";
|
||||
state = "off";
|
||||
}
|
||||
];
|
||||
action =
|
||||
[
|
||||
{
|
||||
@ -61,10 +67,19 @@ let
|
||||
};
|
||||
in {
|
||||
services.home-assistant.config = {
|
||||
sensor = [
|
||||
{ platform = "season"; type = "meteorological";}
|
||||
];
|
||||
|
||||
input_boolean = {
|
||||
badezimmerfenster_lang_offen.name = "Badezimmer lange offen";
|
||||
duschfenster_lang_offen.name = "Duschfenster lange offen";
|
||||
ist_sommer = {
|
||||
name = "Es ist Sommer";
|
||||
initial = true; # TODO
|
||||
};
|
||||
};
|
||||
|
||||
automation = [
|
||||
(fenster_geschlossen_lang "Badezimmerfenster" "binary_sensor.badezimmer_fenster_contact")
|
||||
(fenster_geschlossen_lang "Duschfenster" "binary_sensor.dusche_fenster_contact")
|
||||
|
7
makefu/2configs/home/ham/automation/keller_buttons.nix
Normal file
7
makefu/2configs/home/ham/automation/keller_buttons.nix
Normal file
@ -0,0 +1,7 @@
|
||||
let
|
||||
inherit (../lib) btn_cycle_light;
|
||||
in {
|
||||
services.home-assistant.config.automation = [
|
||||
(btn_cycle_light "light.keller_osram" "keller_btn1" 128)
|
||||
];
|
||||
}
|
@ -1,80 +1,7 @@
|
||||
|
||||
let
|
||||
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 = "Cycle through states of ${light} via button ${btn}";
|
||||
trigger = {
|
||||
platform = "state";
|
||||
entity_id = "sensor.${btn}_click";
|
||||
to = "single";
|
||||
};
|
||||
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;
|
||||
};
|
||||
}];
|
||||
};
|
||||
};
|
||||
turn_off_all = btn:
|
||||
inherit (../lib) btn_cycle_light;
|
||||
turn_off_all = btn: #lights:
|
||||
{
|
||||
alias = "Turn of all lights via ${btn} double click";
|
||||
trigger = {
|
||||
@ -84,14 +11,15 @@ let
|
||||
};
|
||||
action = {
|
||||
service = "light.turn_off";
|
||||
#entity_id = lights;
|
||||
entity_id = "all";
|
||||
};
|
||||
};
|
||||
in {
|
||||
services.home-assistant.config.automation = [
|
||||
# (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")
|
||||
# (btn_cycle_light "light.arbeitszimmerbeleuchtung" "arbeitszimmer_btn1")
|
||||
(btn_cycle_light "light.schlafzimmer_komode_osram" "schlafzimmer_btn2" 128)
|
||||
# (btn_cycle_light "light.wohnzimmerbeleuchtung" "wohnzimmer_btn3")
|
||||
(turn_off_all "schlafzimmer_btn2" )
|
||||
];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user