diff options
author | makefu <github@syntax-fehler.de> | 2020-05-21 08:38:16 +0200 |
---|---|---|
committer | makefu <github@syntax-fehler.de> | 2020-05-21 08:38:16 +0200 |
commit | d027d1d5316371280221870a9c05f2b35fb437ac (patch) | |
tree | e4c8e2a580d4d7d2d01f440ec837bed707db0c64 /lass | |
parent | ab0906f7aab8a49186e64c4942a516686a132558 (diff) | |
parent | cf5b35b2df428495f5bf4dd89e3cab190f069080 (diff) |
Merge remote-tracking branch 'lass/master'
Diffstat (limited to 'lass')
-rw-r--r-- | lass/1systems/icarus/config.nix | 11 | ||||
-rw-r--r-- | lass/1systems/shodan/config.nix | 13 | ||||
-rw-r--r-- | lass/2configs/hass/default.nix | 26 | ||||
-rw-r--r-- | lass/2configs/hass/lib.nix | 196 | ||||
-rw-r--r-- | lass/2configs/hass/rooms/bett.nix | 25 | ||||
-rw-r--r-- | lass/2configs/hass/rooms/essen.nix | 9 | ||||
-rw-r--r-- | lass/2configs/hass/rooms/nass.nix | 10 | ||||
-rw-r--r-- | lass/2configs/hass/zigbee.nix | 79 | ||||
-rw-r--r-- | lass/2configs/home-media.nix | 23 |
9 files changed, 299 insertions, 93 deletions
diff --git a/lass/1systems/icarus/config.nix b/lass/1systems/icarus/config.nix index 5e16052ad..8332e7c53 100644 --- a/lass/1systems/icarus/config.nix +++ b/lass/1systems/icarus/config.nix @@ -21,20 +21,15 @@ with import <stockholm/lib>; #<stockholm/lass/2configs/prism-share.nix> <stockholm/lass/2configs/ssh-cryptsetup.nix> <stockholm/lass/2configs/network-manager.nix> + <stockholm/lass/2configs/home-media.nix> ]; - #media center - users.users.media = { - isNormalUser = true; - uid = genid_uint31 "media"; - extraGroups = [ "video" "audio" ]; - }; + krebs.build.host = config.krebs.hosts.icarus; services.xserver.displayManager.lightdm.autoLogin = { enable = true; user = "media"; }; - krebs.build.host = config.krebs.hosts.icarus; - programs.adb.enable = true; + environment.systemPackages = [ pkgs.chromium ]; } diff --git a/lass/1systems/shodan/config.nix b/lass/1systems/shodan/config.nix index 831e03f79..e41c9bd1e 100644 --- a/lass/1systems/shodan/config.nix +++ b/lass/1systems/shodan/config.nix @@ -22,22 +22,11 @@ with import <stockholm/lib>; <stockholm/lass/2configs/hass> <stockholm/lass/2configs/br.nix> <stockholm/lass/2configs/fetchWallpaper.nix> + <stockholm/lass/2configs/home-media.nix> ]; krebs.build.host = config.krebs.hosts.shodan; - #media center - users.users.media = { - isNormalUser = true; - uid = genid_uint31 "media"; - extraGroups = [ "video" "audio" ]; - }; - - services.xserver.displayManager.lightdm.autoLogin = { - enable = true; - user = "media"; - }; - services.logind.lidSwitch = "ignore"; services.logind.lidSwitchDocked = "ignore"; diff --git a/lass/2configs/hass/default.nix b/lass/2configs/hass/default.nix index ef9361102..639ba3d3f 100644 --- a/lass/2configs/hass/default.nix +++ b/lass/2configs/hass/default.nix @@ -1,8 +1,12 @@ { config, lib, pkgs, ... }: +with import ./lib.nix { inherit lib; }; + { imports = [ ./zigbee.nix ./rooms/bett.nix + ./rooms/essen.nix + ./rooms/nass.nix ]; krebs.iptables.tables.filter.INPUT.rules = [ @@ -33,9 +37,11 @@ homeassistant = { name = "Home"; time_zone = "Europe/Berlin"; - latitude = "48.7687"; - longitude = "9.2478"; - elevation = 247; + latitude = "52.46187"; + longitude = "13.41489"; + elevation = 90; + unit_system = "metric"; + customize = friendly_names; }; config = {}; sun.elevation = 66; @@ -61,6 +67,10 @@ }; }; sensor = [ + { + platform = "dwd_weather_warnings"; + region_name = "Berlin"; + } ]; switch = [ (tasmota_s20 "TV" "tv") @@ -69,6 +79,16 @@ (tasmota_s20 "Stereo Anlage" "stereo") ]; mobile_app = {}; + hue = {}; + weather = [ + { + platform = "openweathermap"; + api_key = "xxx"; # TODO put into secrets + } + ]; + system_health = {}; + history = {}; + shopping_list = {}; }; services.mosquitto = { diff --git a/lass/2configs/hass/lib.nix b/lass/2configs/hass/lib.nix index c69f5e887..555cfae28 100644 --- a/lass/2configs/hass/lib.nix +++ b/lass/2configs/hass/lib.nix @@ -1,18 +1,196 @@ -{ +{ lib, ... }: +rec { lights = { - bett = "light.0x0017880106ed3bd8_light"; - essen = "light.0x0017880108327622_light"; - arbeit = "light.0x0017880106ee2865_light"; - nass = "light.0x00178801082e9f2f_light"; + bett = "0x0017880106ed3bd8"; + essen = "0x0017880108327622"; + arbeit = "0x0017880106ee2865"; + nass = "0x00178801082e9f2f"; + }; + + switches = { + dimmer = { + bett = "0x00178801086ac38c"; + essen = "0x00178801086ad1fb"; + nass = "0x00178801086ac373"; + }; }; sensors = { - bett = "0x00178801086ac38c"; + movement = { + essen = "0x0017880106f772f2"; + nass = "0x0017880106f77f30"; + }; + }; + + friendly_names = + lib.mapAttrs' (n: v: lib.nameValuePair "light.${v}_light" { friendly_name = "l.${n}"; }) lights // + lib.mapAttrs' (n: v: lib.nameValuePair "binary_sensor.${v}_update_available" { friendly_name = "s.${n}_up"; }) switches.dimmer // + lib.mapAttrs' (n: v: lib.nameValuePair "binary_sensor.${v}_update_available" { friendly_name = "i.${n}_up"; }) sensors.movement // + lib.mapAttrs' (n: v: lib.nameValuePair "binary_sensor.${v}_update_available" { friendly_name = "l.${n}_up"; }) lights // + lib.mapAttrs' (n: v: lib.nameValuePair "sensor.${v}_linkquality" { friendly_name = "s.${n}_link"; }) switches.dimmer // + lib.mapAttrs' (n: v: lib.nameValuePair "sensor.${v}_linkquality" { friendly_name = "i.${n}_link"; }) sensors.movement // + lib.mapAttrs' (n: v: lib.nameValuePair "sensor.${v}_linkquality" { friendly_name = "l.${n}_link"; }) lights // + lib.mapAttrs' (n: v: lib.nameValuePair "sensor.${v}_battery" { friendly_name = "s.${n}_bat"; }) switches.dimmer // + lib.mapAttrs' (n: v: lib.nameValuePair "sensor.${v}_battery" { friendly_name = "i.${n}_bat"; }) sensors.movement // + lib.mapAttrs' (n: v: lib.nameValuePair "sensor.${v}_action" { friendly_name = "s.${n}_act"; }) switches.dimmer // + lib.mapAttrs' (n: v: lib.nameValuePair "binary_sensor.${v}_occupancy" { friendly_name = "i.${n}_move"; }) sensors.movement // + lib.mapAttrs' (n: v: lib.nameValuePair "binary_sensor.${v}_occupancy" { friendly_name = "i.${n}_move"; }) sensors.movement // + lib.mapAttrs' (n: v: lib.nameValuePair "sensor.${v}_temperature" { friendly_name = "i.${n}_heat"; }) sensors.movement // + lib.mapAttrs' (n: v: lib.nameValuePair "sensor.${v}_temperature" { friendly_name = "i.${n}_heat"; }) sensors.movement // + lib.mapAttrs' (n: v: lib.nameValuePair "sensor.${v}_illuminance" { friendly_name = "i.${n}_lux"; }) sensors.movement // + lib.mapAttrs' (n: v: lib.nameValuePair "sensor.${v}_illuminance" { friendly_name = "i.${n}_lux"; }) sensors.movement // + {}; + + detect_movement = sensor: light: delay: + let + id = "${sensor}_${light}"; + sensor_ = "binary_sensor.${sensor}_occupancy"; + light_ = "light.${light}_light"; + in { + input_boolean."${id}" = { + }; + timer."${id}" = { + duration = delay; + }; + automation = [ + # { + # alias = "debug detect_movement"; + # trigger = { + # platform = "state"; + # entity_id = sensor_; + # }; + # action = [ + # { + # service = "system_log.write"; + # data_template = { + # message = "XXXXXXXXXXXXXXXXXXXXXX {{ states('input_boolean.${sensor}_${light}_triggered') == 'on' }}"; + # #message = "XXXXXXXXXXXXXXXXXXXXXX {{ state_attr('trigger.to_state.state', 'illuminance') }}"; + # }; + # } + # ]; + # } + { + alias = "movement reset timer ${id}"; + hide_entity = true; + trigger = { + platform = "state"; + entity_id = sensor_; + from = "off"; + to = "on"; + }; + action = [ + { + service = "timer.cancel"; + data_template.entity_id = "timer.${id}"; + } + ]; + } + { + alias = "movement on ${id}"; + # hide_entity = true; + trigger = { + platform = "state"; + entity_id = "binary_sensor.${sensor}_occupancy"; + from = "off"; + to = "on"; + }; + condition = { + condition = "and"; + conditions = [ + { + condition = "template"; + value_template = "{{ trigger.to_state.attributes.illuminance < 13000 }}"; + } + { + condition = "template"; + value_template = "{{ states('${light_}') == 'off' }}"; + } + ]; + }; + action = [ + { + service = "light.turn_on"; + data_template = { + entity_id = light_; + brightness = "100"; + }; + } + { delay = "0:00:02"; } + { + service = "input_boolean.turn_on"; + data_template.entity_id = "input_boolean.${id}"; + } + ]; + } + { + alias = "movement off ${id}"; + hide_entity = true; + trigger = { + platform = "state"; + entity_id = sensor_; + from = "on"; + to = "off"; + }; + condition = { + condition = "template"; + value_template = "{{ states('input_boolean.${id}') == 'on' }}"; + }; + action = [ + { + service = "timer.start"; + entity_id = "timer.${id}"; + } + ]; + } + { + alias = "movement override ${id}"; + hide_entity = true; + trigger = { + platform = "state"; + entity_id = light_; + }; + action = [ + { + service = "input_boolean.turn_off"; + data_template.entity_id = "input_boolean.${id}"; + } + { + service = "system_log.write"; + data_template = { + message = "XXXXXXXXXXXXXXXXXXXXXX {{ trigger }}"; + }; + } + ]; + } + { + alias = "movement expired ${id}"; + hide_entity = true; + trigger = { + platform = "event"; + event_type = "timer.finished"; + event_data.entity_id = "timer.${id}"; + }; + action = [ + { + service = "light.turn_off"; + data_template = { + entity_id = light_; + }; + } + { + service = "input_boolean.turn_off"; + data_template.entity_id = "input_boolean.${id}"; + } + ]; + } + ]; }; lightswitch = switch: light: { automation = [ { + alias = "lightswitch ${switch} turn on light ${light}"; + hide_entity = "true"; trigger = { platform = "mqtt"; topic = "zigbee/${switch}"; @@ -47,13 +225,15 @@ { service = "light.turn_on"; data_template = { - entity_id = light; + entity_id = "light.${light}_light"; brightness = "{{ trigger.payload_json.brightness }}"; }; } ]; } { + alias = "lightswitch ${switch} turn off light ${light}"; + hide_entity = "true"; trigger = { platform = "mqtt"; topic = "zigbee/${switch}"; @@ -74,7 +254,7 @@ action = { service = "light.turn_off"; data_template = { - entity_id = light; + entity_id = "light.${light}_light"; }; }; } diff --git a/lass/2configs/hass/rooms/bett.nix b/lass/2configs/hass/rooms/bett.nix index 21092ef5f..b5da9221c 100644 --- a/lass/2configs/hass/rooms/bett.nix +++ b/lass/2configs/hass/rooms/bett.nix @@ -1,27 +1,8 @@ { lib, ... }: -with import ../lib.nix; +with import ../lib.nix { inherit lib; }; { - lass.hass.config = lib.lists.fold lib.recursiveUpdate {} [ - { - #automation = [{ - # trigger = { - # platform = "mqtt"; - # topic = "zigbee/0x00178801086ac38c/action"; - # payload = "on-press"; - # }; - # action = { - # service = "light.turn_on"; - # data = { - # brightness = 150; - # rgb_color = [ 255 0 0 ]; - # entity_id = [ - # "light.0x0017880108327622_light" - # ]; - # }; - # }; - #}]; - } - (lightswitch sensors.bett lights.bett) + lass.hass.config = lib.mkMerge [ + (lightswitch switches.dimmer.bett lights.bett) ]; } diff --git a/lass/2configs/hass/rooms/essen.nix b/lass/2configs/hass/rooms/essen.nix new file mode 100644 index 000000000..f74996154 --- /dev/null +++ b/lass/2configs/hass/rooms/essen.nix @@ -0,0 +1,9 @@ +{ lib, ... }: +with import ../lib.nix { inherit lib; }; + +{ + lass.hass.config = lib.mkMerge [ + (detect_movement sensors.movement.essen lights.essen 10) + (lightswitch switches.dimmer.essen lights.essen) + ]; +} diff --git a/lass/2configs/hass/rooms/nass.nix b/lass/2configs/hass/rooms/nass.nix new file mode 100644 index 000000000..163f4fc48 --- /dev/null +++ b/lass/2configs/hass/rooms/nass.nix @@ -0,0 +1,10 @@ +{ lib, ... }: +with import ../lib.nix { inherit lib; }; + +{ + lass.hass.config = lib.mkMerge [ + (detect_movement sensors.movement.nass lights.nass 100) + (lightswitch switches.dimmer.nass lights.nass) + ]; +} + diff --git a/lass/2configs/hass/zigbee.nix b/lass/2configs/hass/zigbee.nix index 4d57f9ca4..6d091066e 100644 --- a/lass/2configs/hass/zigbee.nix +++ b/lass/2configs/hass/zigbee.nix @@ -2,7 +2,7 @@ zigbee2mqtt_cfg = pkgs.writeText "zigbee2mqtt.json" (builtins.toJSON { homeassistant = true; - permit_join = true; + permit_join = false; mqtt = { discovery = true; base_topic = "zigbee"; @@ -41,14 +41,14 @@ in { { platform = "mqtt"; name = "Zigbee2mqtt Bridge state"; - state_topic = "/zigbee/bridge/state"; + state_topic = "/zigbee2mqtt/bridge/state"; icon = "mdi:router-wireless"; } # Sensor for Showing the Zigbee2mqtt Version { platform = "mqtt"; name = "Zigbee2mqtt Version"; - state_topic = "/zigbee/bridge/config"; + state_topic = "/zigbee2mqtt/bridge/config"; value_template = "{{ value_json.version }}"; icon = "mdi:zigbee"; } @@ -56,7 +56,7 @@ in { { platform = "mqtt"; name = "Coordinator Version"; - state_topic = "/zigbee/bridge/config"; + state_topic = "/zigbee2mqtt/bridge/config"; value_template = "{{ value_json.coordinator }}"; icon = "mdi:chip"; } @@ -64,39 +64,39 @@ in { switch = [ { platform = "mqtt"; - name = "Zigbee2mqtt Main join"; - state_topic = "/zigbee/bridge/config/permit_join"; - command_topic = "/zigbee/bridge/config/permit_join"; + name = "zigbee2mqtt_join"; + state_topic = "/zigbee2mqtt/bridge/config/permit_join"; + command_topic = "/zigbee2mqtt/bridge/config/permit_join"; payload_on = "true"; payload_off = "false"; } ]; automation = [ - { - alias = "Zigbee2mqtt Log Level"; - initial_state = "on"; - trigger = { - platform = "state"; - entity_id = "input_select.zigbee2mqtt_log_level"; - }; - action = [ - { - service = "mqtt.publish"; - data = { - payload_template = "{{ states('input_select.zigbee2mqtt_log_level') }}"; - topic = "/zigbee/bridge/config/log_level"; - }; - } - ]; - } + #{ + # alias = "Zigbee2mqtt Log Level"; + # initial_state = "on"; + # trigger = { + # platform = "state"; + # entity_id = "input_select.zigbee2mqtt_log_level"; + # }; + # action = [ + # { + # service = "mqtt.publish"; + # data = { + # payload_template = "{{ states('input_select.zigbee2mqtt_log_level') }}"; + # topic = "/zigbee2mqtt/bridge/config/log_level"; + # }; + # } + # ]; + #} # Automation to start timer when enable join is turned on { id = "zigbee_join_enabled"; - alias = "Zigbee Join Enabled"; + alias = ""; hide_entity = "true"; trigger = { platform = "state"; - entity_id = "switch.zigbee2mqtt_main_join"; + entity_id = "switch.zigbee2mqtt_join"; to = "on"; }; action = { @@ -107,7 +107,6 @@ in { # Automation to stop timer when switch turned off and turn off switch when timer finished { id = "zigbee_join_disabled"; - alias = "Zigbee Join Disabled"; hide_entity = "true"; trigger = [ { @@ -117,7 +116,7 @@ in { } { platform = "state"; - entity_id = "switch.zigbee2mqtt_main_join"; + entity_id = "switch.zigbee2mqtt_join"; to = "off"; } ]; @@ -126,22 +125,22 @@ in { data.entity_id = "timer.zigbee_permit_join"; } { service = "switch.turn_off"; - entity_id = "switch.zigbee2mqtt_main_join"; + entity_id = "switch.zigbee2mqtt_join"; } ]; } ]; - input_select.zigbee2mqtt_log_level = { - name = "Zigbee2mqtt Log Level"; - options = [ - "debug" - "info" - "warn" - "error" - ]; - initial = "info"; - icon = "mdi:format-list-bulleted"; - }; + #input_select.zigbee2mqtt_log_level = { + # name = "Zigbee2mqtt Log Level"; + # options = [ + # "debug" + # "info" + # "warn" + # "error" + # ]; + # initial = "info"; + # icon = "mdi:format-list-bulleted"; + #}; timer.zigbee_permit_join = { name = "Zigbee Time remaining"; diff --git a/lass/2configs/home-media.nix b/lass/2configs/home-media.nix new file mode 100644 index 000000000..7e10aed34 --- /dev/null +++ b/lass/2configs/home-media.nix @@ -0,0 +1,23 @@ +with import <stockholm/lib>; +{ pkgs, ... }: +{ + users.users.media = { + isNormalUser = true; + uid = genid_uint31 "media"; + extraGroups = [ "video" "audio" ]; + }; + + services.xserver.displayManager.lightdm.autoLogin = { + enable = true; + user = "media"; + }; + + hardware.pulseaudio.configFile = pkgs.writeText "pulse.pa" '' + .include ${pkgs.pulseaudioFull}/etc/pulse/default.pa + load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1;10.42.0.0/24 auth-anonymous=1 + ''; + + krebs.iptables.tables.filter.INPUT.rules = [ + { predicate = "-p tcp --dport 4713"; target = "ACCEPT"; } # pulseaudio + ]; +} |