Volume slider and irrsend

Hello,

I’m trying to use an input slider to control my old AV receiver.
I have 2 shell_command and script to control it. Each time a press the script, i have +1 ou -1 on my volume.

I want to make it with input_slider from -60dB to -10dB, but i think i need to make a loop somewhere to call +1 or -1 as many time as needed.

Something like. (CurrentValue - NewValue) * +/-_1_script.
Does someone have an idea about such a thing ?

Thanks.

shell_command : 
    volume_up: 'irsend SEND_ONCE Yamaha KEY_VOLUMEUP'
    volume_down: 'irsend SEND_ONCE Yamaha KEY_VOLUMEDOWN'
script:
volume_up:
    sequence:
        - service: shell_command.volume_up
volume_down:
    sequence:
        - service: shell_command.volume_down

on the basis that your commands are Vol up and vol down, you won’t be able to use a slider, unless you can get the volume value of your yamaha device and then send as many vol up/down commands as required.
It would probably be better to set 2 buttons for up and down to “mimic” the remote actions no?

I’m helping another guy with a looped shell command, building a quick python script for him. When it’s done ill toss it your way.

This script and a similar automation should get you what you want

1 Like

thanks @petro, i gonna have a look a this :slight_smile: . i will keep you informed.

It works really great, many thanks for the solution.

1 Like

Could you share the final setup for this? I would like to implement it as well. Did you try integrating it into universal media player?

if you follow the link I posted, it has the script and yaml needed.

No, it was not integrated into the universal media player.

I would have like to use it with universal media_player and a switch for power_on/power_off but i can’t make it work. :confused:

Here is my setup for the slider, i follow what petro post

automation.yaml

# Yamaha Volume
- id: yamaha_volume
  alias: Yamaha Volume
  initial_state: True
  trigger:
    platform: state
    entity_id: input_number.volume
  condition:
    condition: template
    value_template: "{{ trigger.to_state.state != trigger.from_state.state and
                        trigger.to_state.state is not none and
                        trigger.from_state.state is not none }}"
  action:
    service: python_script.loop_command
    data_template:
      command: >
        {% if trigger.to_state.state|float > trigger.from_state.state|float %}
          shell_command.volume_up
        {% else %}
          shell_command.volume_down
        {% endif %}
      count: >
        {{ ((trigger.to_state.state|float - trigger.from_state.state|float)|abs / state_attr('input_number.volume', 'step'))|round }}

shell_command.yaml

volume_up: 'irsend SEND_ONCE Yamaha KEY_VOLUMEUP'
volume_down: 'irsend SEND_ONCE Yamaha KEY_VOLUMEDOWN'

input_number.yaml

volume:
    name: Volume
    initial: -45
    min: -80
    max: 0
    step: 1
1 Like

Hi @petro I’m trying to achieve the same control of an IR amp but through the harmony hub. Below is my setup but I can not get it to work. Any help would be appreciated. I have proven that the volume up/down scripts work.

loop_command.py

count = data.get('count')
command = data.get('command')

sleep_time = 0.05

if count:
    try:
        count = int(count)
    except ValueError:
        # if the value of count is not an integer, don't do any loops.
        logger.warning("Bad count {}, cannot convert to integer.".format(count))
        count = None

domain, command = command.split('.')

if domain and command and count: #make sure the entity_id exists and the count is greater than 0.
    for i in range(count):
        hass.services.call(domain, command , None, True)
        time.sleep(sleep_time)
else:
    logger.warning("Did not execute loop.")

automation.yaml

# Yamaha Volume
- id: yamaha_volume
  alias: Yamaha Volume
  initial_state: True
  trigger:
    platform: state
    entity_id: input_number.yamaha_receiver
  condition:
    condition: template
    value_template: "{{ trigger.to_state.state != trigger.from_state.state and
                        trigger.to_state.state is not none and
                        trigger.from_state.state is not none }}"
  action:
    service: python_script.loop_command
    data_template:
      command: >
        {% if trigger.to_state.state|float > trigger.from_state.state|float %}
          script.yamaha_receiver_volume_up
        {% else %}
          script.yamaha_receiver_volume_down
        {% endif %}
      count: >
        {{ ((trigger.to_state.state|float - trigger.from_state.state|float)|abs / state_attr('input_number.yamaha_receiver', 'step'))|round }}

input_number.yaml

yamaha_receiver:
  name: Yamaha Receiver Volume
  icon: mdi:volume-high
  initial: -80
  min: -80
  max: +16
  step: 0.5
  unit_of_measurement: "dB"

scripts.yaml

yamaha_receiver_volume_down:
  alias: Yamaha Receiver Volume Down
  sequence:
  - data:
      command:
      - VolumeDown
      device: AV Receiver
    entity_id: remote.lounge_room
    service: remote.send_command

yamaha_receiver_volume_up:
  alias: Yamaha Receiver Volume Up
  sequence:
  - data:
      command:
      - VolumeUp
      device: AV Receiver
    entity_id: remote.lounge_room
    service: remote.send_command

Are the individual scripts running? Are you getting warnings or errors in the log?

After a restart of the Hass docker container it is now working but it only output .5dB or one step per 1 seconds so it’s very slow, not sure how to speed this up. Am I right in thinking that a slider control is not really going to work well when hass has no way of knowing the current volume level of the AV receiver. I don’t know if it is possibly to get the current volume level through IR. What are you thoughts, I should really just get a modern AV receiver that is network controllable.

I am at the same point. By coincident, I am also using a Yamaha receiver, which I can control with HA, through a broadlink rm4. Tested and working.

Despite being a 2011 device, it does have LAN connection and is controllable by Yamaha APP “AV Controller”. The App does not use a slider for volume control, but the Amp does feedback volume level with dbA setting. Vol up and vol down, can be set to target colume level and Amp volume knob follows.

I have no idea, though, how to extract that info, either from the app or the amp.

So for the time being, I will have to settle with the less desirable method of Vol up and down buttons

It turns out, that, despite my Amp not featuring MusiCast, I am still able to control it from HA.

The OotB Intergration works fine. follow instructions from integration notes: add device as media player in config.yaml, define host IP, restart. Done. ;))) Meesa happi gungan!

Device tested: Yamaha RX-A810, build ca 2011, latest firmware,