Last active
August 16, 2019 16:46
-
-
Save tenderlove/a940b54d8cbc0c5f938b21854905544a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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