Page 2 of 2
Re: Get data from swith to text in dummy switch
Posted: Sunday 01 November 2020 18:33
by madpatrick
This is working
Code: Select all
2020-11-01 18:29:30.054 Logitech Media Server: (Squeezebox Touch) On
2020-11-01 18:29:30.436 Status: dzVents: Info: songDisplay: ------ Start internal script: LMS: Device: "Squeezebox Touch (Logitech Media Server)", Index: 430
2020-11-01 18:29:30.436 Status: dzVents: Debug: songDisplay: Processing device-adapter for Song played: Text device
2020-11-01 18:29:30.436 Status: dzVents: Debug: songDisplay: OpenURL: url = http://127.0.0.1:9200/json.htm?type=devices&rid=430
2020-11-01 18:29:30.436 Status: dzVents: Debug: songDisplay: OpenURL: method = GET
2020-11-01 18:29:30.436 Status: dzVents: Debug: songDisplay: OpenURL: post data = nil
2020-11-01 18:29:30.436 Status: dzVents: Debug: songDisplay: OpenURL: headers = nil
2020-11-01 18:29:30.436 Status: dzVents: Debug: songDisplay: OpenURL: callback = songDisplay
2020-11-01 18:29:30.436 Status: dzVents: Info: songDisplay: ------ Finished LMS
2020-11-01 18:29:30.442 Status: Incoming connection from: 127.0.0.1
2020-11-01 18:29:30.466 Status: dzVents: Info: songDisplay: ------ Start internal script: LMS: HTTPResponse: "songDisplay"
2020-11-01 18:29:30.471 Status: dzVents: Debug: songDisplay: Processing device-adapter for Song played: Text device
2020-11-01 18:29:30.471 Status: dzVents: !Info: songDisplay: Now playing: U2 - Stuck In Moment You Can't Get Out Of
2020-11-01 18:29:30.471 Status: dzVents: Info: songDisplay: ------ Finished LMS
2020-11-01 18:29:50.426 Logitech Media Server: (Squeezebox Touch) Playing - 'U2 - Stuck In Moment You Can't Get Out Of'
2020-11-01 18:29:50.459 Status: dzVents: Info: songDisplay: ------ Start internal script: LMS: Device: "Squeezebox Touch (Logitech Media Server)", Index: 430
2020-11-01 18:29:50.460 Status: dzVents: Debug: songDisplay: Processing device-adapter for Song played: Text device
2020-11-01 18:29:50.460 Status: dzVents: Debug: songDisplay: OpenURL: url = http://127.0.0.1:9200/json.htm?type=devices&rid=430
2020-11-01 18:29:50.460 Status: dzVents: Debug: songDisplay: OpenURL: method = GET
2020-11-01 18:29:50.460 Status: dzVents: Debug: songDisplay: OpenURL: post data = nil
2020-11-01 18:29:50.460 Status: dzVents: Debug: songDisplay: OpenURL: headers = nil
2020-11-01 18:29:50.460 Status: dzVents: Debug: songDisplay: OpenURL: callback = songDisplay
2020-11-01 18:29:50.460 Status: dzVents: Info: songDisplay: ------ Finished LMS
2020-11-01 18:29:50.507 Status: dzVents: Info: songDisplay: ------ Start internal script: LMS: HTTPResponse: "songDisplay"
2020-11-01 18:29:50.512 Status: dzVents: Debug: songDisplay: Processing device-adapter for Song played: Text device
2020-11-01 18:29:50.512 Status: dzVents: !Info: songDisplay: Now playing: U2 - Stuck In Moment You Can't Get Out Of
2020-11-01 18:29:50.512 Status: dzVents: Info: songDisplay: ------ Finished LMS
But....
It is not getting an update when you change a song.
It is possible to check the info every 10~20 sec when the script is activated to check for an update ?
Re: Get data from swith to text in dummy switch
Posted: Sunday 01 November 2020 19:09
by waaren
madpatrick wrote: ↑Sunday 01 November 2020 18:33
This is working
But....
It is not getting an update when you change a song.
It is possible to check the info every 10~20 sec when the script is activated to check for an update ?
like this ?
Code: Select all
local scriptVar = 'songDisplay'
return
{
on =
{
devices =
{
430, -- ID of your LMS device
},
httpResponses =
{
scriptVar,
}
},
logging =
{
level = domoticz.LOG_DEBUG, -- set to domoticz.LOG_ERROR when all OK
marker = scriptVar,
},
execute = function(dz, item)
songDisplay = dz.devices('Song played') -- change to name of your virtual text sensor
local function getSong(delay)
dz.openURL(
{
url = dz.settings['Domoticz url'] .. '/json.htm?type=devices&rid=430',
callback = scriptVar,
}).afterSec(delay)
end
if item.isHTTPResponse and item.isJSON then
newText = 'Now playing: ' .. item.json.result[1].Data
if songDisplay.text ~= newText then
songDisplay.updateText(newText)
dz.log(newText, dz.LOG_DEBUG)
elseif songDisplay.lastUpdate.secondsAgo > 600 then
dz.log('No new song in the last 10 minutes. Stopping now', dz.LOG_DEBUG)
return
end
getSong(15) -- Check again after 15 seconds
elseif item.isDevice or item.isTimer then
getSong(0)
else
dz.log('Problem with HTTPResponse..', dz.LOG_ERROR)
dz.log(item.data, dz.LOG_DEBUG)
end
end
}
Re: Get data from swith to text in dummy switch [Solved]
Posted: Monday 02 November 2020 14:59
by madpatrick
Yep !! This is now working.
I'll play with to get the correct view and settings
Thanks again !
Re: Get data from swith to text in dummy switch
Posted: Thursday 15 April 2021 11:06
by damdub
Hello
I'm trying to achieve exactly the same thing : display only the Now Playing title in my Dashticz Dashboard.
I tried to follow your steps but I always get errors in domoticz logs.
Can you clarify what kind of script I mut use in domoticz ? Lua, DZVent, which type ?
And if you could eventually give me a quick step by step how to, that would be very much apreciated.
Thank you very much
Re: Get data from swith to text in dummy switch
Posted: Thursday 15 April 2021 11:11
by waaren
damdub wrote: ↑Thursday 15 April 2021 11:06
I tried to follow your steps but I always get errors in domoticz logs.
Can you clarify what kind of script I mut use in domoticz ? Lua, DZVent, which type ?
Please share the errors you see in the log.
The script-type is dzVents (as per the subforum where it is posted)
__________________________________________________________________________________________________________________________
When not yet familiar with dzVents please start with reading
Get started Before implementing (~ 5 minutes). Special attention please for "In Domoticz go to Setup > Settings > Other and in the section EventSystem make sure the checkbox 'dzVents enabled' is checked. Also make sure that in the Security section in the settings you allow 127.0.0.1 to not need a password. dzVents uses that port to send certain commands to Domoticz. Finally make sure you have set your current location in Setup > Settings > System > Location, otherwise there is no way to determine nighttime/daytime state."
___________________________________________________________________________________________________________________________
Re: Get data from swith to text in dummy switch
Posted: Thursday 15 April 2021 11:55
by damdub
Hello and thank you for your help
Here is my code imported as DZvents (All commented) Event
I just modified the LMS IDX 2 times and the text utility block Name
Code: Select all
local scriptVar = 'songDisplay'
return
{
on =
{
devices =
{
131, -- ID of your LMS device
},
httpResponses =
{
scriptVar,
}
},
logging =
{
level = domoticz.LOG_DEBUG, -- set to domoticz.LOG_ERROR when all OK
marker = scriptVar,
},
execute = function(dz, item)
songDisplay = dz.devices('SONG') -- change to name of your virtual text sensor
local function getSong(delay)
dz.openURL(
{
url = dz.settings['Domoticz url'] .. '/json.htm?type=devices&rid=131',
callback = scriptVar,
}).afterSec(delay)
end
if item.isHTTPResponse and item.isJSON then
newText = 'Now playing: ' .. item.json.result[1].Data
if songDisplay.text ~= newText then
songDisplay.updateText(newText)
dz.log(newText, dz.LOG_DEBUG)
elseif songDisplay.lastUpdate.secondsAgo > 600 then
dz.log('No new song in the last 10 minutes. Stopping now', dz.LOG_DEBUG)
return
end
getSong(15) -- Check again after 15 seconds
elseif item.isDevice or item.isTimer
getSong(0)
else
dz.log('Problem with HTTPResponse..', dz.LOG_ERROR)
dz.log(item.data, dz.LOG_DEBUG)
end
end
}
And here are the errors
Code: Select all
2021-04-15 11:51:50.501 Error: dzVents: Error: (3.0.2) error loading module 'Script #1' from file '/home/pi/domoticz/scripts/dzVents/generated_scripts/Script #1.lua':
2021-04-15 11:51:50.501 ...domoticz/scripts/dzVents/generated_scripts/Script #1.lua:46: 'then' expected near 'getSong'
2021-04-15 11:51:50.589 Error: dzVents: Error: (3.0.2) error loading module 'Script #1' from file '/home/pi/domoticz/scripts/dzVents/generated_scripts/Script #1.lua':
2021-04-15 11:51:50.589 ...domoticz/scripts/dzVents/generated_scripts/Script #1.lua:46: 'then' expected near 'getSong'
2021-04-15 11:51:52.138 MQTT: Topic: domoticz/in, Message: {"idx":166,"nvalue":0,"svalue":"69.76"}
2021-04-15 11:51:52.252 Error: dzVents: Error: (3.0.2) error loading module 'Script #1' from file '/home/pi/domoticz/scripts/dzVents/generated_scripts/Script #1.lua':
2021-04-15 11:51:52.252 ...domoticz/scripts/dzVents/generated_scripts/Script #1.lua:46: 'then' expected near 'getSong'
2021-04-15 11:51:52.377 Error: dzVents: Error: (3.0.2) error loading module 'Script #1' from file '/home/pi/domoticz/scripts/dzVents/generated_scripts/Script #1.lua':
2021-04-15 11:51:52.377 ...domoticz/scripts/dzVents/generated_scripts/Script #1.lua:46: 'then' expected near 'getSong'
2021-04-15 11:51:53.369 Error: dzVents: Error: (3.0.2) error loading module 'Script #1' from file '/home/pi/domoticz/scripts/dzVents/generated_scripts/Script #1.lua':
2021-04-15 11:51:53.369 ...domoticz/scripts/dzVents/generated_scripts/Script #1.lua:46: 'then' expected near 'getSong'
Re: Get data from swith to text in dummy switch
Posted: Thursday 15 April 2021 13:26
by waaren
damdub wrote: ↑Thursday 15 April 2021 11:55
Hello and thank you for your help
Here is my code imported as DZvents (All commented) Event
Change line 45 from
Code: Select all
elseif item.isDevice or item.isTimer
to
Code: Select all
elseif item.isDevice or item.isTimer then
Re: Get data from swith to text in dummy switch
Posted: Thursday 15 April 2021 13:51
by damdub
No error anymore but... nothing happens. I see no log in domoticz logs and text block is never updated
Song is playing and is identified in Domoticz LMS Logs

- domoLMS1.png (16.1 KiB) Viewed 940 times
If I paste in a browser the command
http://DOMOTIQUEIP:8080/json.htm?type=devices&rid=131 the result is OK

- domoLMS2.png (6.9 KiB) Viewed 940 times
Any idea ?
Thank you very much for your help
Re: Get data from swith to text in dummy switch
Posted: Thursday 15 April 2021 14:50
by waaren
damdub wrote: ↑Thursday 15 April 2021 13:51
No error anymore but... nothing happens. I see no log in domoticz logs and text block is never updated
Any idea ?
Can you add below lines directly after the line "
if item.isHTTPResponse and item.isJSON then"
Code: Select all
dz.utils.dumpTable(item.json)
dz.log(songDisplay.text,dz.LOG_DEBUG)
Re: Get data from swith to text in dummy switch
Posted: Thursday 15 April 2021 15:24
by damdub
For your info I finally got these errors in domoticz logs
Code: Select all
2021-04-15 14:22:52.508 Error: Error opening url: http://127.0.0.1:8080/json.htm?type=devices&rid=131
2021-04-15 14:22:52.567 Error: dzVents: Error: (3.0.2) songDisplay: HTTP/1.1 response: 401 ==>> Unauthorized
2021-04-15 14:22:52.578 Error: dzVents: Error: (3.0.2) songDisplay: Problem with HTTPResponse..
So I changed
Code: Select all
url = dz.settings['Domoticz url'] .. '/json.htm?type=devices&rid=131',
like this
Code: Select all
url = dz.settings'http://192.168.0.161:8080/json.htm?type=devices&rid=131',
Got no error anymore but nothing happens anyway
Now I modified the code like you suggested so it looks like this
Code: Select all
local scriptVar = 'songDisplay'
return
{
on =
{
devices =
{
131, -- ID of your LMS device
},
httpResponses =
{
scriptVar,
}
},
logging =
{
level = domoticz.LOG_DEBUG, -- set to domoticz.LOG_ERROR when all OK
marker = scriptVar,
},
execute = function(dz, item)
songDisplay = dz.devices('SONG') -- change to name of your virtual text sensor
local function getSong(delay)
dz.openURL(
{
url = dz.settings'http://192.168.0.161:8080/json.htm?type=devices&rid=131',
callback = scriptVar,
}).afterSec(delay)
end
if item.isHTTPResponse and item.isJSON then
dz.utils.dumpTable(item.json)
dz.log(songDisplay.text,dz.LOG_DEBUG)
newText = 'Now playing: ' .. item.json.result[1].Data
if songDisplay.text ~= newText then
songDisplay.updateText(newText)
dz.log(newText, dz.LOG_DEBUG)
elseif songDisplay.lastUpdate.secondsAgo > 600 then
dz.log('No new song in the last 10 minutes. Stopping now', dz.LOG_DEBUG)
return
end
getSong(15) -- Check again after 15 seconds
elseif item.isDevice or item.isTimer then
getSong(0)
else
dz.log('Problem with HTTPResponse..', dz.LOG_ERROR)
dz.log(item.data, dz.LOG_DEBUG)
end
end
}
And now I have these errors in the logs when I launch the script
Code: Select all
2021-04-15 15:17:12.365 Error: dzVents: Error: (3.0.2) songDisplay: An error occurred when calling event handler Script #2
2021-04-15 15:17:12.365 Error: dzVents: Error: (3.0.2) songDisplay: ...domoticz/scripts/dzVents/generated_scripts/Script #2.lua:30: attempt to call a table value (field 'settings')
nothing else after that even when switching to a new song
Re: Get data from swith to text in dummy switch
Posted: Thursday 15 April 2021 15:58
by waaren
damdub wrote: ↑Thursday 15 April 2021 15:24
For your info I finally got these errors in domoticz logs
Code: Select all
2021-04-15 14:22:52.508 Error: Error opening url: http://127.0.0.1:8080/json.htm?type=devices&rid=131
2021-04-15 14:22:52.567 Error: dzVents: Error: (3.0.2) songDisplay: HTTP/1.1 response: 401 ==>> Unauthorized
2021-04-15 14:22:52.578 Error: dzVents: Error: (3.0.2) songDisplay: Problem with HTTPResponse..
___________________________________________________________________________________________________________________________
When not yet familiar with dzVents please start with reading
Get started Before implementing (~ 5 minutes). Special attention please for "In Domoticz go to Setup > Settings > Other and in the section EventSystem make sure the checkbox 'dzVents enabled' is checked. Also make sure that in the Security section in the settings you allow 127.0.0.1 to not need a password. dzVents uses that port to send certain commands to Domoticz. Finally make sure you have set your current location in Setup > Settings > System > Location, otherwise there is no way to determine nighttime/daytime state."
___________________________________________________________________________________________________________________________
And use below code.
Code: Select all
local scriptVar = 'songDisplay'
return
{
on =
{
devices =
{
131, -- ID of your LMS device
},
httpResponses =
{
scriptVar,
}
},
logging =
{
level = domoticz.LOG_DEBUG, -- set to domoticz.LOG_ERROR when all OK
marker = scriptVar,
},
execute = function(dz, item)
songDisplay = dz.devices('SONG') -- change to name of your virtual text sensor
local function getSong(delay)
dz.openURL(
{
url = dz.settings['Domoticz url'] .. '/json.htm?type=devices&rid=131',
callback = scriptVar,
}).afterSec(delay)
end
if item.isHTTPResponse and item.isJSON then
dz.utils.dumpTable(item.json)
dz.log(songDisplay.text,dz.LOG_DEBUG)
newText = 'Now playing: ' .. item.json.result[1].Data
if songDisplay.text ~= newText then
songDisplay.updateText(newText)
dz.log(newText, dz.LOG_DEBUG)
elseif songDisplay.lastUpdate.secondsAgo > 600 then
dz.log('No new song in the last 10 minutes. Stopping now', dz.LOG_DEBUG)
return
end
getSong(15) -- Check again after 15 seconds
elseif item.isDevice or item.isTimer then
getSong(0)
else
dz.log('Problem with HTTPResponse..', dz.LOG_ERROR)
dz.log(item.data, dz.LOG_DEBUG)
end
end
}
Re: Get data from swith to text in dummy switch
Posted: Thursday 15 April 2021 20:14
by damdub
Hello
Sorry about my mistake. I did read the get started manual and allowed the 127.0.0.* but I made a mistake and used a "," instead of a ";" to separate IPs in that setup section. Sorry again.
Your code is still giving an error because of a "then" missing after
Code: Select all
elseif item.isDevice or item.isTimer
I corrected it and it's now working perfectly.
Here is the final code
Code: Select all
local scriptVar = 'songDisplay'
return
{
on =
{
devices =
{
131, -- ID of your LMS device
},
httpResponses =
{
scriptVar,
}
},
logging =
{
level = domoticz.LOG_DEBUG, -- set to domoticz.LOG_ERROR when all OK
marker = scriptVar,
},
execute = function(dz, item)
songDisplay = dz.devices('SONG') -- change to name of your virtual text sensor
local function getSong(delay)
dz.openURL(
{
url = dz.settings['Domoticz url'] .. '/json.htm?type=devices&rid=131',
callback = scriptVar,
}).afterSec(delay)
end
if item.isHTTPResponse and item.isJSON then
newText = '' .. item.json.result[1].Data
if songDisplay.text ~= newText then
songDisplay.updateText(newText)
dz.log(newText, dz.LOG_DEBUG)
elseif songDisplay.lastUpdate.secondsAgo > 600 then
dz.log('No new song in the last 10 minutes. Stopping now', dz.LOG_DEBUG)
return
end
getSong(15) -- Check again after 15 seconds
elseif item.isDevice or item.isTimer then
getSong(0)
else
dz.log('Problem with HTTPResponse..', dz.LOG_ERROR)
dz.log(item.data, dz.LOG_DEBUG)
end
end
}
Thank you again for your help and for being so responsive.
Take care
D.