From d31fbfe31ee26b70f13c93d910f5ce0d3ce1d8c2 Mon Sep 17 00:00:00 2001 From: makefu Date: Wed, 5 Feb 2020 17:34:44 +0100 Subject: ma 2/homeautomation -> 2/ham avoid overlapping autocomplete with home-manager --- makefu/2configs/ham/default.nix | 225 +++++++++++++++++++++ makefu/2configs/ham/google-muell.nix | 45 +++++ makefu/2configs/ham/lib/default.nix | 318 ++++++++++++++++++++++++++++++ makefu/2configs/ham/mqtt.nix | 24 +++ makefu/2configs/ham/multi/timer.nix | 123 ++++++++++++ makefu/2configs/ham/multi/zigbee2mqtt.nix | 165 ++++++++++++++++ makefu/2configs/ham/sensor/outside.nix | 26 +++ 7 files changed, 926 insertions(+) create mode 100644 makefu/2configs/ham/default.nix create mode 100644 makefu/2configs/ham/google-muell.nix create mode 100644 makefu/2configs/ham/lib/default.nix create mode 100644 makefu/2configs/ham/mqtt.nix create mode 100644 makefu/2configs/ham/multi/timer.nix create mode 100644 makefu/2configs/ham/multi/zigbee2mqtt.nix create mode 100644 makefu/2configs/ham/sensor/outside.nix (limited to 'makefu/2configs/ham') diff --git a/makefu/2configs/ham/default.nix b/makefu/2configs/ham/default.nix new file mode 100644 index 00000000..56acc2d0 --- /dev/null +++ b/makefu/2configs/ham/default.nix @@ -0,0 +1,225 @@ +{ pkgs, lib, config, ... }: + +# Ideas: +## wake-on-lan server +## +let + hlib = (import ./lib); + prefix = hlib.prefix; + tasmota = hlib.tasmota; + firetv = "192.168.1.183"; + kodi-host = firetv; + hassdir = "/var/lib/hass"; + zigbee = import ./multi/zigbee2mqtt.nix; +# switch +# automation +# binary_sensor +# sensor +# input_select +# timer +in { + imports = [ + ./mqtt.nix + ]; + + services.home-assistant = { + config = { + input_select = zigbee.input_select; # dict + timer = zigbee.timer; # dict + homeassistant = { + name = "Home"; time_zone = "Europe/Berlin"; + latitude = "48.7687"; + longitude = "9.2478"; + elevation = 247; + }; + #discovery = {}; + conversation = {}; + history = {}; + logbook = {}; + tts = [ + { platform = "google_translate"; + language = "de"; + time_memory = 57600; + service_name = "google_say"; + } + ]; + + telegram_bot = [ + # secrets file: { + # "platform": "broadcast", + # "api_key": "", # talk to Botfather /newbot + # "allowed_chat_ids": [ ID ] # curl -X GET # https://api.telegram.org/bot/getUpdates + #} + (builtins.fromJSON + (builtins.readFile )) + ]; + notify = [ + { + platform = "kodi"; + name = "wohnzimmer"; + host = kodi-host; + } + { + platform = "telegram"; + name = "telegrambot"; + chat_id = builtins.elemAt + (builtins.fromJSON (builtins.readFile + )).allowed_chat_ids 0; + } + ]; + sun.elevation = 247; + recorder = {}; + media_player = [ + { platform = "kodi"; + host = firetv; + } + { platform = "firetv"; + name = "FireTV Stick"; + host = firetv; + adbkey = ; + } + ]; + mqtt = { + broker = "localhost"; + port = 1883; + client_id = "home-assistant"; + username = "hass"; + password = lib.removeSuffix "\n" (builtins.readFile ); + keepalive = 60; + protocol = 3.1; + birth_message = { + topic = "${prefix}/hass/tele/LWT"; + payload = "Online"; + qos = 1; + retain = true; + }; + will_message = { + topic = "${prefix}/hass/tele/LWT"; + payload = "Offline"; + qos = 1; + retain = true; + }; + }; + binary_sensor = [ + (tasmota.motion { name = "Flur Bewegung"; host = "flurlicht";}) + ] ++ zigbee.binary_sensor; + sensor = [ + # broken + #{ 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"; }); + frontend = { }; + group = + { default_view = + { view = "yes"; + entities = [ + "group.flur" + "group.schlafzimmer" + "group.draussen" + "group.wohnzimmer" + "group.arbeitszimmer" + ]; + }; + flur = [ + "light.flurlicht" + "binary_sensor.flur_bewegung" + "automation.dunkel_bei_sonnenuntergang" + "automation.hell_bei_sonnenaufgang" + ]; + wohnzimmer = [ + "media_player.kodi" + "media_player.firetv_stick" + ]; + draussen = [ + "sensor.dark_sky_temperature" + "sensor.dark_sky_hourly_summary" + "sensor.dark_sky_humidity" + "sensor.dark_sky_pressure" + "sensor.muehlhausen_pm10" + "sensor.muehlhausen_pm25" + ]; + schlafzimmer = [ + "sensor.schlafzimmer_temperatur" + "sensor.schlafzimmer_luftdruck" + "sensor.schlafzimmer_luftfeuchtigkeit" + "switch.lichterkette_schlafzimmer" + ]; + arbeitszimmer = [ + "switch.strom_staubsauger" + "sensor.arbeitszimmer_temperatur" + "sensor.arbeitszimmer_luftfeuchtigkeit" + ]; + }; + 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; + }; + enable = true; + configDir = hassdir; + }; + +} diff --git a/makefu/2configs/ham/google-muell.nix b/makefu/2configs/ham/google-muell.nix new file mode 100644 index 00000000..c81eae20 --- /dev/null +++ b/makefu/2configs/ham/google-muell.nix @@ -0,0 +1,45 @@ +{ config, lib, pkgs, buildPythonPackage, ... }: +with import ; +let + pkg = pkgs.ampel; + home = "/var/lib/ampel"; + sec = "${toString }/ampel/google-muell.json"; + ampelsec = "${home}/google-muell.json"; + cred = "${toString }/ampel/google-muell-creds.json"; + # TODO: generate this credential file locally + ampelcred = "${home}/google-muell-creds.json"; + sleepval = "1800"; + # default-color = "18,63,40"; + default-color = "255,127,0"; + config_json = toFile "config.json" (toJSON { + mq_hostname = "localhost"; + mq_port = 1883; + mq_username = "sensor"; + mq_topic = "/ham/flurlicht/cmnd/MEM1"; + mq_password = replaceChars ["\n"] [""] (readFile "${toString }/mqtt/sensor"); + }); +in { + users.users.ampel = { + uid = genid "ampel"; + createHome = true; + isSystemUser = true; + inherit home; + }; + systemd.services.google-muell-ampel = { + description = "Send led change to rgb cubes"; + after = [ "network-online.target" ]; + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + User = "ampel"; + ExecStartPre = pkgs.writeDash "copy-ampel-secrets" '' + install -m600 -o ampel ${sec} ${ampelsec} + install -m600 -o ampel ${cred} ${ampelcred} + ''; + ExecStart = "${pkg}/bin/google-muell --config ${config_json} --default-color=${default-color} --client-secrets=${ampelsec} --credential-path=${ampelcred} --sleepval=${sleepval}"; + PermissionsStartOnly = true; + Restart = "always"; + RestartSec = 10; + PrivateTmp = true; + }; + }; +} diff --git a/makefu/2configs/ham/lib/default.nix b/makefu/2configs/ham/lib/default.nix new file mode 100644 index 00000000..8bc54431 --- /dev/null +++ b/makefu/2configs/ham/lib/default.nix @@ -0,0 +1,318 @@ +let + prefix = "/ham"; +in +{ + inherit prefix; + say = let + # returns a list of actions to be performed on an mpd to say something + tts = { message, entity }: + [ + { + service = "media_player.turn_on"; + data.entity_id = entity; + } + { + service = "media_player.play_media"; + data = { + entity_id = entity; + media_content_type = "playlist"; + media_content_id = "ansage"; + }; + } + { + service = "media_player.turn_on"; + data.entity_id = entity; + } + { delay.seconds = 8; } + { + service = "tts.say"; + entity_id = entity; + data_template = { + inherit message; + language = "de"; + }; + } + ]; + in + { + firetv = message: tts { + inherit message; + entity = "firetv"; + }; + }; + zigbee = let + prefix = "/ham/zigbee"; + in + { + inherit prefix; + state = name: { + platform = "mqtt"; + name = "zigbee ${name} connectivity"; + state_topic = "${prefix}/${name}"; + availability_topic = "${prefix}/bridge/state"; + payload_on = true; + payload_off = false; + value_template = "{{ value_json.state }}"; + device_class = "connectivity"; + }; + battery = name: { + platform = "mqtt"; + name = "zigbee ${name} battery"; + state_topic = "${prefix}/${name}"; + availability_topic = "${prefix}/bridge/state"; + unit_of_measurement = "%"; + device_class = "battery"; + value_template = "{{ value_json.battery }}"; + }; + linkquality = name: { + platform = "mqtt"; + name = "zigbee ${name} linkquality"; + state_topic = "${prefix}/${name}"; + availability_topic = "${prefix}/bridge/state"; + unit_of_measurement = "-"; + value_template = "{{ value_json.linkquality }}"; + }; + temperature = name: { + platform = "mqtt"; + name = "zigbee ${name} temperature"; + state_topic = "${prefix}/${name}"; + availability_topic = "${prefix}/bridge/state"; + unit_of_measurement = "°C"; + device_class = "temperature"; + value_template = "{{ value_json.temperature }}"; + }; + humidity = name: { + platform = "mqtt"; + name = "zigbee ${name} humidity"; + state_topic = "${prefix}/${name}"; + availability_topic = "${prefix}/bridge/state"; + unit_of_measurement = "%"; + device_class = "humidity"; + value_template = "{{ value_json.humidity }}"; + }; + pressure = name: { + platform = "mqtt"; + state_topic = "${prefix}/${name}"; + name = "zigbee ${name} pressure"; + availability_topic = "${prefix}/bridge/state"; + unit_of_measurement = "hPa"; + device_class = "pressure"; + value_template = "{{ value_json.pressure }}" ; + }; + click = name: + { + platform = "mqtt"; + name = "zigbee ${name} click"; + state_topic = "${prefix}/${name}"; + availability_topic = "${prefix}/bridge/state"; + icon = "mdi:toggle-switch"; + value_template = "{{ value_json.click }}"; + }; + contact = name: { + platform = "mqtt"; + name = "zigbee ${name} contact"; + state_topic = "${prefix}/${name}"; + availability_topic = "${prefix}/bridge/state"; + payload_on = false; + payload_off = true; + value_template = "{{ value_json.contact }}"; + device_class = "door"; + }; + }; + esphome = + { + temp = {host, topic ? "temperature" }: + { + platform = "mqtt"; + name = "${host} Temperature"; + device_class = "temperature"; + unit_of_measurement = "°C"; + icon = "mdi:thermometer"; + state_topic = "${prefix}/${host}/sensor/${topic}/state"; + availability_topic = "${prefix}/${host}/status"; + payload_available = "online"; + payload_not_available = "offline"; + }; + hum = {host, topic ? "humidity" }: + { + platform = "mqtt"; + unit_of_measurement = "%"; + icon = "mdi:water-percent"; + device_class = "humidity"; + name = "${host} Humidity"; + state_topic = "${prefix}/${host}/sensor/${topic}/state"; + availability_topic = "${prefix}/${host}/status"; + payload_available = "online"; + payload_not_available = "offline"; + }; + # copied from "homeassistant/light/fablab_led/led_ring/config" + led = {host, topic ? "led", name ? host}: + { # name: fablab_led + # topic: led_ring + platform = "mqtt"; + inherit name; + schema = "json"; + brightness = true; + rgb = true; + effect = true; + effect_list = [ # TODO: may be different + "Random" + "Strobe" + "Rainbow" + "Color Wipe" + "Scan" + "Twinkle" + "Fireworks" + "Addressable Flicker" + "None" + ]; + state_topic = "${prefix}/${host}/light/${topic}/state"; + command_topic = "${prefix}/${host}/light/${topic}/command"; + availability_topic = "${prefix}/${host}/status"; + payload_available = "online"; + payload_not_available = "offline"; + qos = 1; + }; + # Feinstaub + dust_25m = { host, name ? "${host} < 2.5µm", topic ? "particulate_matter_25m_concentration" }: + { + platform = "mqtt"; + unit_of_measurement = "µg/m³"; + icon = "mdi:chemical-weapon"; + inherit name; + state_topic = "${prefix}/${host}/sensor/${topic}/state"; + availability_topic = "${prefix}/${host}/status"; + }; + dust_100m = {host, name ? "${host} < 10µm", topic ? "particulate_matter_100m_concentration" }: + { + platform = "mqtt"; + unit_of_measurement = "µg/m³"; + icon = "mdi:chemical-weapon"; + inherit name; + state_topic = "${prefix}/${host}/sensor/${topic}/state"; + availability_topic = "${prefix}/${host}/status"; + }; + ip = {host, name ? "${host} IP", topic ? "ip_address" }: + { + platform = "mqtt"; + inherit name; + state_topic = "${prefix}/${host}/sensor/${topic}/state"; + availability_topic = "${prefix}/${host}/status"; + }; + wifi = {host, name ? "${host} Wifi Signal", topic ? "wifi_signal" }: + { + platform = "mqtt"; + unit_of_measurement = "dB"; + icon = "mdi:wifi"; + inherit name; + state_topic = "${prefix}/${host}/sensor/${topic}/state"; + availability_topic = "${prefix}/${host}/status"; + }; + switch = {host, name ? "${host} Button", topic ? "btn" }: + # host: ampel + # name: Button 1 + # topic: btn1 + { + inherit name; + platform = "mqtt"; + state_topic = "${prefix}/${host}/sensor/${topic}/state"; + command_topic = "${prefix}/${host}/switch/${topic}/state"; + availability_topic = "${prefix}/${host}/status"; + }; + }; + tasmota = + { + plug = {host, name ? host, topic ? host}: + { + platform = "mqtt"; + inherit name; + state_topic = "sonoff/stat/${topic}/POWER1"; + command_topic = "sonoff/cmnd/${topic}/POWER1"; + availability_topic = "sonoff/tele/${topic}/LWT"; + payload_on= "ON"; + payload_off= "OFF"; + payload_available= "Online"; + payload_not_available= "Offline"; + retain = false; + qos = 1; + }; + am2301 = { name, host, topic?host }: + [ { platform = "mqtt"; + name = "${name} Temperatur"; + state_topic = "${prefix}/${topic}/tele/SENSOR"; + value_template = "{{ value_json.AM2301.Temperature }}"; + unit_of_measurement = "°C"; + } + { platform = "mqtt"; + name = "${name} Luftfeuchtigkeit"; + state_topic = "${prefix}/${topic}/tele/SENSOR"; + value_template = "{{ value_json.AM2301.Humidity }}"; + unit_of_measurement = "%"; + } + ]; + bme = { name, host, topic?host }: + [ { platform = "mqtt"; + name = "${name} Temperatur"; + state_topic = "${prefix}/${topic}/tele/SENSOR"; + value_template = "{{ value_json.BME280.Temperature }}"; + unit_of_measurement = "°C"; + } + { platform = "mqtt"; + name = "${name} Luftfeuchtigkeit"; + state_topic = "${prefix}/${topic}/tele/SENSOR"; + value_template = "{{ value_json.BME280.Humidity }}"; + unit_of_measurement = "%"; + } + { platform = "mqtt"; + name = "${name} Luftdruck"; + state_topic = "${prefix}/${topic}/tele/SENSOR"; + value_template = "{{ value_json.BME280.Pressure }}"; + unit_of_measurement = "hPa"; + } + ]; + rgb = { name, host, topic?host }: + { platform = "mqtt"; + inherit name; + retain = false; + qos = 1; + optimistic = false; + # state + # TODO: currently broken, will not use the custom state topic + #state_topic = "${prefix}/${topic}/stat/POWER"; + state_topic = "${prefix}/${topic}/stat/POWER"; + command_topic = "${prefix}/${topic}/cmnd/POWER"; + availability_topic = "${prefix}/${topic}/tele/LWT"; + payload_on= "ON"; + payload_off= "OFF"; + payload_available= "Online"; + payload_not_available= "Offline"; + # brightness + brightness_state_topic = "${prefix}/${topic}/stat/Dimmer"; + brightness_command_topic = "${prefix}/${topic}/cmnd/Dimmer"; + brightness_value_template = "{{ value_json.Dimmer }}"; + brightness_scale = 100; + # color + rgb_state_topic = "${prefix}/${topic}/stat/Color"; + rgb_command_topic = "${prefix}/${topic}/cmnd/MEM1"; # use enabled rule + rgb_command_mode = "hex"; + rgb_command_template = "{{ '%02x%02x%02x' | format(red, green, blue)}}"; + # effects + effect_state_topic = "${prefix}/${topic}/stat/Scheme"; + effect_command_topic = "${prefix}/${topic}/cmnd/Scheme"; + effect_value_template = "{{ value_json.Scheme }}"; + effect_list = [ 0 1 2 3 4 5 6 7 8 9 10 11 12 ]; +}; + motion = { name, host, topic?host }: + { platform = "mqtt"; + device_class = "motion"; + inherit name; + # TODO: currently broken, will not use the custom state topic + state_topic = "${prefix}/${topic}/stat/POWER"; + payload_on = "ON"; + payload_off = "OFF"; + availability_topic = "${prefix}/${topic}/tele/LWT"; + payload_available = "Online"; + payload_not_available = "Offline"; + }; + }; +} diff --git a/makefu/2configs/ham/mqtt.nix b/makefu/2configs/ham/mqtt.nix new file mode 100644 index 00000000..cd1c328d --- /dev/null +++ b/makefu/2configs/ham/mqtt.nix @@ -0,0 +1,24 @@ +{ pkgs, config, ... }: +{ + services.mosquitto = { + enable = true; + host = "0.0.0.0"; + allowAnonymous = false; + checkPasswords = true; + # see /mosquitto + users.sensor = { + hashedPassword = "$6$2DXU7W1bvqXPqxkF$vtdz5KTd/T09hmoc9LjgEGFjvpwQbQth6vlVcr5hJNLgcBHv4U03YCKC8TKXbmQAa8xiJ76xJIg25kcL+KI3tg=="; + acl = [ "topic readwrite #" ]; + }; + users.hass = { + hashedPassword = "$6$SHuYGrE5kPSUc/hu$EomZ0KBy+vkxLt/6eJkrSBjYblCCeMjhDfUd2mwqXYJ4XsP8hGmZ59mMlmBCd3AvlFYQxb4DT/j3TYlrqo7cDA=="; + acl = [ "topic readwrite #" ]; + }; + users.stats = { + hashedPassword = "$6$j4H7KXD/YZgvgNmL$8e9sUKRXowDqJLOVgzCdDrvDE3+4dGgU6AngfAeN/rleGOgaMhee2Mbg2KS5TC1TOW3tYbk9NhjLYtjBgfRkoA=="; + acl = [ "topic read #" ]; + }; + }; + environment.systemPackages = [ pkgs.mosquitto ]; + # port open via trusted interface +} diff --git a/makefu/2configs/ham/multi/timer.nix b/makefu/2configs/ham/multi/timer.nix new file mode 100644 index 00000000..eafb7841 --- /dev/null +++ b/makefu/2configs/ham/multi/timer.nix @@ -0,0 +1,123 @@ +# Provides: +# timer +# automation +# script + +# Needs: +# sensor.zigbee_btn1_click +# notify.telegrambot +let + button = "sensor.zigbee_btn1_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.wecker', '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"; + duration = "00:05:00"; + } + { + service = "notify.telegrambot"; + data = { + title = "Timer gestartet"; + message = "Timer auf 5 minuten gestellt"; + }; + } + ]; + } + { + alias = "Start Timer 10min"; + trigger = { + platform = "state"; + entity_id = button; + to = "double"; + }; + condition = + { + condition = "state"; + entity_id = "timer.kurzzeitwecker"; + state = "idle"; + }; + action = + [ + { + service = "timer.start"; + entity_id = "timer.kurzzeitwecker"; + duration = "00:10:00"; + } + { + service = "notify.telegrambot"; + data = { + title = "Timer gestartet"; + message = "Timer auf 10 minuten gestellt"; + }; + } + ]; + } + { + alias = "Stop timer on triple click"; + trigger = + { + platform = "state"; + entity_id = button; + to = "triple"; + }; + condition = + { + condition = "state"; + entity_id = "timer.kurzzeitwecker"; + state = "active"; + }; + + action = [ + { + service = "timer.stop"; + entity_id = "timer.kurzzeitwecker"; + } + { + service = "notify.telegrambot"; + data = { + title = "Timer gestoppt"; + }; + } + ]; + } + ]; +} diff --git a/makefu/2configs/ham/multi/zigbee2mqtt.nix b/makefu/2configs/ham/multi/zigbee2mqtt.nix new file mode 100644 index 00000000..ba81b129 --- /dev/null +++ b/makefu/2configs/ham/multi/zigbee2mqtt.nix @@ -0,0 +1,165 @@ +# provides: +# switch +# automation +# binary_sensor +# sensor +# input_select +# timer +let + inherit (import ../lib) zigbee; + prefix = zigbee.prefix; + xiaomi_btn = name: [ + (zigbee.battery name) + (zigbee.linkquality name) + (zigbee.click name) + ]; + xiaomi_temp = name: [ + (zigbee.battery name) + (zigbee.linkquality name) + (zigbee.temperature name) + (zigbee.humidity name) + (zigbee.pressure name) + ]; + xiaomi_contact = name: [ + (zigbee.battery name) + (zigbee.linkquality name) + (zigbee.contact name) + ]; + router_link = name: [ + (zigbee.linkquality name) + ]; + router_bin = name: [ + (zigbee.state name) + ]; +in { + sensor = + (xiaomi_btn "btn1") + ++ (xiaomi_btn "btn2") + ++ (xiaomi_btn "btn3") + + ++ (xiaomi_temp "temp1") + ++ (xiaomi_temp "temp2") + ++ (xiaomi_temp "temp3") + + ++ (router_link "router1") + ++ (router_link "router2") + + ++ [ + # Sensor for monitoring the bridge state + { + platform = "mqtt"; + name = "Zigbee2mqtt Bridge state"; + state_topic = "${prefix}/bridge/state"; + icon = "mdi:router-wireless"; + } + # Sensor for Showing the Zigbee2mqtt Version + { + platform = "mqtt"; + name = "Zigbee2mqtt Version"; + state_topic = "${prefix}/bridge/config"; + value_template = "{{ value_json.version }}"; + icon = "mdi:zigbee"; + } + # Sensor for Showing the Coordinator Version + { + platform = "mqtt"; + name = "Coordinator Version"; + state_topic = "${prefix}/bridge/config"; + value_template = "{{ value_json.coordinator }}"; + icon = "mdi:chip"; + } + ]; + binary_sensor = + (router_bin "router1") + ++ (router_bin "router2"); + switch = [ + { + platform = "mqtt"; + name = "Zigbee2mqtt Main join"; + state_topic = "${prefix}/bridge/config/permit_join"; + command_topic = "${prefix}/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 = "${prefix}/bridge/config/log_level"; + }; + } + ]; + } +# Automation to start timer when enable join is turned on + { + id = "zigbee_join_enabled"; + alias = "Zigbee Join Enabled"; + hide_entity = "true"; + trigger = + { + platform = "state"; + entity_id = "switch.zigbee2mqtt_main_join"; + to = "on"; + }; + action = + { + service = "timer.start"; + entity_id = "timer.zigbee_permit_join"; + }; + } +# # 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 = [ + { + platform = "event"; + event_type = "timer.finished"; + event_data.entity_id = "timer.zigbee_permit_join"; + } + { + platform = "state"; + entity_id = "switch.zigbee2mqtt_main_join"; + to = "off"; + } + ]; + action = [ + { service = "timer.cancel"; + data.entity_id = "timer.zigbee_permit_join"; + } + { service = "switch.turn_off"; + entity_id = "switch.zigbee2mqtt_main_join"; + } + ]; + } + ]; + 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"; + duration = 120; + }; +} diff --git a/makefu/2configs/ham/sensor/outside.nix b/makefu/2configs/ham/sensor/outside.nix new file mode 100644 index 00000000..8436b8de --- /dev/null +++ b/makefu/2configs/ham/sensor/outside.nix @@ -0,0 +1,26 @@ +{lib,...}: [ + { platform = "darksky"; + api_key = lib.removeSuffix "\n" + (builtins.readFile ); + language = "de"; + monitored_conditions = [ + "summary" "icon" + "nearest_storm_distance" "precip_probability" + "precip_intensity" + "temperature" # "temperature_high" "temperature_low" + "apparent_temperature" + "hourly_summary" # next 24 hours text + "humidity" + "pressure" + "uv_index" + ]; + units = "si" ; + scan_interval = "00:30:00"; + } + { platform = "luftdaten"; + name = "Muehlhausen"; + show_on_map = true; + sensor_id = "679"; + sensors.monitored_conditions = [ "P1" "P2" ]; + } + ] -- cgit v1.2.3 From 910686f65623aaccfcf55b91b538441bfbbec5d9 Mon Sep 17 00:00:00 2001 From: makefu Date: Mon, 24 Feb 2020 16:55:34 +0100 Subject: ma ham/esphome: init --- makefu/2configs/ham/default.nix | 112 +++++++---------------- makefu/2configs/ham/multi/esphome.nix | 45 +++++++++ makefu/2configs/ham/multi/kurzzeitwecker.nix | 132 +++++++++++++++++++++++++++ 3 files changed, 211 insertions(+), 78 deletions(-) create mode 100644 makefu/2configs/ham/multi/esphome.nix create mode 100644 makefu/2configs/ham/multi/kurzzeitwecker.nix (limited to 'makefu/2configs/ham') diff --git a/makefu/2configs/ham/default.nix b/makefu/2configs/ham/default.nix index 56acc2d0..1a65ba62 100644 --- a/makefu/2configs/ham/default.nix +++ b/makefu/2configs/ham/default.nix @@ -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 = ; + 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; diff --git a/makefu/2configs/ham/multi/esphome.nix b/makefu/2configs/ham/multi/esphome.nix new file mode 100644 index 00000000..8ca12d89 --- /dev/null +++ b/makefu/2configs/ham/multi/esphome.nix @@ -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; +} diff --git a/makefu/2configs/ham/multi/kurzzeitwecker.nix b/makefu/2configs/ham/multi/kurzzeitwecker.nix new file mode 100644 index 00000000..03d0d5aa --- /dev/null +++ b/makefu/2configs/ham/multi/kurzzeitwecker.nix @@ -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"; + } + ]; + } + ]; +} -- cgit v1.2.3 From bcbc9ad90304a7bc86018e1fdb08c12feb33f17f Mon Sep 17 00:00:00 2001 From: makefu Date: Mon, 24 Feb 2020 16:56:42 +0100 Subject: ma ham/esphome: rip, replaced with autodiscovery --- makefu/2configs/ham/default.nix | 10 +++----- makefu/2configs/ham/multi/esphome.nix | 45 ----------------------------------- 2 files changed, 3 insertions(+), 52 deletions(-) delete mode 100644 makefu/2configs/ham/multi/esphome.nix (limited to 'makefu/2configs/ham') diff --git a/makefu/2configs/ham/default.nix b/makefu/2configs/ham/default.nix index 1a65ba62..de9fa6be 100644 --- a/makefu/2configs/ham/default.nix +++ b/makefu/2configs/ham/default.nix @@ -12,7 +12,6 @@ let zigbee = import ./multi/zigbee2mqtt.nix; flurlicht = import ./multi/flurlicht.nix; kurzzeitwecker = import ./multi/kurzzeitwecker.nix; - esphome = import ./multi/esphome.nix; # switch # automation # binary_sensor @@ -34,7 +33,7 @@ in { longitude = "9.2478"; elevation = 247; }; - #discovery = {}; + discovery = {}; conversation = {}; history = {}; logbook = {}; @@ -110,7 +109,6 @@ in { }; binary_sensor = zigbee.binary_sensor - ++ esphome.binary_sensor ++ flurlicht.binary_sensor; sensor = [ { platform = "speedtest"; @@ -119,10 +117,9 @@ in { # https://www.home-assistant.io/cookbook/automation_for_rainy_days/ ] ++ ((import ./sensor/outside.nix) {inherit lib;}) - ++ esphome.sensor ++ zigbee.sensor ; frontend = { }; - light = flurlicht.light ++ esphome.light; + light = flurlicht.light; group = { default_view = { view = "yes"; @@ -166,8 +163,7 @@ in { }; http = { }; switch = - esphome.switch - ++ zigbee.switch; + zigbee.switch; automation = flurlicht.automation ++ kurzzeitwecker.automation diff --git a/makefu/2configs/ham/multi/esphome.nix b/makefu/2configs/ham/multi/esphome.nix deleted file mode 100644 index 8ca12d89..00000000 --- a/makefu/2configs/ham/multi/esphome.nix +++ /dev/null @@ -1,45 +0,0 @@ -# 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; -} -- cgit v1.2.3 From 843ee70248752c7b3fc656807bd12b6e6f21f0e1 Mon Sep 17 00:00:00 2001 From: makefu Date: Mon, 24 Feb 2020 16:59:11 +0100 Subject: ma ham/zigbee2mqtt: configuration with discovery in mind --- makefu/2configs/ham/default.nix | 6 +- makefu/2configs/ham/lib/default.nix | 275 ---------------------------- makefu/2configs/ham/zigbee2mqtt/default.nix | 31 ++++ 3 files changed, 33 insertions(+), 279 deletions(-) create mode 100644 makefu/2configs/ham/zigbee2mqtt/default.nix (limited to 'makefu/2configs/ham') diff --git a/makefu/2configs/ham/default.nix b/makefu/2configs/ham/default.nix index de9fa6be..ae0c46ba 100644 --- a/makefu/2configs/ham/default.nix +++ b/makefu/2configs/ham/default.nix @@ -108,8 +108,7 @@ in { sensors.monitored_conditions = [ "P1" "P2" ]; }; binary_sensor = - zigbee.binary_sensor - ++ flurlicht.binary_sensor; + flurlicht.binary_sensor; sensor = [ { platform = "speedtest"; monitored_conditions = [ "ping" "download" "upload" ]; @@ -162,8 +161,7 @@ in { ]; }; http = { }; - switch = - zigbee.switch; + switch = []; automation = flurlicht.automation ++ kurzzeitwecker.automation diff --git a/makefu/2configs/ham/lib/default.nix b/makefu/2configs/ham/lib/default.nix index 8bc54431..c2d7916c 100644 --- a/makefu/2configs/ham/lib/default.nix +++ b/makefu/2configs/ham/lib/default.nix @@ -40,279 +40,4 @@ in entity = "firetv"; }; }; - zigbee = let - prefix = "/ham/zigbee"; - in - { - inherit prefix; - state = name: { - platform = "mqtt"; - name = "zigbee ${name} connectivity"; - state_topic = "${prefix}/${name}"; - availability_topic = "${prefix}/bridge/state"; - payload_on = true; - payload_off = false; - value_template = "{{ value_json.state }}"; - device_class = "connectivity"; - }; - battery = name: { - platform = "mqtt"; - name = "zigbee ${name} battery"; - state_topic = "${prefix}/${name}"; - availability_topic = "${prefix}/bridge/state"; - unit_of_measurement = "%"; - device_class = "battery"; - value_template = "{{ value_json.battery }}"; - }; - linkquality = name: { - platform = "mqtt"; - name = "zigbee ${name} linkquality"; - state_topic = "${prefix}/${name}"; - availability_topic = "${prefix}/bridge/state"; - unit_of_measurement = "-"; - value_template = "{{ value_json.linkquality }}"; - }; - temperature = name: { - platform = "mqtt"; - name = "zigbee ${name} temperature"; - state_topic = "${prefix}/${name}"; - availability_topic = "${prefix}/bridge/state"; - unit_of_measurement = "°C"; - device_class = "temperature"; - value_template = "{{ value_json.temperature }}"; - }; - humidity = name: { - platform = "mqtt"; - name = "zigbee ${name} humidity"; - state_topic = "${prefix}/${name}"; - availability_topic = "${prefix}/bridge/state"; - unit_of_measurement = "%"; - device_class = "humidity"; - value_template = "{{ value_json.humidity }}"; - }; - pressure = name: { - platform = "mqtt"; - state_topic = "${prefix}/${name}"; - name = "zigbee ${name} pressure"; - availability_topic = "${prefix}/bridge/state"; - unit_of_measurement = "hPa"; - device_class = "pressure"; - value_template = "{{ value_json.pressure }}" ; - }; - click = name: - { - platform = "mqtt"; - name = "zigbee ${name} click"; - state_topic = "${prefix}/${name}"; - availability_topic = "${prefix}/bridge/state"; - icon = "mdi:toggle-switch"; - value_template = "{{ value_json.click }}"; - }; - contact = name: { - platform = "mqtt"; - name = "zigbee ${name} contact"; - state_topic = "${prefix}/${name}"; - availability_topic = "${prefix}/bridge/state"; - payload_on = false; - payload_off = true; - value_template = "{{ value_json.contact }}"; - device_class = "door"; - }; - }; - esphome = - { - temp = {host, topic ? "temperature" }: - { - platform = "mqtt"; - name = "${host} Temperature"; - device_class = "temperature"; - unit_of_measurement = "°C"; - icon = "mdi:thermometer"; - state_topic = "${prefix}/${host}/sensor/${topic}/state"; - availability_topic = "${prefix}/${host}/status"; - payload_available = "online"; - payload_not_available = "offline"; - }; - hum = {host, topic ? "humidity" }: - { - platform = "mqtt"; - unit_of_measurement = "%"; - icon = "mdi:water-percent"; - device_class = "humidity"; - name = "${host} Humidity"; - state_topic = "${prefix}/${host}/sensor/${topic}/state"; - availability_topic = "${prefix}/${host}/status"; - payload_available = "online"; - payload_not_available = "offline"; - }; - # copied from "homeassistant/light/fablab_led/led_ring/config" - led = {host, topic ? "led", name ? host}: - { # name: fablab_led - # topic: led_ring - platform = "mqtt"; - inherit name; - schema = "json"; - brightness = true; - rgb = true; - effect = true; - effect_list = [ # TODO: may be different - "Random" - "Strobe" - "Rainbow" - "Color Wipe" - "Scan" - "Twinkle" - "Fireworks" - "Addressable Flicker" - "None" - ]; - state_topic = "${prefix}/${host}/light/${topic}/state"; - command_topic = "${prefix}/${host}/light/${topic}/command"; - availability_topic = "${prefix}/${host}/status"; - payload_available = "online"; - payload_not_available = "offline"; - qos = 1; - }; - # Feinstaub - dust_25m = { host, name ? "${host} < 2.5µm", topic ? "particulate_matter_25m_concentration" }: - { - platform = "mqtt"; - unit_of_measurement = "µg/m³"; - icon = "mdi:chemical-weapon"; - inherit name; - state_topic = "${prefix}/${host}/sensor/${topic}/state"; - availability_topic = "${prefix}/${host}/status"; - }; - dust_100m = {host, name ? "${host} < 10µm", topic ? "particulate_matter_100m_concentration" }: - { - platform = "mqtt"; - unit_of_measurement = "µg/m³"; - icon = "mdi:chemical-weapon"; - inherit name; - state_topic = "${prefix}/${host}/sensor/${topic}/state"; - availability_topic = "${prefix}/${host}/status"; - }; - ip = {host, name ? "${host} IP", topic ? "ip_address" }: - { - platform = "mqtt"; - inherit name; - state_topic = "${prefix}/${host}/sensor/${topic}/state"; - availability_topic = "${prefix}/${host}/status"; - }; - wifi = {host, name ? "${host} Wifi Signal", topic ? "wifi_signal" }: - { - platform = "mqtt"; - unit_of_measurement = "dB"; - icon = "mdi:wifi"; - inherit name; - state_topic = "${prefix}/${host}/sensor/${topic}/state"; - availability_topic = "${prefix}/${host}/status"; - }; - switch = {host, name ? "${host} Button", topic ? "btn" }: - # host: ampel - # name: Button 1 - # topic: btn1 - { - inherit name; - platform = "mqtt"; - state_topic = "${prefix}/${host}/sensor/${topic}/state"; - command_topic = "${prefix}/${host}/switch/${topic}/state"; - availability_topic = "${prefix}/${host}/status"; - }; - }; - tasmota = - { - plug = {host, name ? host, topic ? host}: - { - platform = "mqtt"; - inherit name; - state_topic = "sonoff/stat/${topic}/POWER1"; - command_topic = "sonoff/cmnd/${topic}/POWER1"; - availability_topic = "sonoff/tele/${topic}/LWT"; - payload_on= "ON"; - payload_off= "OFF"; - payload_available= "Online"; - payload_not_available= "Offline"; - retain = false; - qos = 1; - }; - am2301 = { name, host, topic?host }: - [ { platform = "mqtt"; - name = "${name} Temperatur"; - state_topic = "${prefix}/${topic}/tele/SENSOR"; - value_template = "{{ value_json.AM2301.Temperature }}"; - unit_of_measurement = "°C"; - } - { platform = "mqtt"; - name = "${name} Luftfeuchtigkeit"; - state_topic = "${prefix}/${topic}/tele/SENSOR"; - value_template = "{{ value_json.AM2301.Humidity }}"; - unit_of_measurement = "%"; - } - ]; - bme = { name, host, topic?host }: - [ { platform = "mqtt"; - name = "${name} Temperatur"; - state_topic = "${prefix}/${topic}/tele/SENSOR"; - value_template = "{{ value_json.BME280.Temperature }}"; - unit_of_measurement = "°C"; - } - { platform = "mqtt"; - name = "${name} Luftfeuchtigkeit"; - state_topic = "${prefix}/${topic}/tele/SENSOR"; - value_template = "{{ value_json.BME280.Humidity }}"; - unit_of_measurement = "%"; - } - { platform = "mqtt"; - name = "${name} Luftdruck"; - state_topic = "${prefix}/${topic}/tele/SENSOR"; - value_template = "{{ value_json.BME280.Pressure }}"; - unit_of_measurement = "hPa"; - } - ]; - rgb = { name, host, topic?host }: - { platform = "mqtt"; - inherit name; - retain = false; - qos = 1; - optimistic = false; - # state - # TODO: currently broken, will not use the custom state topic - #state_topic = "${prefix}/${topic}/stat/POWER"; - state_topic = "${prefix}/${topic}/stat/POWER"; - command_topic = "${prefix}/${topic}/cmnd/POWER"; - availability_topic = "${prefix}/${topic}/tele/LWT"; - payload_on= "ON"; - payload_off= "OFF"; - payload_available= "Online"; - payload_not_available= "Offline"; - # brightness - brightness_state_topic = "${prefix}/${topic}/stat/Dimmer"; - brightness_command_topic = "${prefix}/${topic}/cmnd/Dimmer"; - brightness_value_template = "{{ value_json.Dimmer }}"; - brightness_scale = 100; - # color - rgb_state_topic = "${prefix}/${topic}/stat/Color"; - rgb_command_topic = "${prefix}/${topic}/cmnd/MEM1"; # use enabled rule - rgb_command_mode = "hex"; - rgb_command_template = "{{ '%02x%02x%02x' | format(red, green, blue)}}"; - # effects - effect_state_topic = "${prefix}/${topic}/stat/Scheme"; - effect_command_topic = "${prefix}/${topic}/cmnd/Scheme"; - effect_value_template = "{{ value_json.Scheme }}"; - effect_list = [ 0 1 2 3 4 5 6 7 8 9 10 11 12 ]; -}; - motion = { name, host, topic?host }: - { platform = "mqtt"; - device_class = "motion"; - inherit name; - # TODO: currently broken, will not use the custom state topic - state_topic = "${prefix}/${topic}/stat/POWER"; - payload_on = "ON"; - payload_off = "OFF"; - availability_topic = "${prefix}/${topic}/tele/LWT"; - payload_available = "Online"; - payload_not_available = "Offline"; - }; - }; } diff --git a/makefu/2configs/ham/zigbee2mqtt/default.nix b/makefu/2configs/ham/zigbee2mqtt/default.nix new file mode 100644 index 00000000..cb1f80d8 --- /dev/null +++ b/makefu/2configs/ham/zigbee2mqtt/default.nix @@ -0,0 +1,31 @@ +{config, pkgs, lib, ...}: + +let + pkg = pkgs.callPackage ./zigbee2mqtt.nix { }; +in + +{ + #users.users.z2m = { + # extraGroups = [ "dialout" ]; + #}; + + services.udev.extraRules = '' + SUBSYSTEM=="tty", ATTRS{idVendor}=="0451", ATTRS{idProduct}=="16a8", SYMLINK+="cc2531", MODE="0660", GROUP="dailout" + ''; + #systemd.services.zigbee2mqtt = { + # wantedBy = ["multi-user.target" ]; + # after = [ "network.target" ]; + # description = "Run zigbee2mqtt as daemon"; + # environment.ZIGBEE2MQTT_DATA = "/var/lib/zigbee2mqtt"; + # serviceConfig = { + # WorkingDirectory = ''${pkg}/lib/node_modules/zigbee2mqtt''; + # ExecStart = ''${pkgs.nodejs-12_x}/bin/node index.js''; + # StandardOutput = "inherit"; + # StandardError = "inherit"; + # Restart = "always"; + # User = "z2m"; + # StateDirectory = "zigbee2mqtt"; + # #DeviceAllow = "/dev/cc2531 rw"; + # }; + #}; +} -- cgit v1.2.3 From 2563c59e73dfe9df7b98d5b184785f3a5936ca17 Mon Sep 17 00:00:00 2001 From: makefu Date: Tue, 3 Mar 2020 21:12:51 +0100 Subject: ma ham: use home-assistant from unstable, enable androidtv support --- makefu/2configs/ham/androidtv/adbshell.nix | 38 +++++++++++++ makefu/2configs/ham/androidtv/default.nix | 30 ++++++++++ makefu/2configs/ham/androidtv/purepythonadb.nix | 21 +++++++ makefu/2configs/ham/automation/firetv_restart.nix | 26 +++++++++ makefu/2configs/ham/default.nix | 67 +++++++---------------- 5 files changed, 134 insertions(+), 48 deletions(-) create mode 100644 makefu/2configs/ham/androidtv/adbshell.nix create mode 100644 makefu/2configs/ham/androidtv/default.nix create mode 100644 makefu/2configs/ham/androidtv/purepythonadb.nix create mode 100644 makefu/2configs/ham/automation/firetv_restart.nix (limited to 'makefu/2configs/ham') diff --git a/makefu/2configs/ham/androidtv/adbshell.nix b/makefu/2configs/ham/androidtv/adbshell.nix new file mode 100644 index 00000000..f5b96c85 --- /dev/null +++ b/makefu/2configs/ham/androidtv/adbshell.nix @@ -0,0 +1,38 @@ +{ lib +, buildPythonPackage +, fetchPypi +, cryptography +, pyasn1 +, rsa +, pycryptodome +}: + +buildPythonPackage rec { + pname = "adb_shell"; + version = "0.0.8"; + + src = fetchPypi { + inherit pname version; + sha256 = "01f9jinhfyjldg9793gz2i7gcd9xyx0a62r7a5ijssklcnn2rwnm"; + }; + + propagatedBuildInputs = [ + cryptography + pyasn1 + rsa + ]; + + # tests are not part of pypi package + doCheck = false; + + checkInputs = [ + pycryptodome + ]; + + meta = with lib; { + description = "A Python implementation of ADB with shell and FileSync functionality"; + homepage = https://github.com/JeffLIrion/adb_shell/; + license = licenses.mit; + # maintainers = [ maintainers. ]; + }; +} diff --git a/makefu/2configs/ham/androidtv/default.nix b/makefu/2configs/ham/androidtv/default.nix new file mode 100644 index 00000000..8f3bdc1f --- /dev/null +++ b/makefu/2configs/ham/androidtv/default.nix @@ -0,0 +1,30 @@ +{ lib +, buildPythonPackage +, callPackage +, fetchPypi +}: + +buildPythonPackage rec { + pname = "androidtv"; + version = "0.0.34"; + + src = fetchPypi { + inherit pname version; + sha256 = "13078i2a9hglpv4ldycph5n5485np21vs6z2qn830hybmx8kfxsw"; + }; + + propagatedBuildInputs = [ + (callPackage ./adbshell.nix {}) + (callPackage ./purepythonadb.nix {}) + ]; + + # tests are not packaged in pypi release + doCheck = false; + + meta = with lib; { + description = "Communicate with an Android TV or Fire TV device via ADB over a network"; + homepage = https://github.com/JeffLIrion/python-androidtv/; + license = licenses.mit; + # maintainers = [ maintainers. ]; + }; +} diff --git a/makefu/2configs/ham/androidtv/purepythonadb.nix b/makefu/2configs/ham/androidtv/purepythonadb.nix new file mode 100644 index 00000000..d4e763b7 --- /dev/null +++ b/makefu/2configs/ham/androidtv/purepythonadb.nix @@ -0,0 +1,21 @@ +{ lib +, buildPythonPackage +, fetchPypi +}: + +buildPythonPackage rec { + pname = "pure-python-adb"; + version = "0.2.3.dev0"; + + src = fetchPypi { + inherit pname version; + sha256 = "88e5a4578435197799aa368fb1a5d87fe43e02a888cb7e85c2ad66173b383c89"; + }; + + meta = with lib; { + description = "Pure python implementation of the adb client"; + homepage = https://github.com/Swind/pure-python-adb; + license = licenses.mit; + # maintainers = [ maintainers. ]; + }; +} \ No newline at end of file diff --git a/makefu/2configs/ham/automation/firetv_restart.nix b/makefu/2configs/ham/automation/firetv_restart.nix new file mode 100644 index 00000000..779092c7 --- /dev/null +++ b/makefu/2configs/ham/automation/firetv_restart.nix @@ -0,0 +1,26 @@ +[ + { + alias = "Nightly reboot of firetv"; + trigger = { + platform = "time"; + at = "03:00:00"; + }; + action = [ + { + service = "androidtv.adb_command"; + data = { + entity_id = "media_player.firetv_stick"; + command = "reboot"; + }; + } + { delay.minutes = 2; } + { + service = "media_player.select_source"; + data = { + entity_id = "media_player.firetv_stick"; + source = "com.amazon.bueller.music"; + }; + } + ]; + } +] diff --git a/makefu/2configs/ham/default.nix b/makefu/2configs/ham/default.nix index ae0c46ba..3fbe1187 100644 --- a/makefu/2configs/ham/default.nix +++ b/makefu/2configs/ham/default.nix @@ -4,13 +4,14 @@ ## wake-on-lan server ## let + upkgs = (import {}).pkgs; hlib = (import ./lib); prefix = hlib.prefix; tasmota = hlib.tasmota; firetv_stick = "192.168.1.24"; hassdir = "/var/lib/hass"; zigbee = import ./multi/zigbee2mqtt.nix; - flurlicht = import ./multi/flurlicht.nix; + #flurlicht = import ./multi/flurlicht.nix; kurzzeitwecker = import ./multi/kurzzeitwecker.nix; # switch # automation @@ -24,6 +25,13 @@ in { ]; services.home-assistant = { + package = (upkgs.home-assistant.overrideAttrs (old: { + })).override { + extraPackages = ps: with ps; [ + python-forecastio jsonrpc-async jsonrpc-websocket mpd2 pkgs.picotts + (ps.callPackage ./androidtv {}) + ]; + }; config = { input_select = zigbee.input_select; # dict timer = zigbee.timer // kurzzeitwecker.timer; # dict @@ -71,7 +79,7 @@ in { sun.elevation = 247; recorder = {}; media_player = [ - { platform = "kodi"; + { platform = "FireTV Stick kodi"; host = firetv_stick; } { platform = "androidtv"; @@ -79,10 +87,13 @@ in { device_class = "firetv"; # adb_server_ip = firetv_stick; host = firetv_stick; + port = 5555; } ]; mqtt = { broker = "localhost"; + discovery = true; #enable esphome discovery + discovery_prefix = "homeassistant"; port = 1883; client_id = "home-assistant"; username = "hass"; @@ -107,8 +118,8 @@ in { sensor_id = 679; sensors.monitored_conditions = [ "P1" "P2" ]; }; - binary_sensor = - flurlicht.binary_sensor; + #binary_sensor = + # flurlicht.binary_sensor; sensor = [ { platform = "speedtest"; monitored_conditions = [ "ping" "download" "upload" ]; @@ -118,53 +129,13 @@ in { ++ ((import ./sensor/outside.nix) {inherit lib;}) ++ zigbee.sensor ; frontend = { }; - light = flurlicht.light; - group = - { default_view = - { view = "yes"; - entities = [ - "group.flur" - "group.schlafzimmer" - "group.draussen" - "group.wohnzimmer" - "group.arbeitszimmer" - ]; - }; - flur = [ - "light.flurlicht" - "binary_sensor.flur_bewegung" - "automation.dunkel_bei_sonnenuntergang" - "automation.hell_bei_sonnenaufgang" - ]; - wohnzimmer = [ - "media_player.kodi" - "media_player.firetv_stick" - ]; - draussen = [ - "sensor.dark_sky_temperature" - "sensor.dark_sky_hourly_summary" - "sensor.dark_sky_humidity" - "sensor.dark_sky_pressure" - "sensor.muehlhausen_pm10" - "sensor.muehlhausen_pm25" - ]; - schlafzimmer = [ - "sensor.schlafzimmer_temperatur" - "sensor.schlafzimmer_luftdruck" - "sensor.schlafzimmer_luftfeuchtigkeit" - "switch.lichterkette_schlafzimmer" - ]; - arbeitszimmer = [ - "switch.strom_staubsauger" - "sensor.arbeitszimmer_temperatur" - "sensor.arbeitszimmer_luftfeuchtigkeit" - ]; - }; + # light = flurlicht.light; http = { }; switch = []; automation = - flurlicht.automation - ++ kurzzeitwecker.automation + (import ./automation/firetv_restart.nix) + kurzzeitwecker.automation + #++ flurlicht.automation ++ zigbee.automation; script = kurzzeitwecker.script; # dict }; -- cgit v1.2.3 From e1d6406fbd7be66bd4a2ebd08c568a19ee09f906 Mon Sep 17 00:00:00 2001 From: makefu Date: Tue, 3 Mar 2020 21:17:43 +0100 Subject: ma ham/zigbee2mqtt: giving up docker-container that shit away --- makefu/2configs/ham/zigbee2mqtt/default.nix | 35 ++++++++++------------------- 1 file changed, 12 insertions(+), 23 deletions(-) (limited to 'makefu/2configs/ham') diff --git a/makefu/2configs/ham/zigbee2mqtt/default.nix b/makefu/2configs/ham/zigbee2mqtt/default.nix index cb1f80d8..7c55326f 100644 --- a/makefu/2configs/ham/zigbee2mqtt/default.nix +++ b/makefu/2configs/ham/zigbee2mqtt/default.nix @@ -1,31 +1,20 @@ {config, pkgs, lib, ...}: -let - pkg = pkgs.callPackage ./zigbee2mqtt.nix { }; -in { - #users.users.z2m = { - # extraGroups = [ "dialout" ]; - #}; - + # symlink the zigbee controller services.udev.extraRules = '' SUBSYSTEM=="tty", ATTRS{idVendor}=="0451", ATTRS{idProduct}=="16a8", SYMLINK+="cc2531", MODE="0660", GROUP="dailout" ''; - #systemd.services.zigbee2mqtt = { - # wantedBy = ["multi-user.