Playing an audio file with rules

Does anyone know of a simple way to play audio file on the controller with rules? I am running OR 2.6 on Raspberry Pi and would like to play a specific audio file saved on the Raspberry PI triggered by specific sensor state..

Hi

I know that VLC can be triggered from the command line, so that might be an option.

There are various light weight players for Windows, so I assume that there must be plenty of players for Debian.

Please let us know how you get on.

Regards,
Stuart

A quick web search found this superuser forum post.

https://superuser.com/questions/548663/linux-super-light-weight-music-player-with-http-or-commandline-interface

You'd only need to create a command in OpenRemote to start incorporating your player of choice.

If you use ${param} instead of the sound filename in the OpenRemote command, you can insert whatever you like from rules and just use the one command.

Thanks for the hints Stuart. I found a couple of links that i believe should get e started. I would appreciate if you could provide an example of the command and rule for “use ${param} instead of the sound filename in the OpenRemote command, you can insert whatever you like from rules and just use the one command.”. Anything that you may have used in the past would be great. I am a newbie with Java programing and rules

There are the links on the command line Audio options for RP

https://www.raspberrypi.org/documentation/usage/audio/

http://elinux.org/Omxplayer

Hi

That default Pi sound file player looks easy enough to configure.

Just create a command in OpenRemote and link it to a button to get your Pi to play a file.

Once you're​ happy that a button click causes a file to be played, create another command and replace the path to the sound file with ${param}

You can then execute that command from within rules and insert a full path and filename.

So a rule might look like this :-

    rule "A sensor triggers a rule to inject a path and filename into the pi sound command"
    
    when
      Event( source == "A Sensor", value == "on" )
    then
      execute.command( "PI_sound_command_with_param", "/full_media_path/example.mp3" );
    
    end

Extra useful features of omxplayer :-

If omxplayer's auto-detection of the correct audio output device fails, you can force output over HDMI with:

   omxplayer -o hdmi example.mp3

Alternatively, you can force output over the headphone jack with:

   omxplayer -o local example.mp3

You can even force output over both the headphone jack and HDMI with:

   omxplayer -o both example.mp3

Useful reference to rules example :-

https://github.com/openremote/Documentation/wiki/OpenRemote-Rules-examples#push-a-value-from-a-rule-into-a-command

Just double check that the command names match perfectly when executing them from rules.

Screenshot_20170411-214129.jpg

Screenshot_20170411-215339.jpg

Hi Stuart thanks for all the good stuff you post!
This was a lot easier than i though. I have the basic command working with a rule. I will tryout the $param method but looks promising.

Hi

You're very welcome.

Please update this thread with your success story, for the benefit of future users.

Apparently there is an app called Mplayer that can be used with BeagleBones.

Cheers,
Stuart