Shelly and dzVents cannot fetch some json data
Posted: Saturday 17 October 2020 19:15
Hi,
I'm trying to extract some data from a shelly 2.5 device The script executing leaves me with some questions.
I checked for 2 devices, one with power consumption of 4.26 Watt and the other with power consumption 206.95 Watt
The first log:
The second log shows power consumption 0 instad of 206.95
This 206.95 cannot be fetched whilst the Voltage 231.66 is displayed without a problem.
Then there is this other question on how to fetch data from unit [0] (part of script)
I'm trying to extract some data from a shelly 2.5 device The script executing leaves me with some questions.
Code: Select all
-- Shelly (get watt)
-- Howto at Luftdaten https://www.domoticz.com/forum/viewtopic.php?f=72&t=23406&hilit=luftdaten
-- Call Shelly with http://192.168.x.x/status
return {
active = true,
on = {
timer = { 'every minute' }, -- every minute for testing, 10 minutes when active
httpResponses = { 'ShellyRetrieved' } -- matches callback string below
},
execute = function(domoticz, item)
if (item.isTimer) then
domoticz.openURL({
url = 'http://192.168.2.20/status',
method = 'GET',
callback = 'ShellyRetrieved'
})
elseif (item.isHTTPResponse) then
if (item.ok and item.isJSON) then
--domoticz.devices('Shell').updateCustomSensor(item.json.meters[0].power) -- Shelly-test.lua:22: attempt to index a nil value (field '?')
domoticz.devices('Shell').updateCustomSensor(item.json.meters[1].power) -- zero response instead of the value
domoticz.notify('Power ' .. item.json.meters[1].power, domoticz.PRIORITY_HIGH) -- zero response
--domoticz.notify('Is_valid ' .. item.json.meters[1].is_valid, domoticz.PRIORITY_LOW) --howto display TRUE or FALSE?
domoticz.log(item.json.meters[1].is_valid, domoticz.LOG_ERROR) -- displays correct as LOG_ERROR
domoticz.notify('Timestamp ' .. item.json.meters[1].timestamp, domoticz.PRIORITY_LOW) -- success
else
-- oops
domoticz.log('Error fetching Shelly data', domoticz.LOG_ERROR)
domoticz.log(item.data, domoticz.LOG_ERROR)
end
end
end
}The first log:
Code: Select all
2020-10-17 19:05:00.496 Status: dzVents: Info: ------ Start internal script: Shelly-test:, trigger: "every minute"
2020-10-17 19:05:00.497 Status: dzVents: Info: ------ Finished Shelly-test
2020-10-17 19:05:00.498 Status: EventSystem: Script event triggered: /home/rpi1/domoticz/dzVents/runtime/dzVents.lua
2020-10-17 19:05:01.420 Notification sent (browser) => Success
2020-10-17 19:05:01.421 Notification sent (browser) => Success
2020-10-17 19:05:01.110 Status: dzVents: Info: Handling httpResponse-events for: "ShellyRetrieved"
2020-10-17 19:05:01.111 Status: dzVents: Info: ------ Start internal script: Shelly-test: HTTPResponse: "ShellyRetrieved"
2020-10-17 19:05:01.204 Status: dzVents: Info: ------ Finished Shelly-test
2020-10-17 19:05:01.205 Status: EventSystem: Script event triggered: /home/rpi1/domoticz/dzVents/runtime/dzVents.lua
2020-10-17 19:05:01.404 Status: Notification: Power 4.26
2020-10-17 19:05:01.405 Status: Notification: Timestamp 1602961500 Code: Select all
2020-10-17 19:10:00.644 Status: dzVents: Info: ------ Start internal script: Shelly-test:, trigger: "every 5 minutes"
2020-10-17 19:10:00.645 Status: dzVents: Info: ------ Finished Shelly-test
2020-10-17 19:10:00.646 Status: EventSystem: Script event triggered: /home/rpi1/domoticz/dzVents/runtime/dzVents.lua
2020-10-17 19:10:01.633 Notification sent (browser) => Success
2020-10-17 19:10:01.634 Notification sent (browser) => Success
2020-10-17 19:10:01.298 Status: dzVents: Info: Handling httpResponse-events for: "ShellyRetrieved"
2020-10-17 19:10:01.298 Status: dzVents: Info: ------ Start internal script: Shelly-test: HTTPResponse: "ShellyRetrieved"
2020-10-17 19:10:01.483 Status: dzVents: Info: ------ Finished Shelly-test
2020-10-17 19:10:01.486 Status: EventSystem: Script event triggered: /home/rpi1/domoticz/dzVents/runtime/dzVents.lua
2020-10-17 19:10:01.607 Status: Notification: Power 0.0
2020-10-17 19:10:01.607 Status: Notification: Timestamp 1602961801 Then there is this other question on how to fetch data from unit [0] (part of script)
Code: Select all
domoticz.devices('Shell').updateCustomSensor(item.json.meters[0].power)
-- Shelly-test.lua:22: attempt to index a nil value (field '?')