ma ham/esphome: init

This commit is contained in:
makefu 2020-02-24 16:55:34 +01:00
parent 6edc89b1a8
commit 13b2e5e838
3 changed files with 211 additions and 78 deletions

View file

@ -7,10 +7,12 @@ let
hlib = (import ./lib); hlib = (import ./lib);
prefix = hlib.prefix; prefix = hlib.prefix;
tasmota = hlib.tasmota; tasmota = hlib.tasmota;
firetv = "192.168.1.183"; firetv_stick = "192.168.1.24";
kodi-host = firetv;
hassdir = "/var/lib/hass"; hassdir = "/var/lib/hass";
zigbee = import ./multi/zigbee2mqtt.nix; zigbee = import ./multi/zigbee2mqtt.nix;
flurlicht = import ./multi/flurlicht.nix;
kurzzeitwecker = import ./multi/kurzzeitwecker.nix;
esphome = import ./multi/esphome.nix;
# switch # switch
# automation # automation
# binary_sensor # binary_sensor
@ -25,7 +27,7 @@ in {
services.home-assistant = { services.home-assistant = {
config = { config = {
input_select = zigbee.input_select; # dict input_select = zigbee.input_select; # dict
timer = zigbee.timer; # dict timer = zigbee.timer // kurzzeitwecker.timer; # dict
homeassistant = { homeassistant = {
name = "Home"; time_zone = "Europe/Berlin"; name = "Home"; time_zone = "Europe/Berlin";
latitude = "48.7687"; latitude = "48.7687";
@ -57,7 +59,7 @@ in {
{ {
platform = "kodi"; platform = "kodi";
name = "wohnzimmer"; name = "wohnzimmer";
host = kodi-host; host = firetv_stick;
} }
{ {
platform = "telegram"; platform = "telegram";
@ -71,12 +73,13 @@ in {
recorder = {}; recorder = {};
media_player = [ media_player = [
{ platform = "kodi"; { platform = "kodi";
host = firetv; host = firetv_stick;
} }
{ platform = "firetv"; { platform = "androidtv";
name = "FireTV Stick"; name = "FireTV Stick";
host = firetv; device_class = "firetv";
adbkey = <secrets/hass/adbkey>; # adb_server_ip = firetv_stick;
host = firetv_stick;
} }
]; ];
mqtt = { mqtt = {
@ -100,21 +103,26 @@ in {
retain = true; retain = true;
}; };
}; };
binary_sensor = [ luftdaten = {
(tasmota.motion { name = "Flur Bewegung"; host = "flurlicht";}) show_on_map = true;
] ++ zigbee.binary_sensor; sensor_id = 679;
sensors.monitored_conditions = [ "P1" "P2" ];
};
binary_sensor =
zigbee.binary_sensor
++ esphome.binary_sensor
++ flurlicht.binary_sensor;
sensor = [ sensor = [
# broken { platform = "speedtest";
#{ platform = "speedtest"; monitored_conditions = [ "ping" "download" "upload" ];
# monitored_conditions = [ "ping" "download" "upload" ]; }
#}
# https://www.home-assistant.io/cookbook/automation_for_rainy_days/ # https://www.home-assistant.io/cookbook/automation_for_rainy_days/
] ]
++ ((import ./sensor/outside.nix) {inherit lib;}) ++ ((import ./sensor/outside.nix) {inherit lib;})
++ zigbee.sensor ++ esphome.sensor
++ (tasmota.bme { name = "Schlafzimmer"; host = "schlafzimmer";}) ++ zigbee.sensor ;
++ (tasmota.am2301 { name= "Arbeitszimmer" ; host = "arbeitszimmer"; });
frontend = { }; frontend = { };
light = flurlicht.light ++ esphome.light;
group = group =
{ default_view = { default_view =
{ view = "yes"; { view = "yes";
@ -157,66 +165,14 @@ in {
]; ];
}; };
http = { }; http = { };
switch = [ switch =
(tasmota.plug { name = "Lichterkette Schlafzimmer"; host = "schlafzimmer";}) esphome.switch
(tasmota.plug { name = "Strom Staubsauger"; host = "arbeitszimmer"; } ) ++ zigbee.switch;
] ++ zigbee.switch; automation =
light = [ (tasmota.rgb { name = "Flurlicht"; host = "flurlicht";} ) ]; flurlicht.automation
automation = [ ++ kurzzeitwecker.automation
{ alias = "Dunkel bei Sonnenuntergang"; ++ zigbee.automation;
trigger = { script = kurzzeitwecker.script; # dict
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;
}; };
enable = true; enable = true;
configDir = hassdir; 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";
}
];
}
];
}