@trixwood, thanks for your scripts and detailed explanation!
I have used your bash scripts to control the volume of my Marantz NR1604 with Domoticz using two LUA scripts.

- tv-volume.jpg (16.11 KiB) Viewed 3332 times
LUA device script which sends volume via dimmer in Domoticz to Marantz
Code: Select all
commandArray = {}
IP = '192.168.1.138' --IP of Marantz
if devicechanged['TV volume'] == 'On' then
local play = 'curl --url "http://192.168.1.138/MainZone/index.put.asp?cmd0=PutVolumeMute%2Foff" &' --unmute
os.execute(play)
end
if devicechanged['TV volume'] == 'Off' then
local play = 'curl --url "http://192.168.1.138/MainZone/index.put.asp?cmd0=PutVolumeMute%2Fon" &' --mute
os.execute(play)
end
if devicechanged['TV volume'] then
NewLevel = otherdevices_svalues['TV volume']
if NewLevel ~= "Off" and NewLevel ~= "0" then
if tonumber(NewLevel) > 60 then --volume max 60
NewLevel = 60
end
SendLevel = NewLevel - 80 --79.5
--os.execute ("curl http://" .. (IP) .. "/MainZone/index.put.asp?cmd0=PutSystem_OnStandby%2FON")
--os.execute ("curl http://" .. (IP) .. "/MainZone/index.put.asp?cmd0=PutVolumeMute%2Foff")
os.execute ("curl http://" .. (IP) .. "/MainZone/index.put.asp?cmd0=PutMasterVolumeSet/" .. (SendLevel))
end
end
return commandArray
LUA time script which updates actual volume from Marantz in Domoticz
Code: Select all
commandArray = {}
function execute(command)
-- returns success, error code, output.
local f = io.popen(command..' 2>&1 && echo " $?"')
local output = f:read"*a"
return output
end
--read xml and remove value strings
--<MasterVolume><value>-60.0</value></MasterVolume> becomes -60.0
function get(data,name)
data = data:match("<"..name..">(.-)</"..name..">")
data = data:gsub("<value>", "")
data = data:gsub("</value>", "")
return data
end
vol_tv = execute('curl --url "http://192.168.1.138/goform/formMainZone_MainZoneXml.xml" &')
--get volume of TV and update volume switch in Domoticz if it differs
local vol_tv = get(vol_tv,"MasterVolume")
local vol_domo = otherdevices_svalues['TV volume']
--print(vol_tv)
vol_tv = tonumber(vol_tv) + 80
--print(vol_tv)
--if otherdevices['TV'] == 'On' then
if (vol_domo ~= vol_tv) then
commandArray['UpdateDevice'] = otherdevices_idx['TV volume'] ..' |2|' .. vol_tv
end
--end
return commandArray
The volume gets updated every minute, that is fast enough for me.
This way I can also control the volume via Siri using the excellent
Homebridge-eDomoticz software .
Edit: changed the script a bit, because it was only updating if you have a device TV which is On.