[solved] [How-to] Run a bash/shell commands and use output as a variable eg for Denon AVR

Full project / how-to use command_line, fetch unsupported states of Dennon AVRs available in the web frontend of network accessable Denon/Marantz AVRs at the end of this post

(here the original question - as description of my problem)

Hi and sorry if id should have found the exact answer in an existing thread. All I found didn’t really match my needs. I’m a total rookie - started yesterday.

So I have setup home assistant (docker) on my synology NAS. denonavr integration is running and already sending notifications to my LG Smart TV.

Unfortunatly I’m not able to get source signal information (I want to dissplay the source output channel like 5.1 and 2.0).

If someone knows the exact attribute to fetch this information it would be great. I did not find it
Denon AVR Network Receivers - Home Assistant

So a simple way would be to add a trigger to call my bash script which gets the source format/channel information using GNU Linux commands like wget, grep and head. The information I am looking can be read out from the AVRs web frontend.

So long story short: Is it possible to fetch output of a bash/shell script to use it as a variable for an automatition?

Thanks in advance

Edit: If your’e asking why I want do to this - the TV is connected via eARC and so there is no way to have an on screen display from the receiver with these information.

How to fetch information eg from web fronted of Denon network enabled AVRs that are not supported but viewable on the Web frontend

First - Open a Chrome/Chromium or derivat browser using other browsers may vary

  • visit your AVRs web frontend (by entering its ip or by url) - make sure you are at the main page(!)
  • press F12 - a developer console appears on the right site of the browsers page
  • notice the dot on the upper left side of this developer console is red and you are on the “Network” register (right above the dot mentioned is the list with “Elements” “Console” “Sources”)
  • now that you have checked everything and it’s recording take a look back to the left side where your web frontend is: navigate to the “Information” overview where you have an overview of the information you want to fetch for (code in this thread could easily be modified)
  • after you have navigated to the Information panel take a look at the lift side where you’ve recorded the network activity an stop recording by clicking on the (red) dot.

Here you have the information - different request URLs(? don’t now the term of this actually)
The one we searched for should be the last in the list - klick on it.

Now you should see the exact lURL looking something like this:
https://(YOUR.AVRs.IP):(PORT)/ajax/general/get_config?type=12(bla bla bla)

You only need the part up to (…)get_config?type=12 (on my AVR its the #12 - this may vary like your IP also does)

Now you could check, if you are getting some information from your Denon AVR by entering the whole URL in to your browser (a source code XML should appear)

  • If testing the URL was successful:

Copy the request URL to this yan replace the ###

  - platform: command_line
    name: Source_Channel
    command: wget --no-check-certificate -q ### -O wget.txt && grep -P -o "(?<=\<Format\>).*(?=\</Format\>)" wget.txt && rm wget.txt

Last step is to copy this block in to your ~/config/configuration.yaml
Check the configuration throug the home assistant GUI and restart the instance

You can access your variable/value as sensor (like you named it) in my case " sensor.source_channel"

I have no answer on how to get the channel but… you can run command line stuff,

Command Line - Home Assistant (home-assistant.io)
generate a file and then use this to create a sensor for it which you then can use in HA
File - Home Assistant (home-assistant.io)

Thank you!
I didn’t expect this really could just execute all of my code but it does. I got this to work without writing a file. I just used a sensor and in the automatitions I printed the output direct as a variable:
message: 'Source_Channel: {{ states("sensor.source_channel") }}'

As I too have a denon, would you mind sharing the script please? And when done, please makr this thread as resolved

sure. As I said I just started 2 days ago. So I’ll look for how to share this. Which part do you need just the code I used to read the Denon source channels or the part where i push a notification to the LG TV using notify?

For the last part I have not found I usable trigger jet to get a notified every time the input signal changes or I switch imput source or something like that.

For people reading this and also have a LG TV: I have spend hours setting up webostv for WebOS Smart TVs - There is a bug so that at the moment (it’s the 7th of May 2022) the last version known to be working to setup webostv is core-2021.3.4 read more here: Component LG WebOSTV crashed in core-2021.4.1 · Issue #48925 · home-assistant/core · GitHub

This is the code to put in the configuration.yaml to read the source channels

  - platform: command_line
    name: Source_Channel
    command: wget --no-check-certificate -q https://LAN.IP:OF.DenonAVR:10443/ajax/general/get_config?type=12 -O wget.txt && sed -i.bak 's/Video.*//g' wget.txt && rm wget.txt.bak && grep -P -o "(?<=\<Format\>).*(?=\</Format\>)" wget.txt && rm wget.txt

Edit: Insert Code and important notice for LGTV owners