ma ham/esphome: init

This commit is contained in:
makefu 2020-02-24 16:55:34 +01:00
parent 64c224a711
commit 910686f656
No known key found for this signature in database
GPG Key ID: 36F7711F3FC0F225
3 changed files with 211 additions and 78 deletions

View File

@ -7,10 +7,12 @@ let
hlib = (import ./lib);
prefix = hlib.prefix;
tasmota = hlib.tasmota;
firetv = "192.168.1.183";
kodi-host = firetv;
firetv_stick = "192.168.1.24";
hassdir = "/var/lib/hass";
zigbee = import ./multi/zigbee2mqtt.nix;
flurlicht = import ./multi/flurlicht.nix;
kurzzeitwecker = import ./multi/kurzzeitwecker.nix;
esphome = import ./multi/esphome.nix;
# switch
# automation
# binary_sensor
@ -25,7 +27,7 @@ in {
services.home-assistant = {
config = {
input_select = zigbee.input_select; # dict
timer = zigbee.timer; # dict
timer = zigbee.timer // kurzzeitwecker.timer; # dict
homeassistant = {
name = "Home"; time_zone = "Europe/Berlin";
latitude = "48.7687";
@ -57,7 +59,7 @@ in {
{
platform = "kodi";
name = "wohnzimmer";
host = kodi-host;
host = firetv_stick;
}
{
platform = "telegram";
@ -71,12 +73,13 @@ in {
recorder = {};
media_player = [
{ platform = "kodi";
host = firetv;
host = firetv_stick;
}
{ platform = "firetv";
{ platform = "androidtv";
name = "FireTV Stick";
host = firetv;
adbkey = <secrets/hass/adbkey>;
device_class = "firetv";
# adb_server_ip = firetv_stick;
host = firetv_stick;
}
];
mqtt = {
@ -100,21 +103,26 @@ in {
retain = true;
};
};
binary_sensor = [
(tasmota.motion { name = "Flur Bewegung"; host = "flurlicht";})
] ++ zigbee.binary_sensor;
luftdaten = {
show_on_map = true;
sensor_id = 679;
sensors.monitored_conditions = [ "P1" "P2" ];
};
binary_sensor =
zigbee.binary_sensor
++ esphome.binary_sensor
++ flurlicht.binary_sensor;
sensor = [
# broken
#{ platform = "speedtest";
# monitored_conditions = [ "ping" "download" "upload" ];
#}
{ platform = "speedtest";
monitored_conditions = [ "ping" "download" "upload" ];
}
# https://www.home-assistant.io/cookbook/automation_for_rainy_days/
]
++ ((import ./sensor/outside.nix) {inherit lib;})
++ zigbee.sensor
++ (tasmota.bme { name = "Schlafzimmer"; host = "schlafzimmer";})
++ (tasmota.am2301 { name= "Arbeitszimmer" ; host = "arbeitszimmer"; });
++ esphome.sensor
++ zigbee.sensor ;
frontend = { };
light = flurlicht.light ++ esphome.light;
group =
{ default_view =
{ view = "yes";
@ -157,66 +165,14 @@ in {
];
};
http = { };
switch = [
(tasmota.plug { name = "Lichterkette Schlafzimmer"; host = "schlafzimmer";})
(tasmota.plug { name = "Strom Staubsauger"; host = "arbeitszimmer"; } )
] ++ zigbee.switch;
light = [ (tasmota.rgb { name = "Flurlicht"; host = "flurlicht";} ) ];
automation = [
{ alias = "Dunkel bei Sonnenuntergang";
trigger = {
platform = "sun";
event = "sunset";
# offset: "-00:45:00"
};
action = [
{
service= "light.turn_on";
data = {
entity_id= "light.flurlicht";
# rgb_color = [ 0,0,0 ]; <-- TODO default color
brightness_pct = 15;
};
}
{
service= "light.turn_off";
entity_id= "light.flurlicht";
}
];
}
{ alias = "Hell bei Sonnenaufgang";
trigger = {
platform = "sun";
event = "sunrise";
# offset: "-00:00:00"
};
action = [
{
service= "light.turn_on";
data = {
entity_id= "light.flurlicht";
brightness_pct = 85;
};
}
{
service= "light.turn_off";
entity_id= "light.flurlicht";
}
];
}
#{ alias = "Staubsauger Strom aus nach 6h";
# trigger = {
# platform = "state";
# entity_id = "switch.strom_staubsauger";
# to = "on";
# for.hours = 6;
# };
# action = {
# service= "homeassistant.turn_off";
# entity_id= "switch.strom_staubsauger";
# };
#}
] ++ zigbee.automation;
switch =
esphome.switch
++ zigbee.switch;
automation =
flurlicht.automation
++ kurzzeitwecker.automation
++ zigbee.automation;
script = kurzzeitwecker.script; # dict
};
enable = true;
configDir = hassdir;

View File

@ -0,0 +1,45 @@
# provides:
# switch
# automation
# binary_sensor
# sensor
# input_select
# timer
let
inherit (import ../lib) esphome;
sonoff_s20 = host: {
sensor = [
(esphome.ip { inherit host;})
(esphome.wifi { inherit host;})
(esphome.temp { inherit host;})
(esphome.hum { inherit host;})
];
binary_sensor = [
(esphome.btn { inherit host;})
];
light = [
(esphome.monoled { inherit host;})
];
switch = [
(esphome.relay { inherit host;})
(esphome.restart { inherit host;})
];
};
dusche = sonoff_s20 "dusche_plug";
schlafzimmer = sonoff_s20 "schlafzimmer_plug";
in {
sensor = [
(esphome.pressure {host = "dusche_plug";})
]
++ dusche.sensor
++ schlafzimmer.sensor;
binary_sensor =
dusche.binary_sensor
++ schlafzimmer.binary_sensor;
light =
dusche.light
++ schlafzimmer.light;
switch =
dusche.switch
++ schlafzimmer.switch;
}

View File

@ -0,0 +1,132 @@
# Provides:
# timer
# automation
# script
# Needs:
# sensor.zigbee_btn1_click
# notify.telegrambot
let
button = "sensor.zigbee_btn2_click";
in {
timer.kurzzeitwecker =
{
name = "Zigbee Kurzzeitwecker";
duration = 300;
};
script.add_5_minutes_to_kurzzeitwecker =
{
alias = "Add 5 minutes to kurzzeitwecker";
sequence = [
{ service = "timer.pause";
entity_id = "timer.kurzzeitwecker";
}
{ service = "timer.start";
data_template = {
entity_id = "timer.kurzzeitwecker";
duration = ''
{% set r = state_attr('timer.kurzzeitwecker', 'remaining') ~ '-0000' %}
{% set t = strptime(r, '%H:%M:%S.%f%z') %}
{{ (as_timestamp(t) + 300) | timestamp_custom('%H:%M:%S', false) }}
'';
};
}
];
};
automation =
[
{
alias = "Start Timer 5min";
trigger = {
platform = "state";
entity_id = button;
to = "single";
};
condition =
{ condition = "state";
entity_id = "timer.kurzzeitwecker";
state = "idle";
};
action = [
{ service = "timer.start";
entity_id = "timer.kurzzeitwecker";
data.duration = "00:05:00";
}
{
service = "notify.telegrambot";
data.message = "Timer gestartet {{state_attr('timer.kurzzeitwecker', 'remaining') }}, verbleibend ";
}
];
}
{
alias = "Add Timer 5min";
trigger = {
platform = "state";
entity_id = button;
to = "single";
};
condition =
{ condition = "state";
entity_id = "timer.kurzzeitwecker";
state = "active";
};
action = [
{ service = "homeassistant.turn_on";
entity_id = "script.add_5_minutes_to_kurzzeitwecker";
}
{
service = "notify.telegrambot";
data.message = ''Timer um 5 minuten verlängert, {{ state_attr('timer.kurzzeitwecker', 'remaining') | truncate(9,True," ") }} verbleibend '';
}
];
}
{
alias = "Stop timer on double click";
trigger = [
{
platform = "state";
entity_id = button;
to = "double";
}
{
platform = "state";
entity_id = button;
to = "triple";
}
];
condition =
{
condition = "state";
entity_id = "timer.kurzzeitwecker";
state = "active";
};
action = [
{
service = "timer.cancel";
entity_id = "timer.kurzzeitwecker";
}
{
service = "notify.telegrambot";
data.message = "Timer gestoppt, abgebrochen";
}
];
}
{
alias = "Timer Finished";
trigger = {
platform = "event";
event_type = "timer.finished";
event_data.entity_id = "timer.kurzzeitwecker";
};
action = [
{
service = "notify.telegrambot";
data.message = "Timer beendet";
}
];
}
];
}