Creating a new media device

I am wanting to create a media device.

The device is an IP controllable stereo amplifier (it’s called a Meridan 218). I need input and volume control.

I currently have the following code and it gives access to sources

switch:
  - platform: command_line
    switches:
      218_cd:
        command_on: echo -e '#MSR CD' | nc 192.168.1.8 9014
        command_off: echo -e '#MSR SB' | nc 192.168.1.8 9014
      218_game:
        command_on: echo -e '#MSR GA' | nc 192.168.1.8 9014
        command_off: echo -e '#MSR SB' | nc 192.168.1.8 9014
      218_tv:
        command_on: echo -e '#MSR TV' | nc 192.168.1.8 9014
        command_off: echo -e '#MSR SB' | nc 192.168.1.8 9014
      218_off:
        command_off: echo -e '#MSR SB' | nc 192.168.1.8 9014

Is there a way to consolidate the networking information into the header (just to tidy this up)?

As this is a list of sources is there a better way to prevent the information than a set of on/off switches because only one of these can be selected at any one time.

As for the volume, this is going to be a bit more complex as I would like two communication to have a slider in lovelace.

With the following code:

sensor:
  - platform: command_line
    name: 218_volume
    command: echo -e '?PGS' | nc 192.168.1.8 9014

It provides me with this output:

!PID Product:“218” SerialNumber:“XXXXXX” VersionNumber:“1.1.240” ZoneName:“Lounge” ProtocolVersion:“3” *PGS Standby:“Standby” Source:“3” Legend:"TV " Input:“Optical” Mute:“Demute” Volume:“40”

From what I have read I’ll need to setup templating to extract the part I am interested in, which is ‘Volume’. To date, I’m not sure how to do this part or where to implement it.

I assume that once I’m able to extract that information I can advance with creating a volume slider.
(also I want the volume number so I can display this on my TV via notifications).

Could someone help get the ball rolling and I’ll tackle the interfacing with the volume after this.

Thanks in advance

Create a shell command for each option (instead of switches).

Create an input select that lists the available sources.

Create an automation that calls the appropriate shell command when the input select is changed.

You have a method to retrieve the current volume but you have not indicated you have a method to set the volume. Both would be required to create a volume slider.

Thank you,

I have begun my research into the shell command. I haven’t tested it yet but I expect this will work:

shell_command:
  218cd: echo -e '#MSR CD' | nc 192.168.1.8 9014
  218tv: echo -e '#MSR TV' | nc 192.168.1.8 9014
  218game: echo -e '#MSR GA' | nc 192.168.1.8 9014
  218standby: echo -e '#MSR SB' | nc 192.168.1.8 9014
  218voldown: echo -e '#MSR VM' | nc 192.168.1.8 9014
  218volup: echo -e '#MSR VP' | nc 192.168.1.8 9014

From my understanding, a shell is a script with a reference (eg. ‘218cd’ as a reference using the example above). thus allowing me to call on that reference within other scripts.

As for volume commands, I have 2 different ways for control. Either an incremental increase or decrease using ‘VP’ or ‘VM’ from the code above or I can access a number from 1 -99 with ‘SVN 45’ (45 being the example volume level).

All of this control is transmitted using RAW TCP packets as per the manufacturers API document.

There are two ways that I know of to combine other entities into a media player.

I’m starting to make some progress, thank you! Once I have this put together I’ll share my code for others.

I am really struggling with Templating. All documentation I have read describes extracting value from the attributes of a sensor. the problem is the feedback from my sensor is placed into the state.

here’s my sensor code:

sensor:
  - platform: command_line
    name: 218_sensor
    command: echo -e '?PGS' | nc 192.168.1.8 9014

I can’t work out how i would extract the volume number and/or the standby state.

A sensor should only have one state, the rest should be in attributes, or separate sensors.

Any idea how I could defer the info from the command_line sensor to the attributes section of HA?

In the absence of me being able to identify what the output is (it is not json or xml for instance) it is hard. Back to bash basics with awk I think.

Where is this doc (or did I miss it?)

EDIT: I remember from your other thread you refused to provide it.

‘refused to provide’ is such a harsh way of explaining that, nickrout. I said there wasn’t a link, it’s a PDF I have saved on my local disk. Not sure I can upload attachments.

The state output of that sensor is:

!PID Product:"218" SerialNumber:"101024" VersionNumber:"1.1.240" ZoneName:"Lounge" ProtocolVersion:"3"*PGS Standby:"Standby" Source:"11" Legend:"Cast " Input:"Analogue" Mute:"Demute" Volume:"40"

https://1drv.ms/b/s!AjBxBGMPf05nhO083zPbBzEYUDTXGg?e=BdUA86

Yeah I suppose it was sorry, but there are ways and means, as you have now done :slight_smile:

However when I click on your link it asks me for a password.

Whoops… my bad!

This one should be free to access until tomorrow:
https://1drv.ms/b/s!AjBxBGMPf05nhO08th6_xqVtiKUJpw?e=YHQHW5