Command Line Sensor Slow To Update

I’m working with an older Onkyo AVR (vsx-lx102) that I have in a closet in my garage.
The Onkyo AVR Media Player integration doesn’t really fit my need so my I’m building a page with my own controls for input, volume, power, etc. I’ll focus on Volume for the purpose of this question.

I’ve successfully built the controls utilizing eiscp shell commands to the device. I can control the volume up and down, and can retrieve the current volume from the device as well.

I use this shell command to control the volume:

shell_command:
     onkyo_volume_up: onkyo --host 192.168.2.67 volume=level-up-1db-step

I execute the command via script:

 alias: scrpt_Onkyo_Volume_Up
 sequence:
   - service: shell_command.onkyo_volume_up
     target:
       entity_id: sensor.onkyo_current_volume

The volume_up shell command returns a value of “unknown-model: master-volume = 46” showing the now current volume. I use template sensor to format the output to just “46”.

I’m then displaying the current volume template sensor on my dashboard.

The problem is that when I press the volume up, there can be as much as a 10 second delay in the template volume sensor updating. The response is instant from the volume up command, so I’m not sure why there is such a delay in updating the sensor.

Is there a more efficient way of accomplishing this?

EDIT:
It just dawned on me that it’s possible that the firing of the script is the slow part, and not the return of the data. Is there an easy way to troubleshoot this?

UPDATE:
I have verified that the execution of the script is not the issue. After executing the script I immediately queried the AVR and got the updated volume well before the sensor was updated in HA.

Further testing of the sensor.onkyo_current_level shows that the output from the script execution is not updating this sensor timely. The delay seems to be in the actual updating of the target sensor. Once the sensor is updated, it displays immediately.

So why is there such a delay in processing the output of the shell command when the value is returned instantly from the AVR?

I have exactly the same problem.
I imagine you are talking about your onkyo media_player volume_level sensor ?
mine gets updated more than 10 sec after i sent a volume up/down command.

But asking my onkyo with shell command for volume status returns instantly the updated value (dev tools).

service: shell_command.onkyo_command
data:
  cmd: volume=query
stdout: "TX-NR609: master-volume = 58"
stderr: ""
returncode: 0

So i would like to make a script to extract the value, each time i need the volume level and not having to wait 10 to 20 seconds that the media_player sensor updates…
If any idea to extract the valuewithin a called script ? I do NOT want that value from sensor in configuration…

I’m investigating a few options and i’ll keep posting if i find something usefull :slight_smile:

  1. HA documentation says:
    Shell commands provide a service response in a dictionary containing stdout, stderr, and returncode. These can be used in automations to act upon the command results using response_variable.
    Service calls - Home Assistant

  2. SERVICE HOMEASSISTANT.UPDATE_ENTITY:
    Home Assistant Core Integration - Home Assistant

ok, both methods worked for me but i find the method below to be the most simple: homeassistant.update_entity !

command_line:
  - sensor:
      name: Onkyo Volume
      command: onkyo --host 192.168.1.70 volume=query
      value_template: '{{ value.split("=")[1] }}'

Below, scripts for the “volume up/down” on my TX-NR609.

##################################################
onkyo_volume_up_with_feedback:
  sequence:
  #----------------------------------------
  - service: shell_command.onkyo_command
    data:
      cmd: volume=level-up
  #----------------------------------------
  - service: script.force_onkyo_volume_sensor_update
  mode: queued
  ########################
onkyo_volume_down_with_feedback:
  sequence:
  #----------------------------------------
  - service: shell_command.onkyo_command
    data:
      cmd: volume=level-down
  #----------------------------------------
  - service: script.force_onkyo_volume_sensor_update
  mode: queued
##################################################
force_onkyo_volume_sensor_update:
  sequence:
  - service: homeassistant.update_entity
    target:
      entity_id:
      - sensor.onkyo_volume
  mode: queued
##################################################

Also, i had to filter the volume with a triggered template like below (config):
So, the volume information got from the receiver is filtered to not show “unknown, unavailable” values.

template:
  - trigger:
      - platform: state
        entity_id: sensor.onkyo_volume
        not_to:
          - unknown
          - unavailable
    sensor:
      - name:  "onkyo_volume_show"
        state: '{{ trigger.to_state.state }}'
        unit_of_measurement: ''

So in the UI, i have 2 buttons for volumes up/down and the returned volume information just between these 2 buttons.
So if someone change the volume with a usual remote, i still read the actual volume in UI.
Capture

In all this, i did not want to use an input_number to store the volume because you still have to read the actual value from the receiver and this could easely lead to a loop between the “set” and “get” volume commands… i experienced it :rofl: