diff options
author | lassulus <lassulus@lassul.us> | 2021-03-17 15:42:13 +0100 |
---|---|---|
committer | lassulus <lassulus@lassul.us> | 2021-03-17 15:42:13 +0100 |
commit | 3d1472a7cac3ab2c5f9efd06a501368308681999 (patch) | |
tree | 950fbe49dfd060923756dd517c41f27f646857de /makefu/2configs/home/ham/multi | |
parent | f659c1879f6e0a0e9228205edd794aaab467aa0b (diff) | |
parent | 2044ad632b68ce173463287a9f437aae699bda83 (diff) |
Merge remote-tracking branch 'gum/master'
Diffstat (limited to 'makefu/2configs/home/ham/multi')
-rw-r--r-- | makefu/2configs/home/ham/multi/fliegen-couter.nix | 71 | ||||
-rw-r--r-- | makefu/2configs/home/ham/multi/flurlicht.nix | 57 | ||||
-rw-r--r-- | makefu/2configs/home/ham/multi/kurzzeitwecker.nix | 135 | ||||
-rw-r--r-- | makefu/2configs/home/ham/multi/the_playlist.nix | 86 |
4 files changed, 349 insertions, 0 deletions
diff --git a/makefu/2configs/home/ham/multi/fliegen-couter.nix b/makefu/2configs/home/ham/multi/fliegen-couter.nix new file mode 100644 index 000000000..5b8abb2ff --- /dev/null +++ b/makefu/2configs/home/ham/multi/fliegen-couter.nix @@ -0,0 +1,71 @@ +# uses: +# sensor.btn1_click +# sensor.btn2_click +let + hlib = import ../lib; + fly_swat = for: btn: method: incr: { + alias = "Increment ${method} for ${for}"; + trigger = { + platform = "state"; + entity_id = "sensor.${btn}_click"; + to = method; + }; + action = builtins.genList (cnt: { + service = "counter.increment"; + data.entity_id = "counter.${for}_fliegen"; + }) incr; + }; +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"; + } + ]; + } + ]; + }; +} diff --git a/makefu/2configs/home/ham/multi/flurlicht.nix b/makefu/2configs/home/ham/multi/flurlicht.nix new file mode 100644 index 000000000..25eb78b7f --- /dev/null +++ b/makefu/2configs/home/ham/multi/flurlicht.nix @@ -0,0 +1,57 @@ +# provides: +# light +# automation +# binary_sensor +let + hlib = (import ../lib); + tasmota = hlib.tasmota; +in +{ + binary_sensor = [ + (tasmota.motion { name = "Flur Bewegung"; host = "flurlicht";}) + ]; + 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"; + } + ]; + } + ]; +} diff --git a/makefu/2configs/home/ham/multi/kurzzeitwecker.nix b/makefu/2configs/home/ham/multi/kurzzeitwecker.nix new file mode 100644 index 000000000..bd81465cb --- /dev/null +++ b/makefu/2configs/home/ham/multi/kurzzeitwecker.nix @@ -0,0 +1,135 @@ +# Provides: +# timer +# automation +# script + +# Needs: +# sensor.zigbee_btn1_click +# notify.telegrambot +let + button = "sensor.zigbee_btn2_click"; +in +{ + services.home-assistant.config = { + 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"; + } + ]; + } + ]; + }; +} diff --git a/makefu/2configs/home/ham/multi/the_playlist.nix b/makefu/2configs/home/ham/multi/the_playlist.nix new file mode 100644 index 000000000..0d714ea44 --- /dev/null +++ b/makefu/2configs/home/ham/multi/the_playlist.nix @@ -0,0 +1,86 @@ +# Inputs: +# binary_sensor.playlist_button_good +# binary_sensor.playlist_button_bad + +# outputs +# rest_command +# automation +# sensor +{ + services.home-assistant.config = + { + 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"; + }; + 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'] }}''; + }; + }; + } + ]; + }; +} |