Skip to content

Instantly share code, notes, and snippets.

@tenderlove
Last active August 16, 2019 16:46
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tenderlove/a940b54d8cbc0c5f938b21854905544a to your computer and use it in GitHub Desktop.
Save tenderlove/a940b54d8cbc0c5f938b21854905544a to your computer and use it in GitHub Desktop.
# Watch Yamaha AV receivers for events
#
# This script watches a Yamaha AV receiver for changes in state.
# It also implements two functions for changing the volume which is a fun
# way to "help" unsuspecting users.
#
# Protocol is here: https://www.sdu.se/pub/yamaha/yamaha-ynca-receivers-protocol.pdf
require "socket"
require "io/wait"
require "logger"
def volume s
s.write "@MAIN:VOL=?\r\n"
s.gets.split('=').last.to_f
end
def set_volume s, to
s.write "@MAIN:VOL=#{sprintf("%.1f", to)}\r\n"
s.gets.split('=').last.to_f
end
logger = Logger.new $stderr
s = TCPSocket.new "yamaha-av-receiver.local", 50000
s.write "@SYS:PWR=?\r\n"
logger.info s.gets.chomp
s.write "@MAIN:PWR=?\r\n"
logger.info s.gets.chomp
loop do
if s.wait_readable 30
logger.info s.gets.chomp
else
s.write "@SYS:VERSION=?\r\n"
logger.debug s.gets.chomp
end
end
s.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment