Appologies that this probably falls into RTFM but I am super lost and after many days of going in circles I had to get some pointers.
I have a monoprice zone amp and a bunch of lutron pico remotes. All I am trying to do is map a button press to an action. (in a somewhat efficient way because I will end up with 12 remotes and 6 zones)
I was able to get a remote talking to a zone using automations and a WHOLE bunch of chained IF / THEN logic brute force style.
I know theres a better way. I am guessing that scripts is probably how but I just don’t event know where I am going wrong. or if it is even what I should be using.
When I make an automation with the following logic, it works. but I think it will end up too messy to do at scale.
- id: '1662140620804'
alias: Audio Test Remote
description: ''
trigger:
- platform: state
entity_id:
- sensor.remotes_test
condition: []
action:
- if:
- condition: state
entity_id: sensor.remotes_test
state: '2'
then:
- service: media_player.toggle
data: {}
target:
entity_id: media_player.zone_11
- if:
- condition: state
entity_id: sensor.remotes_test
state: '4'
then:
- if:
- condition: state
entity_id: media_player.zone_11
attribute: source
state: '1'
then:
- service: media_player.select_source
data:
source: '2'
target:
entity_id: media_player.zone_11
else:
- service: media_player.select_source
data:
source: '1'
target:
entity_id: media_player.zone_11
- if:
- condition: state
entity_id: sensor.remotes_test
state: '8'
then:
- service: media_player.volume_up
data: {}
target:
entity_id: media_player.zone_11
- if:
- condition: state
entity_id: sensor.remotes_test
state: '16'
then:
- service: media_player.volume_down
data: {}
target:
entity_id: media_player.zone_11
My thought for how to turn this into a script call function (sorry if thats the wrong way to describe) is the following
Automation
- id: "1662220652179"
alias: Audio test remote script test
description: "test to send var to script"
trigger:
- platform: state
entity_id: sensor.remotes_test
from: "0"
condition: []
action:
service: script.audio_remote
data:
variables:
button: "{{ states.sensor.remotes_test.state }}"
speaker: "{{ media_player.zone_11 }}"
source: "{{media_player.zone_11.source}}"
mode: single
Script
audio_remote:
alias: audio remote script
mode: parallel
variables:
button_pressed: "{{ button }}"
speaker_zone: "{{ speaker }}"
zone_soucre: "{{ source }}"
sequence:
# button play/pause (1) pressed
- if: button_pressed == "1"
then:
- if: zone_source == 1
then:
- service: media_player.select_source
data:
source: "2"
target:
entity_id: speaker_zone
else:
- service: media_player.select_source
data:
source: "1"
target:
entity_id: speaker_zone
# button center (2) pressed
- if: button_pressed == "2"
then:
- service: media_player.toggle
data: {}
target:
entity_id: speaker_zone
# button next (4) pressed
- if: button_pressed == "4"
then:
- if: zone_source == 1
then:
- service: media_player.select_source
data:
source: "2"
target:
entity_id: speaker_zone
else:
- service: media_player.select_source
data:
source: "1"
target:
entity_id: speaker_zone
# button volume up (8) pressed
- if: button_pressed == "8"
then:
- service: media_player.volume_up
data: {}
target:
entity_id: speaker_zone
# button volume down (16) pressed
- if: button_pressed == "16"
then:
- service: media_player.volume_down
data: {}
target:
entity_id: speaker_zone
As I say even just a point in the right direction is much appreciated, I will attest to being in too deep and having not enough a grasp on the architecture as a whole but this just seems really cumbersome to do in HA so im sure there is probably some base concept that I am not grasping because I would think it is a pretty basic function to map a physical button to an action and it seems automations is how you have to do it? Anyway really apprecaite any tips or help!