From 78fc347be0a0b680bd39a72ac94418d211f5d777 Mon Sep 17 00:00:00 2001 From: makefu Date: Wed, 18 Nov 2020 22:23:33 +0100 Subject: ma ham: use new home-assistant merge function --- makefu/2configs/ham/automation/firetv_restart.nix | 52 ++--- makefu/2configs/ham/calendar/nextcloud.nix | 11 +- makefu/2configs/ham/default.nix | 66 ++----- makefu/2configs/ham/device_tracker/openwrt.nix | 23 ++- makefu/2configs/ham/multi/fliegen-couter.nix | 100 +++++----- makefu/2configs/ham/multi/kurzzeitwecker.nix | 223 +++++++++++----------- makefu/2configs/ham/multi/the_playlist.nix | 139 +++++++------- makefu/2configs/ham/sensor/outside.nix | 45 +++-- makefu/2configs/ham/zigbee2mqtt/osram.nix | 14 ++ 9 files changed, 342 insertions(+), 331 deletions(-) create mode 100644 makefu/2configs/ham/zigbee2mqtt/osram.nix (limited to 'makefu') diff --git a/makefu/2configs/ham/automation/firetv_restart.nix b/makefu/2configs/ham/automation/firetv_restart.nix index 1094d177..9ae46987 100644 --- a/makefu/2configs/ham/automation/firetv_restart.nix +++ b/makefu/2configs/ham/automation/firetv_restart.nix @@ -7,27 +7,31 @@ let }; }; sec = seconds: { delay.seconds = seconds; }; -in [ - { - alias = "Nightly reboot of firetv"; - trigger = { - platform = "time"; - at = "03:00:00"; - }; - action = [ - (cmd "reboot") - (sec 90) # go to my music because apparently select_source does not seem to always work - (cmd "HOME") - (sec 2) - (cmd "DOWN") - (sec 2) - (cmd "DOWN") - (sec 2) - (cmd "ENTER") - (sec 4) - (cmd "RIGHT") - (sec 2) - (cmd "RIGHT") - ]; - } -] +in +{ + services.home-assistant.config.sensor = + [ + { + alias = "Nightly reboot of firetv"; + trigger = { + platform = "time"; + at = "03:00:00"; + }; + action = [ + (cmd "reboot") + (sec 90) # go to my music because apparently select_source does not seem to always work + (cmd "HOME") + (sec 2) + (cmd "DOWN") + (sec 2) + (cmd "DOWN") + (sec 2) + (cmd "ENTER") + (sec 4) + (cmd "RIGHT") + (sec 2) + (cmd "RIGHT") + ]; + } + ]; +} diff --git a/makefu/2configs/ham/calendar/nextcloud.nix b/makefu/2configs/ham/calendar/nextcloud.nix index 0be23ad7..80e51b34 100644 --- a/makefu/2configs/ham/calendar/nextcloud.nix +++ b/makefu/2configs/ham/calendar/nextcloud.nix @@ -2,7 +2,12 @@ let cred = import ; in { - platform = "caldav"; - inherit (cred) username password; - url = "https://o.euer.krebsco.de/remote.php/dav"; + services.home-assistant.config.calendar = + [ + { + platform = "caldav"; + inherit (cred) username password; + url = "https://o.euer.krebsco.de/remote.php/dav"; + } + ]; } diff --git a/makefu/2configs/ham/default.nix b/makefu/2configs/ham/default.nix index 3a6d1952..44a36c0a 100644 --- a/makefu/2configs/ham/default.nix +++ b/makefu/2configs/ham/default.nix @@ -4,39 +4,27 @@ ## wake-on-lan server ## let - upkgs = (import {}).pkgs; - hlib = (import ./lib); - prefix = hlib.prefix; - tasmota = hlib.tasmota; + prefix = (import ./lib).prefix; 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; - firetv_restart = import ./multi/firetv_restart.nix; - the_playlist = import ./multi/the_playlist.nix; - fliegen-counter = import ./multi/fliegen-couter.nix; -# switch -# automation -# binary_sensor -# sensor -# input_select -# timer in { imports = [ ./mqtt.nix + ./zigbee2mqtt/default.nix + + # hass config + ./zigbee2mqtt/hass.nix + # ./multi/flurlicht.nix + ./multi/kurzzeitwecker.nix + ./multi/the_playlist.nix + ./multi/fliegen-couter.nix + ./device_tracker/openwrt.nix + ./sensor/outside.nix + ./calendar/nextcloud.nix + ./automation/firetv_restart.nix ]; services.home-assistant = { - package = (upkgs.home-assistant.overrideAttrs (old: { - doCheck = false; - checkPhase = ":"; - installCheckPhase = ":"; - })).override { - extraPackages = ps: with ps; [ - python-forecastio jsonrpc-async jsonrpc-websocket mpd2 pkgs.picotts androidtv - ]; - }; config = { influxdb = { database = "ham"; @@ -48,8 +36,6 @@ in { }; config = {}; - input_select = zigbee.input_select; # dict - timer = zigbee.timer // kurzzeitwecker.timer; # dict homeassistant = { name = "Home"; time_zone = "Europe/Berlin"; latitude = "48.7687"; @@ -60,12 +46,10 @@ in { conversation = {}; history = {}; logbook = {}; - counter = fliegen-counter.counter; logger = { default = "info"; }; - rest_command = {} - // the_playlist.rest_command; + rest_command = {}; tts = [ { platform = "google_translate"; language = "de"; @@ -81,7 +65,7 @@ in { # "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 )) ]; @@ -101,7 +85,6 @@ in { ]; sun.elevation = 247; recorder = {}; - device_tracker = (import ./device_tracker/openwrt.nix); media_player = [ { platform = "FireTV Stick kodi"; host = firetv_stick; @@ -149,25 +132,12 @@ in { monitored_conditions = [ "ping" "download" "upload" ]; } # https://www.home-assistant.io/cookbook/automation_for_rainy_days/ - ] - ++ ((import ./sensor/outside.nix) {inherit lib;}) - ++ the_playlist.sensor - ++ zigbee.sensor ; + ]; frontend = { }; - calendar = [ (import ./calendar/nextcloud.nix) ]; - # light = flurlicht.light; http = { }; switch = []; - automation = [] - ++ (import ./automation/firetv_restart.nix) - ++ kurzzeitwecker.automation - #++ flurlicht.automation - ++ the_playlist.automation - ++ fliegen-counter.automation - ++ zigbee.automation; - script = - { } - // kurzzeitwecker.script; # dict + automation = []; + script = { }; }; enable = true; configDir = hassdir; diff --git a/makefu/2configs/ham/device_tracker/openwrt.nix b/makefu/2configs/ham/device_tracker/openwrt.nix index 8173fcfc..0a34f702 100644 --- a/makefu/2configs/ham/device_tracker/openwrt.nix +++ b/makefu/2configs/ham/device_tracker/openwrt.nix @@ -1,10 +1,13 @@ -[ - { platform = "luci"; - host = "192.168.1.5"; - username = "root"; - password = import ; - interval_seconds = 30; # instead of 12seconds - consider_home = 300; # 5 minutes timeout - new_device_defaults.track_new_devices = true; - } -] +{ + services.home-assistant.config.device_tracker = + [ + { platform = "luci"; + host = "192.168.1.5"; + username = "root"; + password = import ; + interval_seconds = 30; # instead of 12seconds + consider_home = 300; # 5 minutes timeout + new_device_defaults.track_new_devices = true; + } + ]; +} diff --git a/makefu/2configs/ham/multi/fliegen-couter.nix b/makefu/2configs/ham/multi/fliegen-couter.nix index d5c180e0..5b8abb2f 100644 --- a/makefu/2configs/ham/multi/fliegen-couter.nix +++ b/makefu/2configs/ham/multi/fliegen-couter.nix @@ -15,53 +15,57 @@ let data.entity_id = "counter.${for}_fliegen"; }) incr; }; -in { - counter = { - felix_fliegen = {}; - misa_fliegen = {}; +in +{ + services.home-assistant.config = + { + counter = { + felix_fliegen = {}; + misa_fliegen = {}; + }; + automation = [ + (fly_swat "misa" "btn1" "single" 1) + (fly_swat "misa" "btn1" "double" 2) + (fly_swat "misa" "btn1" "triple" 3) + (fly_swat "felix" "btn2" "single" 1) + (fly_swat "felix" "btn2" "double" 2) + (fly_swat "felix" "btn2" "triple" 3) + { + alias = "Send Fly Counter Update"; + trigger = [ + { + platform = "state"; + entity_id = "counter.felix_fliegen"; + } + { + platform = "state"; + entity_id = "counter.misa_fliegen"; + #above = -1; + } + ]; + action = { + service = "mqtt.publish"; + data_template = { # gauge-style + payload = "{{ trigger.to_state.state }}"; + topic = "${hlib.prefix}/flycounter/{{ trigger.to_state.object_id }}"; + }; + }; + } + { + alias = "Reset Fly counters on midnight"; + trigger = { + platform = "time"; + at = "01:00:00"; + }; + action = [ + { service = "counter.reset"; + data.entity_id = "counter.misa_fliegen"; + } + { service = "counter.reset"; + data.entity_id = "counter.felix_fliegen"; + } + ]; + } + ]; }; - automation = [ - (fly_swat "misa" "btn1" "single" 1) - (fly_swat "misa" "btn1" "double" 2) - (fly_swat "misa" "btn1" "triple" 3) - (fly_swat "felix" "btn2" "single" 1) - (fly_swat "felix" "btn2" "double" 2) - (fly_swat "felix" "btn2" "triple" 3) - { - alias = "Send Fly Counter Update"; - trigger = [ - { - platform = "state"; - entity_id = "counter.felix_fliegen"; - } - { - platform = "state"; - entity_id = "counter.misa_fliegen"; - #above = -1; - } - ]; - action = { - service = "mqtt.publish"; - data_template = { # gauge-style - payload = "{{ trigger.to_state.state }}"; - topic = "${hlib.prefix}/flycounter/{{ trigger.to_state.object_id }}"; - }; - }; - } - { - alias = "Reset Fly counters on midnight"; - trigger = { - platform = "time"; - at = "01:00:00"; - }; - action = [ - { service = "counter.reset"; - data.entity_id = "counter.misa_fliegen"; - } - { service = "counter.reset"; - data.entity_id = "counter.felix_fliegen"; - } - ]; - } - ]; } diff --git a/makefu/2configs/ham/multi/kurzzeitwecker.nix b/makefu/2configs/ham/multi/kurzzeitwecker.nix index 03d0d5aa..bd81465c 100644 --- a/makefu/2configs/ham/multi/kurzzeitwecker.nix +++ b/makefu/2configs/ham/multi/kurzzeitwecker.nix @@ -8,125 +8,128 @@ # 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 = - [ +in +{ + services.home-assistant.config = { + timer.kurzzeitwecker = { - 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"; + 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"; - state = "active"; + } + { 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) }} + ''; }; - - 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 = [ - { + }; + automation = + [ + { + alias = "Start Timer 5min"; + trigger = { platform = "state"; entity_id = button; - to = "double"; - } - { + 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 = "triple"; - } - ]; - condition = - { - condition = "state"; - entity_id = "timer.kurzzeitwecker"; - state = "active"; - }; + to = "single"; + }; + 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 = [ + 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 = { - service = "notify.telegrambot"; - data.message = "Timer beendet"; - } - ]; - } - ]; + 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"; + } + ]; + } + ]; + }; } diff --git a/makefu/2configs/ham/multi/the_playlist.nix b/makefu/2configs/ham/multi/the_playlist.nix index ad090938..0d714ea4 100644 --- a/makefu/2configs/ham/multi/the_playlist.nix +++ b/makefu/2configs/ham/multi/the_playlist.nix @@ -7,77 +7,80 @@ # automation # sensor { - rest_command = { - good_song = { - url = "http://prism.r:8001/good"; - method = "POST"; - }; - bad_song = { - url = "http://prism.r:8001/skip"; - method = "POST"; - }; - }; - automation = [ - { - alias = "playlist song publish"; - trigger = { - #platform = "event"; - #event_data.entity_id = "sensor.the_playlist_song"; - platform = "state"; - entity_id = "sensor.the_playlist_song"; - }; - action = { - service = "mqtt.publish"; - data = { - topic = "/ham/the_playlist/song"; - payload_template = "{{ states.sensor.the_playlist_song.state }}"; - }; - }; - } - { - alias = "playlist upvote on button"; - trigger = { - platform = "state"; - entity_id = "binary_sensor.playlist_button_good"; - from = "off"; - to = "on"; + services.home-assistant.config = + { + rest_command = { + good_song = { + url = "http://prism.r:8001/good"; + method = "POST"; }; - action.service = "rest_command.good_song"; - } - { - alias = "playlist downvote on button"; - trigger = { - platform = "state"; - entity_id = "binary_sensor.playlist_button_bad"; - from = "off"; - to = "on"; + bad_song = { + url = "http://prism.r:8001/skip"; + method = "POST"; }; - action.service = "rest_command.bad_song"; - } - ]; - sensor = [ - { platform = "rest"; - name = "pl"; - resource = "http://prism.r:8001/current"; - scan_interval = 30; - value_template = "1"; - json_attributes = [ "name" "filename" "youtube" ]; - } - { platform = "template"; - sensors = { - the_playlist_song = { - friendly_name = "Current Song"; - value_template = ''{{ states.sensor.pl.attributes['name'] }}''; + }; + automation = [ + { + alias = "playlist song publish"; + trigger = { + #platform = "event"; + #event_data.entity_id = "sensor.the_playlist_song"; + platform = "state"; + entity_id = "sensor.the_playlist_song"; }; - the_playlist_url = { - friendly_name = "Song Youtube URL"; - value_template = ''{{ states.sensor.pl.attributes['youtube'] }}''; + action = { + service = "mqtt.publish"; + data = { + topic = "/ham/the_playlist/song"; + payload_template = "{{ states.sensor.the_playlist_song.state }}"; + }; }; - the_playlist_filename = { - friendly_name = "Song Filename"; - value_template = ''{{ states.sensor.pl.attributes['filename'] }}''; + } + { + alias = "playlist upvote on button"; + trigger = { + platform = "state"; + entity_id = "binary_sensor.playlist_button_good"; + from = "off"; + to = "on"; }; - }; - } - ]; + action.service = "rest_command.good_song"; + } + { + alias = "playlist downvote on button"; + trigger = { + platform = "state"; + entity_id = "binary_sensor.playlist_button_bad"; + from = "off"; + to = "on"; + }; + action.service = "rest_command.bad_song"; + } + ]; + sensor = [ + { platform = "rest"; + name = "pl"; + resource = "http://prism.r:8001/current"; + scan_interval = 30; + value_template = "1"; + json_attributes = [ "name" "filename" "youtube" ]; + } + { platform = "template"; + sensors = { + the_playlist_song = { + friendly_name = "Current Song"; + value_template = ''{{ states.sensor.pl.attributes['name'] }}''; + }; + the_playlist_url = { + friendly_name = "Song Youtube URL"; + value_template = ''{{ states.sensor.pl.attributes['youtube'] }}''; + }; + the_playlist_filename = { + friendly_name = "Song Filename"; + value_template = ''{{ states.sensor.pl.attributes['filename'] }}''; + }; + }; + } + ]; + }; } diff --git a/makefu/2configs/ham/sensor/outside.nix b/makefu/2configs/ham/sensor/outside.nix index c46b35ba..332746be 100644 --- a/makefu/2configs/ham/sensor/outside.nix +++ b/makefu/2configs/ham/sensor/outside.nix @@ -1,20 +1,25 @@ -{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"; - } - ] +{lib,...}: + +{ + services.home-assistant.config.sensor = + [ + { 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"; + } + ]; +} diff --git a/makefu/2configs/ham/zigbee2mqtt/osram.nix b/makefu/2configs/ham/zigbee2mqtt/osram.nix new file mode 100644 index 00000000..d1bf2b29 --- /dev/null +++ b/makefu/2configs/ham/zigbee2mqtt/osram.nix @@ -0,0 +1,14 @@ +{ + + +availability_topic: /ham/zigbee/bridge/state +command_topic: /ham/zigbee/flur_arbeitszimmer_osram2/set + + - platform: "mqtt" + state_topic: "zigbee2mqtt/" + availability_topic: "zigbee2mqtt/bridge/state" + payload_on: true + payload_off: false + value_template: "{{ value_json.battery_low}}" + device_class: "battery" +} -- cgit v1.2.3