I am unable to update 2 virtual sensors in Domoticz 2024-4 on a Raspi. VERSION="11 (bullseye)"
It throws an error:
"Method updateCustomSensor is not available for device "amps" (deviceType=General, deviceSubType=Current). If you believe this is not correct, please report.
2024-05-06 19:50:00.290 Error: dzVents: Error: (3.1.8) Method updateCustomSensor is not available for device "voltage" (deviceType=General, deviceSubType=Voltage).
I do get the correct data from the Youless which is copied into a temp file.
I used "curl" because the http poller did not work as expected in one way or another..
Here is the raw received data from the Youless 192.168.1.14/f that is copied as "http_response.txt" to the /home/pi/domoticz dir, and chmodded to 777 to no avail....
------------
{"ver": 50,"tr": 2,"i1": 3.000,"i2": 0.000,"i3": 0.000,"v1": 225.800,"v2": 0.000,"v3": 0.000,"l1": 449,"l2": 0,"l3": 0}
--------------
I am only interested in the "i1" and 'V1" values, these are supposed to be extracted and converted to json via this DzEvent script.
Can anyone shine a light on what I am doing wrong here?
Thanks in Advance!
Code: Select all
local tempFilePath = '/home/pi/domoticz/http_response.txt' -- Path to temporary file
return {
on = {
timer = { 'every 1 minutes' }
},
execute = function(domoticz)
local url = 'http://192.168.1.14/f'
-- Hardcoded URL that creates the tempfile ,it does get created on the Pi as a TXT file:
-- {"ver": 50,"tr": 2,"i1": 7.000,"i2": 0.000,"i3": 0.000,"v1": 223.300,"v2": 0.000,"v3": 0.000,"l1": 1675,"l2": 0,"l3": 0}
-- Send HTTP request and save response to temporary file
os.execute('curl -s ' .. url .. ' > ' .. tempFilePath)
-- Read response from temporary file
local file = io.open(tempFilePath, 'r')
if file then
local response = file:read('*all')
file:close()
domoticz.log('Received HTTP response: ' .. response, domoticz.LOG_DEBUG)
-- Extract the values behind "i1" and "v1"
local i1_value = response:match('"i1": (%d+%.?%d*)')
local v1_value = response:match('"v1": (%d+%.?%d*)')
if i1_value and v1_value then
-- Create a JSON string manually
local jsonString = string.format('{"i1": %s, "v1": %s}', i1_value, v1_value)
-- Update Domoticz virtual sensors Assuming IDX 9 for "amps" and IDX 10 for "voltage"
domoticz.devices(9).updateCustomSensor(jsonString)
domoticz.devices(10).updateCustomSensor(jsonString)
domoticz.log('Updated virtual sensors with JSON data.', domoticz.LOG_DEBUG)
else
domoticz.log('Failed to extract values behind "i1" and "v1" from the response.', domoticz.LOG_ERROR)
end
else
domoticz.log('Failed to open temporary file.', domoticz.LOG_ERROR)
end
end
}