diff options
author | makefu <github@syntax-fehler.de> | 2023-07-28 22:24:15 +0200 |
---|---|---|
committer | makefu <github@syntax-fehler.de> | 2023-07-28 22:24:15 +0200 |
commit | 060a8f28fa1fc648bdf66afb31a5d1efac868837 (patch) | |
tree | 2b354eacc7897365ee45244fe7a51720e0d0333f /makefu/2configs/home/ham/lib | |
parent | cbfcc890e3b76d942b927809bf981a5fa7289e6a (diff) |
makefu: move out to own repo, add vacation-note
Diffstat (limited to 'makefu/2configs/home/ham/lib')
-rw-r--r-- | makefu/2configs/home/ham/lib/cheat-sheet.nix | 42 | ||||
-rw-r--r-- | makefu/2configs/home/ham/lib/default.nix | 134 |
2 files changed, 0 insertions, 176 deletions
diff --git a/makefu/2configs/home/ham/lib/cheat-sheet.nix b/makefu/2configs/home/ham/lib/cheat-sheet.nix deleted file mode 100644 index f593ef4ec..000000000 --- a/makefu/2configs/home/ham/lib/cheat-sheet.nix +++ /dev/null @@ -1,42 +0,0 @@ -# Begin -let -in { - services.home-assistant.config.automation = - [ - ]; -} - -# example automation - { alias = ""; - trigger = [ - { - platform = "state"; - entity_id = ""; - to = "on"; - for.seconds = 0; - } - ]; - condition = [ - { condition = "state"; - entity_id = ""; - state = "off"; - } - ]; - action = - [ - { choose = [ - { - conditions = { - condition = "state"; - entity_id = ""; - state = "on"; - }; - sequence = [{ - service = "home_assistant.turn_on"; - target.entity_id = ""; - }]; - }]; - default = { }; - } - ]; - } diff --git a/makefu/2configs/home/ham/lib/default.nix b/makefu/2configs/home/ham/lib/default.nix deleted file mode 100644 index 0d89d1e9e..000000000 --- a/makefu/2configs/home/ham/lib/default.nix +++ /dev/null @@ -1,134 +0,0 @@ -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 = "sonos.snapshot"; - target.entity_id = entity; - } - { - service = "tts.google_say"; - data = { - entity_id = entity; - inherit message; - language = "de"; - }; - } - #{ wait_template = "{{ is_state('${entity}' , 'playing') }}"; - # timeout = "00:00:02"; - #} - #{ wait_template = "{{ not is_state('${entity}' , 'playing') }}"; - # timeout = "00:01:00"; - #} - { delay.seconds = 1; } - { delay = '' - {% set duration = state_attr("${entity}","media_duration") or 0 %} - {% set seconds = (duration % 60 ) %} - {% set minutes = (duration / 60)|int % 60 %} - {% set hours = (duration / 3600)|int %} - {{ "%02i:%02i:%02i"|format(hours, minutes, seconds)}} - ''; - } - { - service = "sonos.restore"; - target.entity_id = entity; - } - ]; - in - { - living_room = message: tts { - inherit message; - entity = "media_player.living_room"; - }; - office = message: tts { - inherit message; - entity = "media_player.office"; - }; - bedroom = message: tts { - inherit message; - entity = "media_player.bedroom"; - }; - }; - - zigbee.prefix = "/ham/zigbee"; - - btn_cycle_light = light: btn: halfbright: - let - maxbright = 255; - transition = 0.2; # seconds - in - # this function implements a simple state machine based on the state and brightness of the light (light must support brightness - { - alias = "Cycle through states of ${light} via button ${btn}"; - trigger = { - platform = "state"; - entity_id = "sensor.${btn}_click"; - to = "single"; - }; - action = { - choose = [ - { - # state 0: off to half - conditions = { - condition = "template"; - value_template = ''{{ states("${light}") == "off" }}''; - }; - sequence = [ - { - service = "light.turn_on"; - data = { - entity_id = light; - brightness = halfbright; - }; - } - ]; - } - { - # state 1: half to full - conditions = { - condition = "template"; - value_template = ''{{ states('${light}') == 'on' and ( ${toString (halfbright - 1)} <= state_attr("${light}","brightness") <= ${toString (halfbright + 1)})}}''; - }; - sequence = [ - { - service = "light.turn_on"; - data = { - entity_id = light; - brightness = maxbright; - }; - } - ]; - } - { - # state 2: full to off - conditions = { - condition = "template"; - # TODO: it seems like the devices respond with brightness-1 , maybe off-by-one somewhere? - value_template = ''{{ states("${light}") == "on" and state_attr("${light}","brightness") >= ${toString (maxbright - 1)}}}''; - }; - sequence = [ - { - service = "light.turn_off"; - data = { - entity_id = light; - }; - } - ]; - } - ]; - # default: on to off - # this works because state 0 checks for "state == off" - default = [{ - service = "light.turn_off"; - data = { - entity_id = light; - }; - }]; - }; - }; -} |