diff options
author | makefu <github@syntax-fehler.de> | 2022-06-06 21:07:52 +0200 |
---|---|---|
committer | makefu <github@syntax-fehler.de> | 2022-06-06 21:07:52 +0200 |
commit | 2047429a2e858c438c5b81508910ae9d195e0301 (patch) | |
tree | a2cc73bcbf0ad796b2e7d2ae4c85093c72e84ac2 /makefu/2configs/home/ham/media | |
parent | 54869b752d3f5724679f84ed6f0896a03c578ab5 (diff) |
ma ham: reenabel giesskanne
Diffstat (limited to 'makefu/2configs/home/ham/media')
-rw-r--r-- | makefu/2configs/home/ham/media/remote_sound_arbeitszimmer.nix | 107 | ||||
-rw-r--r-- | makefu/2configs/home/ham/media/sonos.nix | 1 |
2 files changed, 108 insertions, 0 deletions
diff --git a/makefu/2configs/home/ham/media/remote_sound_arbeitszimmer.nix b/makefu/2configs/home/ham/media/remote_sound_arbeitszimmer.nix new file mode 100644 index 000000000..f59f022f4 --- /dev/null +++ b/makefu/2configs/home/ham/media/remote_sound_arbeitszimmer.nix @@ -0,0 +1,107 @@ +{ lib, ...}: +let + statecond = cond: { # cond must be a list + condition = "template"; + value_template = "{{ trigger.to_state.state in ( " + + (lib.concatMapStringsSep "," (x: "'${x}'") cond) + ") }}"; + }; + vol_change = 0.030; + + max_repeat = "30"; # max loops to repeat before bailing out + remote = "sensor.arbeitszimmer_sound1_action"; + player = "media_player.office"; + last_state_sensor_name = "last_rotation_action_arbeitszimmer"; + last_state_sensor = "input_text.${last_state_sensor_name}"; + # - service: media_player.volume_set + # target: + # entity_id: media_player.kitchen + # data: + # volume_level: {{ state_attr('media_player.kitchen', 'volume_level') + 0.02 }} + rotate_stop = "brightness_stop"; + rotate_right = "brightness_move_up"; + rotate_left = "brightness_move_down" ; + + single_click = "toggle"; + double_click = "brightness_step_up"; + triple_click = "brightness_step_down"; +in { + services.home-assistant.config.input_text."${last_state_sensor_name}".name = "Last action of the arbeitszimmer"; + services.home-assistant.config.automation = [ + { + trigger = { + platform = "state"; + entity_id = remote; + to = [ rotate_stop ]; + }; + action = [ + { service = "input_text.set_value"; + target.entity_id = last_state_sensor; + data.value = "stop"; + } + ]; + } + { + alias = "Perform Actions with ${remote}"; + trigger = { + platform = "state"; + entity_id = remote; + to = [ single_click double_click triple_click rotate_left rotate_right ]; + }; + #mode = "queued"; + #max = 5; + mode = "single"; + #max_exceeded = "silent"; + action = [ + { + choose = [ + { + conditions = statecond [ single_click ]; + sequence = [ + { service = "media_player.media_play_pause"; + target.entity_id = player; + } + ]; + } + { + conditions = statecond [ rotate_left rotate_right ]; + sequence = let + vol_up = toString vol_change; + vol_down = toString (-1 * vol_change); + in [ + { + variables.nextvol = ''{% if trigger.to_state.state in ( "${rotate_left}" ) -%} ${vol_down} {% else -%} ${vol_up} {% endif -%}''; + variables.state = ''{% if trigger.to_state.state in ( "${rotate_left}" ) -%} left {% else -%} right {% endif -%}''; + } + { service = "input_text.set_value"; + target.entity_id = last_state_sensor; + data.value = ''{{ state }}''; + } + { + repeat = { + sequence = [ + { service = "media_player.volume_set"; + target.entity_id = player; + data.volume_level = ''{{ state_attr("${player}","volume_level") + (nextvol|float) }}''; + } + { delay.milliseconds = "150"; } + ]; + while = [ + { + condition = "template"; + value_template = ''{{ states("${last_state_sensor}") == state }}''; + } + { + condition = "template"; + value_template = "{{ repeat.index <= ${max_repeat}}}"; + } + ]; + }; + } + ]; + } + ]; + } + ]; + } + ]; +} diff --git a/makefu/2configs/home/ham/media/sonos.nix b/makefu/2configs/home/ham/media/sonos.nix index 5b9694512..40dcfc3ca 100644 --- a/makefu/2configs/home/ham/media/sonos.nix +++ b/makefu/2configs/home/ham/media/sonos.nix @@ -2,6 +2,7 @@ services.home-assistant.config.sonos.media_player.hosts = [ "192.168.111.30" "192.168.111.31" + "192.168.111.32" ]; } |