ma ham: add more automations
This commit is contained in:
parent
2cd994a1be
commit
426e0b0c6d
@ -7,7 +7,7 @@ let
|
||||
light = "light.espcam_02_light";
|
||||
seconds = 60; # default shutoff to protect the LED from burning out
|
||||
};
|
||||
seconds = 6;
|
||||
seconds = 60;
|
||||
pump = "switch.arbeitszimmer_giesskanne_relay";
|
||||
# sensor = "sensor.statistics_for_sensor_crafting_brotbox_soil_moisture";
|
||||
in
|
||||
|
41
makefu/2configs/ham/automation/moodlight.nix
Normal file
41
makefu/2configs/ham/automation/moodlight.nix
Normal file
@ -0,0 +1,41 @@
|
||||
# uses:
|
||||
|
||||
let
|
||||
wohnzimmer = "light.wohnzimmer_fenster_lichterkette_licht";
|
||||
arbeitszimmer = "light.box_led_status";
|
||||
final_off = "01:00";
|
||||
|
||||
turn_on = entity_id: at:
|
||||
{ alias = "Turn on ${entity_id} at ${at}";
|
||||
trigger = [
|
||||
{ platform = "time"; inherit at; }
|
||||
];
|
||||
action =
|
||||
[
|
||||
{ service = "light.turn_on"; inherit entity_id; }
|
||||
];
|
||||
};
|
||||
in
|
||||
{
|
||||
services.home-assistant.config =
|
||||
{
|
||||
automation =
|
||||
[
|
||||
(turn_on wohnzimmer "17:30")
|
||||
(turn_on arbeitszimmer "9:00")
|
||||
|
||||
{ alias = "Always turn off the lights at ${final_off}";
|
||||
trigger = [
|
||||
{ platform = "time"; at = final_off; }
|
||||
];
|
||||
action =
|
||||
[
|
||||
{
|
||||
service = "light.turn_off";
|
||||
entity_id = [ wohnzimmer arbeitszimmer];
|
||||
}
|
||||
];
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
@ -26,6 +26,81 @@ let
|
||||
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}";
|
||||
@ -39,14 +114,13 @@ let
|
||||
data.entity_id = light;
|
||||
};
|
||||
};
|
||||
|
||||
in
|
||||
{
|
||||
services.home-assistant.config.automation = [
|
||||
(rf_toggle "400551" "light.wohnzimmer_fernseher_led_strip") # A
|
||||
(rf_toggle "401151" "light.wohnzimmer_stehlampe_osram") # B
|
||||
(rf_toggle "401451" "light.wohnzimmer_komode_osram") # C
|
||||
(rf_toggle "401511" "light.wohnzimmer_schrank_osram") # D
|
||||
(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
|
||||
|
Loading…
Reference in New Issue
Block a user