OK thanks for all suggestions I got one step further.
Domoticz is replaced with dz where needed.
Now the log spits the correct data for the script as HvdW suggested.
2024-01-28 13:07:00.434 Status: dzVents: Info: ESP32: ------ Start internal script: EPS32 T+H+R:, trigger: "every minute"
2024-01-28 13:07:00.434 Status: dzVents: Debug: ESP32: OpenURL: url = 192.168.1.19
2024-01-28 13:07:00.434 Status: dzVents: Debug: ESP32: OpenURL: method = GET
2024-01-28 13:07:00.434 Status: dzVents: Debug: ESP32: OpenURL: post data = nil
2024-01-28 13:07:00.434 Status: dzVents: Debug: ESP32: OpenURL: headers = nil
2024-01-28 13:07:00.434 Status: dzVents: Debug: ESP32: OpenURL: callback = ESP32_getJSON
2024-01-28 13:07:00.434 Status: dzVents: Info: ESP32: ------ Finished EPS32 T+H+R
2024-01-28 13:07:00.436 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2024-01-28 13:07:00.877 Status: dzVents: Info: Handling httpResponse-events for: "ESP32_getJSON"
2024-01-28 13:07:00.877 Status: dzVents: Info: ESP32: ------ Start internal script: EPS32 T+H+R: HTTPResponse: "ESP32_getJSON"
2024-01-28 13:07:00.878 Status: dzVents: > mac: 24:6F:2
2024-01-28 13:07:00.879 Status: dzVents: > humidity: 51.00
2024-01-28 13:07:00.879 Status: dzVents: > th_error:
2024-01-28 13:07:00.879 Status: dzVents: > relay_high_level: 1
2024-01-28 13:07:00.879 Status: dzVents: > type: TH&Relay
2024-01-28 13:07:00.879 Status: dzVents: > relay_error:
2024-01-28 13:07:00.879 Status: dzVents: > wifi_ssi: -53
2024-01-28 13:07:00.879 Status: dzVents: > fahrenheit: 62.60
2024-01-28 13:07:00.879 Status: dzVents: > celsius: 17.00
2024-01-28 13:07:00.879 Status: dzVents: > version: 4
2024-01-28 13:07:00.879 Status: dzVents: > relay_high: 0
2024-01-28 13:07:00.879 Status: dzVents: > name: Thermostaat
2024-01-28 13:07:00.879 Status: dzVents: Info: ESP32: ------ Finished EPS32 T+H+R
2024-01-28 13:07:04.659 Status: EventSystem: reset all events...
2024-01-28 13:07:04.661 Status: dzVents: Write file: /home/pi/domoticz/scripts/dzVents/generated_scripts/EPS32 T+H+R.lua
Then I tried to understand the logic that comes from HvdW his example but it throws an error.
Code used now
Code: Select all
local scriptVar = 'ESP32'
return
{
on =
{
timer =
{
'every minute',
},
httpResponses =
{
scriptVar .. '*',
},
},
logging =
{
level = domoticz.LOG_DEBUG, -- set to domoticz.LOG_ERROR when all OK
marker = scriptVar,
},
execute = function(dz, item)
--local temperature = dz.devices(32) -- set to id of your virtual temperature sensor
--local humidity = dz.devices(64) -- set to id of your virtual humidity sensor
--local relay = dz.devices(34) -- set to id of your virtual text device
if item.isTimer then
dz.openURL(
{
url = '192.168.1.19',
callback = scriptVar .. '_getJSON',
})
elseif item.isHTTPResponse and item.isJSON then
domoticz.devices(32).updateTemperature(item.json.celsius)
-- temperature.updateTemperature(item.json.celsius)
-- humidity.updateHumidity(item.json.humidity)
-- relay.updateText(item.json.relay_high)
dz.utils.dumpTable(item.json)
else
dz.log('There was a problem handling the request', dz.LOG_ERROR)
dz.log(item, dz.LOG_DEBUG)
end
end
}
It throws this as log...
2024-01-28 13:10:00.450 Status: dzVents: Info: ESP32: ------ Start internal script: EPS32 T+H+R:, trigger: "every minute"
2024-01-28 13:10:00.451 Status: dzVents: Debug: ESP32: OpenURL: url = 192.168.1.19
2024-01-28 13:10:00.451 Status: dzVents: Debug: ESP32: OpenURL: method = GET
2024-01-28 13:10:00.451 Status: dzVents: Debug: ESP32: OpenURL: post data = nil
2024-01-28 13:10:00.451 Status: dzVents: Debug: ESP32: OpenURL: headers = nil
2024-01-28 13:10:00.451 Status: dzVents: Debug: ESP32: OpenURL: callback = ESP32_getJSON
2024-01-28 13:10:00.451 Status: dzVents: Info: ESP32: ------ Finished EPS32 T+H+R
2024-01-28 13:10:00.453 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2024-01-28 13:10:00.863 Status: dzVents: Info: Handling httpResponse-events for: "ESP32_getJSON"
2024-01-28 13:10:00.864 Status: dzVents: Info: ESP32: ------ Start internal script: EPS32 T+H+R: HTTPResponse: "ESP32_getJSON"
2024-01-28 13:10:00.865 Status: dzVents: Info: ESP32: ------ Finished EPS32 T+H+R
2024-01-28 13:10:00.865 Error: dzVents: Error: (3.1.8) ESP32: An error occurred when calling event handler EPS32 T+H+R
2024-01-28 13:10:00.865 Error: dzVents: Error: (3.1.8) ESP32: ...moticz/scripts/dzVents/generated_scripts/EPS32 T+H+R.lua:34: attempt to index a nil value (global 'domoticz')
Line 34 = domoticz.devices(32).updateTemperature(item.json.celsius)
Paco