Page 1 of 1
Concatenating an URL with values from sensors.
Posted: Wednesday 11 July 2018 7:32
by radiochild
Hi, I am running Domoticzs on a Synology NAS and I am trying to send a value to an ESPEasy LED display. I can send the dummy info, just as a straight number, e.g.
Code: Select all
commandArray[1]={['OpenURL'] = baseurlESPEasy..'7dt,'..333 }
but I can't substitute a sensor value for the number, e.g.
Code: Select all
commandArray[1]={['OpenURL'] = baseurlESPEasy..'7dt,'..sensortemp}
commandArray[1]={['OpenURL'] = baseurlESPEasy..'7dt,'..['Sensor_Temperature']}
The errors usually relate to concatenation a global or things like that.
I don't understand the examples and other posts I have read. Can someone please explain if this can work or how to do it if it can't?
Re: Concatenating an URL with values from sensors.
Posted: Wednesday 11 July 2018 9:33
by waaren
radiochild wrote: ↑Wednesday 11 July 2018 7:32
Hi, I am running Domoticzs on a Synology NAS and I am trying to send a value to an ESPEasy LED display. I can send the dummy info, just as a straight number, e.g.
Code: Select all
commandArray[1]={['OpenURL'] = baseurlESPEasy..'7dt,'..333 }
but I can't substitute a sensor value for the number, e.g.
Code: Select all
commandArray[1]={['OpenURL'] = baseurlESPEasy..'7dt,'..sensortemp}
commandArray[1]={['OpenURL'] = baseurlESPEasy..'7dt,'..['Sensor_Temperature']}
The errors usually relate to concatenation a global or things like that.
I don't understand the examples and other posts I have read. Can someone please explain if this can work or how to do it if it can't?
Yes it can work. If you post the complete script it is easier to comment on what modifications are needed to get this to work.
Re: Concatenating an URL with values from sensors.
Posted: Wednesday 11 July 2018 12:13
by radiochild
Hi Waaren, thanks for having a look for me.
Code: Select all
-- Variables
baseurlESPEasy = "http://192.168.1.xx/control?cmd="
commandArray = {}
if devicechanged['Undercot_Temperature'] then
commandArray[1]={['OpenURL'] = baseurlESPEasy..'7dt,'..333 }
end
This works.
I just can't figure out how to put a value from a sensor where the '333' is.
Re: Concatenating an URL with values from sensors.
Posted: Wednesday 11 July 2018 12:56
by waaren
radiochild wrote: ↑Wednesday 11 July 2018 12:13
Code: Select all
-- Variables
baseurlESPEasy = "http://192.168.1.xx/control?cmd="
commandArray = {}
if devicechanged['Undercot_Temperature'] then
commandArray[1]={['OpenURL'] = baseurlESPEasy..'7dt,'..333 }
end
This works.
I just can't figure out how to put a value from a sensor where the '333' is.
This will send the same as in your example with the temperature from sensor Undercot_Temperature. (dzVents)
Code: Select all
-- Send Undercot Temp
return {
on = { devices = { "Undercot_Temperature" }},
logging = { level = domoticz.LOG_DEBUG,
marker = "Send undercot" },
execute = function(domoticz, undercot )
local baseurlESPEasy = "http://192.168.1.xx/control?cmd="
domoticz.openURL({
url = baseurlESPEasy .. "7dt" .. undercot.temperature,
method = "GET"
})
end
}
Re: Concatenating an URL with values from sensors.
Posted: Wednesday 11 July 2018 13:29
by radiochild
Hi Waaren.
I tried your code and I get;
Error: EventSystem: in Portable LED Display: [string "-- Send Undercot Temp ..."]:6: attempt to index global 'domoticz' (a nil value)
I am using this in Events. I realise I didn't mention that before, does that make a difference?
Re: Concatenating an URL with values from sensors.
Posted: Wednesday 11 July 2018 13:37
by jvdz
So you have an LUA event script and you want to send the new received value for ... to ESPEASY....right?
Something like this should be close for a Device Lua event script:
Code: Select all
baseurlESPEasy = "http://192.168.1.xx/control?cmd="
commandArray = {}
if devicechanged['Undercot_Temperature'] then
commandArray[1]={['OpenURL'] = baseurlESPEasy..'7dt,'.. devicechanged['Undercot_Temperature']}
end
.. but are you sure about that ESPEASY URL? Does that work directly from a browser?
Jos
Re: Concatenating an URL with values from sensors.
Posted: Wednesday 11 July 2018 13:46
by radiochild
Hi jvdz,
Thank you! That worked a charm. The url works in a browser for ESPEasy. It now works in Domoticz. It's just an update to a MAX7219 LED display. So simple but I just couldn't figureit out.
Thank you again, Waaren and jvdz for helping me out.
Re: Concatenating an URL with values from sensors.
Posted: Wednesday 11 July 2018 17:19
by waaren
radiochild wrote: ↑Wednesday 11 July 2018 13:29
Hi Waaren.
I tried your code and I get;
Error: EventSystem: in Portable LED Display: [string "-- Send Undercot Temp ..."]:6: attempt to index global 'domoticz' (a nil value)
I am using this in Events. I realise I didn't mention that before, does that make a difference?
Hi radioChild, my script is dzVents. Choose dzVents in the event editor and copy paste the script ..
Re: Concatenating an URL with values from sensors.
Posted: Wednesday 19 February 2020 6:56
by MarloCZ
Hello, please can someone advise me, I try the script written above, but my display shows nothing.
When I enter a command via URL, it will show up on the display.
Thanks for the help
Code: Select all
-- Send Undercot Temp
return {
on = { devices = { "Outdoor_thermometer" }},
logging = { level = domoticz.LOG_DEBUG,
marker = "Send undercot" },
execute = function(domoticz, undercot )
local baseurlESPEasy = "http://192.168.7.71/control?cmd="
domoticz.openURL({
url = baseurlESPEasy .. "7dt" .. Outdoor_thermometer,
method = "GET"
})
end
}
Device:
48 Dummy 14080 1 Outdoor_thermometer Temp LaCrosse TX3 2.7 C
LOG:
2020-02-19 06:57:59.694 Status: dzVents: Error (2.4.19): Send undercot: An error occured when calling event handler Displej-1
2020-02-19 06:57:59.694 Status: dzVents: Error (2.4.19): Send undercot: ...Domoticz\scripts\dzVents\generated_scripts/Displej-1.lua:13: attempt to concatenate global 'Outdoor_thermometer' (a nil value)
2020-02-19 06:57:59.694 Status: dzVents: Info: Send undercot: ------ Finished Displej-1
2020-02-19 06:58:02.679 EventSystem: Event triggered: Termostat-Loznice_2
Re: Concatenating an URL with values from sensors.
Posted: Wednesday 19 February 2020 8:38
by waaren
MarloCZ wrote: ↑Wednesday 19 February 2020 6:56
Hello, please can someone advise me, I try the script written above, but my display shows nothing.
You copied and paste some unexpected values.
Can you try this
Code: Select all
-- Send temperature of a sensor to ESP Easy
return
{
on =
{
devices =
{
'Outdoor_thermometer',
}
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'Temperature to ESPEasy'
},
execute = function(dz, item)
local ESPEasyURL = 'http://192.168.7.71/control?cmd='
dz.openURL(
{
url = ESPEasyURL .. '7dt,' .. item.temperature,
method = 'GET',
})
end
}
Re: Concatenating an URL with values from sensors.
Posted: Wednesday 19 February 2020 13:07
by MarloCZ
Thank you very much for the modified script.
I turned it on, but the screen still doesn't show me anything
The extract from the log is as follows:
2020-02-19 13:06:25.489 Status: dzVents: Info: Handling events for: "Outdoor_thermometer", value: "5.06"
2020-02-19 13:06:25.490 Status: dzVents: Info: Temperature to ESPEasy: ------ Start internal script: Display-1: Device: "Outdoor_thermometer (Dummy)", Index: 48
2020-02-19 13:06:25.490 Status: dzVents: Debug: Temperature to ESPEasy: OpenURL: url = http://192.168.7.71/control?cmd=7dt5.0599999427795
2020-02-19 13:06:25.490 Status: dzVents: Debug: Temperature to ESPEasy: OpenURL: method = GET
2020-02-19 13:06:25.490 Status: dzVents: Debug: Temperature to ESPEasy: OpenURL: post data = nil
2020-02-19 13:06:25.490 Status: dzVents: Debug: Temperature to ESPEasy: OpenURL: headers = nil
2020-02-19 13:06:25.490 Status: dzVents: Debug: Temperature to ESPEasy: OpenURL: callback = nil
2020-02-19 13:06:25.491 Status: dzVents: Info: Temperature to ESPEasy: ------ Finished Display-1
Re: Concatenating an URL with values from sensors.
Posted: Wednesday 19 February 2020 13:22
by MarloCZ
So I figured it out - it works

There was no comma in 7dt
,
Code: Select all
url = ESPEasyURL .. '7dt,' .. item.temperature,
Can I have another request, could it be done on the display alternate between two different temperatures - from outside and from inside thermometer - alternately ?
Thank you in advance for your help.
Re: Concatenating an URL with values from sensors.
Posted: Wednesday 19 February 2020 14:43
by waaren
MarloCZ wrote: ↑Wednesday 19 February 2020 13:22
Can I have another request, could it be done on the display alternate between two different temperatures - from outside and from inside thermometer - alternately ?
Could be something like
Code: Select all
-- Send temperature of two sensors alternately to ESP Easy
return
{
on =
{
timer =
{
'every minute',
}
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'Temperature to ESPEasy'
},
execute = function(dz, item)
local display
if dz.time.minutes % 2 == 0 then
display = dz.utils.round(dz.devices('Outdoor_thermometer').temperature,1)
else
display = dz.utils.round(dz.devices('Indoor_thermometer').temperature,1)
end
local ESPEasyURL = 'http://192.168.7.71/control?cmd='
dz.openURL(
{
url = ESPEasyURL .. '7dt,' .. display
method = 'GET',
})
end
}
Re: Concatenating an URL with values from sensors.
Posted: Wednesday 19 February 2020 21:43
by MarloCZ
Thanks for the new script, but it reports me an error
Code: Select all
2020-02-19 21:36:57.915 Status: dzVents: Error (2.4.19): error loading module 'Display-2' from file 'C:\Program Files (x86)\Domoticz\scripts\dzVents\generated_scripts/Display-2.lua':
2020-02-19 21:36:57.915 ...Domoticz\scripts\dzVents\generated_scripts/Display-2.lua:32: '}' expected (to close '{' at line 30) near 'method'
Re: Concatenating an URL with values from sensors.
Posted: Wednesday 19 February 2020 23:07
by waaren
MarloCZ wrote: ↑Wednesday 19 February 2020 21:43
Thanks for the new script, but it reports me an error
Sorry for that. I missed a comma after display.
can you try again ?
Code: Select all
-- Send temperature of two sensors alternately to ESP Easy
return
{
on =
{
timer =
{
'every minute',
}
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'Temperature to ESPEasy'
},
execute = function(dz, item)
local display
if dz.time.minutes % 2 == 0 then
display = dz.utils.round(dz.devices('Outdoor_thermometer').temperature,1)
else
display = dz.utils.round(dz.devices('Indoor_thermometer').temperature,1)
end
local ESPEasyURL = 'http://192.168.7.71/control?cmd='
dz.openURL(
{
url = ESPEasyURL .. '7dt,' .. display,
method = 'GET',
})
end
}
Re: Concatenating an URL with values from sensors.
Posted: Thursday 20 February 2020 7:07
by MarloCZ
Thank you, it works very well.
I have one more request, is somehow done to change temperatures not after one minute, but after 5 (10) seconds
Thank you
Re: Concatenating an URL with values from sensors.
Posted: Thursday 20 February 2020 14:58
by waaren
MarloCZ wrote: ↑Thursday 20 February 2020 7:07
is somehow done to change temperatures not after one minute, but after 5 (10) seconds
Thank you
That's possible with the attached script. Please note that the temperature shown can be 50 seconds behind measured temperature. It is possible to have a real-time temperature with a different approach but that would require dzVents >= 3.0.0
Code: Select all
-- Send temperature of two sensors alternately to ESP Easy every 10 seconds
local scriptVar = 'Temperature to ESPEasy'
return
{
on =
{
timer =
{
'every minute',
},
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = scriptVar,
},
execute = function(dz, item)
local display = {}
display[0] = dz.utils.round(dz.devices('Outdoor_thermometer').temperature,1)
display[1] = dz.utils.round(dz.devices('Indoor_thermometer').temperature,1)
local function sendTemp(selector)
temperature = display[selector % 2]
local ESPEasyURL = 'http://192.168.7.71/control?cmd='
dz.openURL(
{
url = ESPEasyURL .. '7dt,' .. temperature,
method = 'GET',
}).afterSec(selector * 10)
end
-- main
for i = 0, 5 do
sendTemp(i)
end
end
}
Re: Concatenating an URL with values from sensors.
Posted: Thursday 20 February 2020 17:37
by MarloCZ
Thank you very much, it works great.

Re: Concatenating an URL with values from sensors.
Posted: Thursday 20 February 2020 17:44
by waaren
MarloCZ wrote: ↑Thursday 20 February 2020 17:37
Thank you very much, it works great.
Show us a picture please ?
Re: Concatenating an URL with values from sensors.
Posted: Friday 21 February 2020 15:48
by MarloCZ
Picture of what? A picture of the display?
I am currently testing two adults, 7 numbers and 4 numbers.
https://uloz.to/file/Up42O3LzfwyK/2020- ... -40-50-jpg