Page 1 of 1
Bluesound in Domoticz
Posted: Saturday 29 April 2017 22:54
by alveman
Someone how has conneted Bluesound to Domoticz and like to share how. I have found some info but my skills is not good enough.
https://github.com/venjum/bluesound
https://helpdesk.bluesound.com/discussi ... php?t=2293
Martin
Skickat från min iPad med Tapatalk
Re: Bluesound in Domoticz
Posted: Saturday 07 October 2017 14:45
by possm
This is my setup for my Bluesound speakers. At this moment all I do is volume control through Domoticz
I've not used the mentioned API because i think the Bluesound speaker AP itself is already useable enough.
1 create a Virtual Dummy hardware device: Bluesound

- Schermafbeelding 2017-10-07 om 14.31.04.png (26.61 KiB) Viewed 6175 times
2 Create your Virtual Switches (the speakers)

- Schermafbeelding 2017-10-07 om 14.31.39.png (74.71 KiB) Viewed 6175 times

- Schermafbeelding 2017-10-07 om 14.30.46.png (42.36 KiB) Viewed 6175 times
3 LUA script to translate the Domoticz controls into http requests for the speakers. (Set the script to "Device")
Code: Select all
------------------------------------------------------------------------------------------
-- Version 1 (20171006)
--
-- Domoticz lua script to convert the Domoticz switch commands to control the speaker
-- Creates a http request based on a list of unique IP and passes the volume values to the speakers
-------------------------------------------------------------------------------------------
-- Poss'M (c)2017
-------------------------------------------------------------------------------------------
-- Define your device IP-addresses (Bluesound devices respond to port 11000)
-- { <IP>, <Virtual Switch Name>}
Devices = {}
Devices [1] = {"192.168.1.60:11000", 'Speaker Woonkamer'}
Devices [2] = {"192.168.1.61:11000", 'Speaker Keuken'}
commandArray = {}
-- Loop trough BlueSound speakers and set the volume to right speaker
for i,device in ipairs(Devices) do
BSVolControl = 'http://' .. device[1] .. '/Volume?level=' .. otherdevices_svalues[device[2]]
if (devicechanged[device[2]]) then
commandArray['OpenURL']=BSVolControl
print(device[2] .. " (".. device[1] ..") set to " .. otherdevices_svalues[device[2]] .."%")
end
end
return commandArray
4 Syncing the volume of the speaker with Domoticz through a LUA script.
When the volume of the speaker is set outside of Domoticz this script will sync its interface with the actual volume of the speaker. (Set the script to "Time")
Code: Select all
------------------------------------------------------------------------------------------
-- Version 1 (20171006)
--
-- Domoticz lua script to convert XML output from Bluesound Speakers to Domoticz commands
-- Reads the status based on a list of unique IP and passes the volume values to virtual switches in Domoticz
-------------------------------------------------------------------------------------------
-- Original XML_Capture function by RATA1 at Domoticz-forum, adapted by Poss'M (c)2017
-------------------------------------------------------------------------------------------
commandArray = {}
function XML_Capture(cmd,flatten)
local f = assert(io.popen(cmd, 'r'))
local s = assert(f:read('*a'))
f:close()
if flatten then
s = string.gsub(s, '^%s+', '')
s = string.gsub(s, '%s+$', '')
s = string.gsub(s, '[\n\r]+', ' ')
end
return s
end
-- Set debug to true to print to log file.
debug = false
-- Define your device IP-addresses (Bluesound devices respond to port 11000)
-- { <IP>, <Virtual Switch Name>}
Devices = {}
Devices [1] = {"192.168.1.60:11000", 'Speaker Woonkamer'}
Devices [2] = {"192.168.1.61:11000", 'Speaker Keuken'}
for i,device in ipairs(Devices) do
if debug == true then
print("Reading values from: 'http://".. device[1] .."/Volume'")
end
-- Read the XML data from the device
XML_string=XML_Capture("curl -s 'http://".. device[1] .."/Volume'",1)
valid = string.find(XML_string, "<volume>") -- check we are looking in the right place
if debug == true then
print(XML_string)
end
if valid == nil then
print ("Bad XML status read - info NOT updated")
else
-- Find in the XML_string the info-fields based on their labels
-- Determine start/stop-positions of the values within the substrings
v_open = string.find(XML_string,"<volume>")+8 -- read volume string
v_close = string.find(XML_string,"</volume>")-1 -- read volume string
volume= string.sub(XML_string,v_open,v_close)
-- If volume levels mismatch with the Domoticz interface, update the Virtual Switch with the level of the Speaker
if (otherdevices_svalues[device[2]] ~= volume) then
commandArray[device[2]] = 'Set Level ' .. volume
end
end
end
return commandArray
Re: Bluesound in Domoticz
Posted: Monday 09 October 2017 21:26
by alveman
Thanx for you LUA code. When I tryed it I can't change the volym from Domoticz. Domoticz it self directly change it back to last set value. I have the two LUA codes in two different LUA file is that right?
Code: Select all
2017-10-09 21:19:11.110 User: Admin initiated a switch command (764/V-rum/Set Level)
2017-10-09 21:19:12.013 EventSystem: Script event triggered: /home/pi/domoticz/scripts/lua/script_device_bluesound2.lua
2017-10-09 21:19:12.086 LUA: V-rum (192.168.1.20:11000) set to 11%
2017-10-09 21:19:12.087 EventSystem: Fetching url...
2017-10-09 21:19:12.087 EventSystem: Script event triggered: /home/pi/domoticz/scripts/lua/script_device_bluesound1.lua
2017-10-09 21:19:12.162 (El) Light/Switch (V-rum)
2017-10-09 21:19:13.114 LUA: V-rum (192.168.1.20:11000) set to 6%
2017-10-09 21:19:13.115 EventSystem: Fetching url...
2017-10-09 21:19:13.115 EventSystem: Script event triggered: /home/pi/domoticz/scripts/lua/script_device_bluesound1.lua
2017-10-09 21:19:13.190 (El) Light/Switch (V-rum)
Re: Bluesound in Domoticz
Posted: Tuesday 10 October 2017 21:33
by possm
alveman wrote: ↑Monday 09 October 2017 21:26
Thanx for you LUA code. When I tryed it I can't change the volym from Domoticz. Domoticz it self directly change it back to last set value. I have the two LUA codes in two different LUA file is that right?
Yes thats is correct, try setting the second script to "Time", and the first script to "Device".
Re: Bluesound in Domoticz
Posted: Friday 13 October 2017 0:02
by alveman
possm wrote:alveman wrote: ↑Monday 09 October 2017 21:26
Thanx for you LUA code. When I tryed it I can't change the volym from Domoticz. Domoticz it self directly change it back to last set value. I have the two LUA codes in two different LUA file is that right?
Yes thats is correct, try setting the second script to "Time", and the first script to "Device".
Works perfectly now! Thanx
Skickat från min iPhone med Tapatalk
Re: Bluesound in Domoticz
Posted: Tuesday 30 January 2018 20:49
by GJvdP
Hello fellow bluesound users,
I own 3 Node1 mediastreamers. They react to the same command as the speakers (I checked)
I followed the above steps as far as I could understand them (I am new to domotics abd lua) and saved the scripts in the lua directory under "script_device_Bluesound.lua and script_time_bluesound,lua. Edited the IP addresses of the 3 Node1's.
Created de Bluesound dummy hardware.
First question: Do I create the dummy switches from this hardware or through Switches/Manual/Bluesound etc. (Did both but none seem to work)
If I look in the log I can see that the scripts read the correct value for the volumes but I don't see the switches change accordingly.
I also see the following error msg in the log:
2018-01-30 17:25:02.159 Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_device_Bluesound.lua: /home/pi/domoticz/scripts/lua/script_device_Bluesound.lua:19: attempt to concatenate field '?' (a nil value)
Hope you can straighten me out, all help is welcome.
Thanks, GJ
Re: Bluesound in Domoticz
Posted: Wednesday 31 January 2018 13:42
by GJvdP
Update:
Found that when my router restarted the IUOP addresses were not as fixed as I thought. Added the mac addresses in the router and that problem is fixed now.
While editing the lua scripts found that one of the Nodes had a spelling error. Changed that and now the error msgs are gone!
The volume controls are now set to 0 on the nodes even if I turn them up. Next pass they are 0 again.
And it shows in the log:
2018-01-31 13:35:00.692 EventSystem: Fetching url...
2018-01-31 13:35:00.692 EventSystem: Script event triggered: /home/pi/domoticz/scripts/lua/script_device_Bluesound.lua
2018-01-31 13:36:00.314 EventSystem: Script event triggered: /home/pi/domoticz/scripts/lua/script_time_Bluesound.lua
2018-01-31 13:36:00.349 LUA: Node1 Living (192.168.16.46:11000) set to %
If I understand the problem and if I master lua script I will try to create a script that does more than just set the volume.
So still all help is welcome
GJ
Re: Bluesound in Domoticz
Posted: Wednesday 31 January 2018 20:07
by GJvdP
Got it. It is the way you create the dummy switches. They actually have to be switches instead of soundlevel, as I falsely thought.
Later to change in Switches to dimmer. Works like a charm.
Re: Bluesound in Domoticz
Posted: Monday 15 October 2018 21:23
by basleeftink
Hi possm
Loveley script, i got it working for the control but have a problem reading the value´s.
The request on
http://192.168.1.200:11000/Volume returns:
The script looks in the XML for <volume> but it can not be found because the db= is added.
Does anyone know how to solve this? do you have an updated script?
Re: Bluesound in Domoticz
Posted: Sunday 28 October 2018 9:26
by alveman
basleeftink wrote:Hi possm
Loveley script, i got it working for the control but have a problem reading the value´s.
The request on
http://192.168.1.200:11000/Volume returns:
The script looks in the XML for <volume> but it can not be found because the db= is added.
Does anyone know how to solve this? do you have an updated script?
Change to
http://192.168.1.200:11000/Status and it will work.
Martin
Skickat från min iPhone med Tapatalk
Re: Bluesound in Domoticz
Posted: Sunday 04 November 2018 18:44
by basleeftink
Thanx Martin,
That works for me.