How can I dump data from a device  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
HvdW
Posts: 612
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

How can I dump data from a device

Post by HvdW »

Hi,
I tried dumping data from my device.
Whatever I try, there is an error about a nil value.

Code: Select all

local myDevice = 'YR weer'

return {

	on = {
		devices = {'YR weer'},
		timer = {'every minute'},
	},

	logging = {
	    level = domoticz.LOG_DEBUG,
	    marker = 'Outside temperature',
	    },

	execute = function(domoticz, triggeredItem)
        -- myDevice.dump()
        -- dumpDeviceStatus(item.data, myDevice)
        -- dumpAttributes(myDevice)
        local outside_temperature = domoticz.devices('YR weer').temperature
        domoticz.log('temp = '.. outside_temperature, domoticz.LOG_DEBUG)
        domoticz.notify('notifyer', YR .. '  outside temperature  : '.. outside_temperature..'º',domoticz.PRIORITY_HIGH)

	end
}
and the error in the log file

Code: Select all

 2023-01-19 00:01:00.413 Error: dzVents: Error: (3.1.8) Outside temperature: An error occurred when calling event handler Temperatuur buiten
2023-01-19 00:01:00.413 Error: dzVents: Error: (3.1.8) Outside temperature: ...scripts/dzVents/generated_scripts/Temperatuur buiten.lua:16: bad argument #1 to 'dump' (function expected, got no value) 
Must be a very simple problem, however I can't find the bug.
Bugs bug me.
User avatar
waltervl
Posts: 5853
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: How can I dump data from a device  [Solved]

Post by waltervl »

In your script use
triggeredItem.dump()
or use
domoticz.devices(myDevice).dump()
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
HvdW
Posts: 612
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: How can I dump data from a device

Post by HvdW »

Thank you for the information @waltervl
I couldn't find it in the dzvents wiki.
After reading your information I now understand how to handle an attribute like dump() or any other.

The better choice to dump the complete json is: domoticz.devices(myDevice).dump()
Bugs bug me.
HvdW
Posts: 612
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: How can I dump data from a device

Post by HvdW »

I'm sorry to come back on this question but I still cannot retrieve how to dump()

Code: Select all

dz.devices('Power').dump()
returns this error: 2023-09-13 22:25:00.377 Error: dzVents: Error: (3.1.8) Afzonderlijke Meterstanden 1.10: .../dzVents/generated_scripts/P1 meterstanden gesplitst.lua:51: attempt to concatenate a nil value

Code: Select all

dz.log('Production        : ' ..P1.usageDelivered, dz.LOG_INFO)
dz.log('Consumtion      : ' ..P1.usage, dz.LOG_INFO)
works like a charm
usage2, usage1, return2, return1 no problem.
json Data: Data "30174158;16197288;11095429;26693622;510;0"

What's the secret for dump()

From the Wiki:

Code: Select all

P1 Smart meter

    counterDeliveredToday: Number.
    counterToday: Number.
    usage1, usage2: Number.
    return1, return2: Number.
    updateP1(usage1, usage2, return1, return2, cons, prod): Function. Updates the device. Supports command options.
    usage: Number.
    usageDelivered: Number.
Bugs bug me.
User avatar
waltervl
Posts: 5853
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: How can I dump data from a device

Post by waltervl »

Do you have more devices called 'Power'? As DzVents cannot handle this. For DzVents all device names should be unique.

What happens if you dump another device to the log?
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
waltervl
Posts: 5853
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: How can I dump data from a device

Post by waltervl »

For me it works
This code gives me be the dump as listed in the spoiler for a P1 smart meter device

Code: Select all

return {
	on = {
		timer = {
			'every minute',
		}
	},
	execute = function(domoticz, timer)
		domoticz.devices(67).dump()
	end
}
Spoiler: show
2023-09-13 23:02:00.036 Status: dzVents: device> signalLevel: 12
2023-09-13 23:02:00.036 Status: dzVents: device> id: 67
2023-09-13 23:02:00.036 Status: dzVents: device> description:
2023-09-13 23:02:00.036 Status: dzVents: device> batteryLevel: 255
2023-09-13 23:02:00.036 Status: dzVents: device> switchTypeValue: 0
2023-09-13 23:02:00.036 Status: dzVents: device> name: P1 Smart Meter
2023-09-13 23:02:00.036 Status: dzVents: device> switchType: On/Off
2023-09-13 23:02:00.036 Status: dzVents: device> lastLevel: 0
2023-09-13 23:02:00.036 Status: dzVents: device> baseType: device
2023-09-13 23:02:00.036 Status: dzVents: device> data:
2023-09-13 23:02:00.036 Status: dzVents: device> _state: 3879384;3171962;3169839;141761;2100;100
2023-09-13 23:02:00.036 Status: dzVents: device> counterDeliveredToday: 5.479 kWh
2023-09-13 23:02:00.036 Status: dzVents: device> customImage: 0
2023-09-13 23:02:00.036 Status: dzVents: device> protected: false
2023-09-13 23:02:00.036 Status: dzVents: device> hardwareID: 4
2023-09-13 23:02:00.036 Status: dzVents: device> hardwareType: Dummy (Does nothing, use for virtual switches only)
2023-09-13 23:02:00.036 Status: dzVents: device> icon: counter
2023-09-13 23:02:00.036 Status: dzVents: device> counterToday: 11.315 kWh
2023-09-13 23:02:00.036 Status: dzVents: device> hardwareName: Dummy
2023-09-13 23:02:00.036 Status: dzVents: device> usage: 2100 Watt
2023-09-13 23:02:00.036 Status: dzVents: device> counterDelivered: 3311.6000976562
2023-09-13 23:02:00.036 Status: dzVents: device> usageDelivered: 100 Watt
2023-09-13 23:02:00.036 Status: dzVents: device> _nValue: 0
2023-09-13 23:02:00.036 Status: dzVents: device> counter: 7051.346
2023-09-13 23:02:00.036 Status: dzVents: device> hardwareTypeValue: 15
2023-09-13 23:02:00.036 Status: dzVents: device> unit: 1
2023-09-13 23:02:00.036 Status: dzVents: device> timedOut: false
2023-09-13 23:02:00.036 Status: dzVents: device> subType: Energy
2023-09-13 23:02:00.036 Status: dzVents: device> iconNumber: 34
2023-09-13 23:02:00.036 Status: dzVents: device> protected: false
2023-09-13 23:02:00.036 Status: dzVents: device> image:
2023-09-13 23:02:00.036 Status: dzVents: device> deviceID: 82067
2023-09-13 23:02:00.036 Status: dzVents: device> changed: false
2023-09-13 23:02:00.036 Status: dzVents: device> deviceType: P1 Smart Meter
2023-09-13 23:02:00.036 Status: dzVents: device> lastUpdate: 2023-09-13 23:00:00
2023-09-13 23:02:00.036 Status: dzVents: device> rawData:
2023-09-13 23:02:00.036 Status: dzVents: device> 1: 3879384
2023-09-13 23:02:00.036 Status: dzVents: device> 2: 3171962
2023-09-13 23:02:00.036 Status: dzVents: device> 3: 3169839
2023-09-13 23:02:00.036 Status: dzVents: device> 4: 141761
2023-09-13 23:02:00.036 Status: dzVents: device> 5: 2100
2023-09-13 23:02:00.036 Status: dzVents: device> 6: 100
2023-09-13 23:02:00.036 Status: dzVents: device> active: false
2023-09-13 23:02:00.036 Status: dzVents: device> protected: false
2023-09-13 23:02:00.036 Status: dzVents: device> deviceId: 82067
2023-09-13 23:02:00.036 Status: dzVents: device> actualWatt: 2100
2023-09-13 23:02:00.036 Status: dzVents: device> icon: counter
2023-09-13 23:02:00.036 Status: dzVents: device> unit: 1
2023-09-13 23:02:00.036 Status: dzVents: device> usageDelivered: 100
2023-09-13 23:02:00.036 Status: dzVents: device> hardwareTypeValue: 15
2023-09-13 23:02:00.036 Status: dzVents: device> hardwareID: 4
2023-09-13 23:02:00.036 Status: dzVents: device> sValue: 3879384;3171962;3169839;141761;2100;100
2023-09-13 23:02:00.036 Status: dzVents: device> deviceType: P1 Smart Meter
2023-09-13 23:02:00.036 Status: dzVents: device> changed: false
2023-09-13 23:02:00.036 Status: dzVents: device> isGroup: false
2023-09-13 23:02:00.036 Status: dzVents: device> _adapters:
2023-09-13 23:02:00.036 Status: dzVents: device> 1: P1 smart meter energy device adapter
2023-09-13 23:02:00.036 Status: dzVents: device> isHTTPResponse: false
2023-09-13 23:02:00.036 Status: dzVents: device> hardwareType: Dummy (Does nothing, use for virtual switches only)
2023-09-13 23:02:00.036 Status: dzVents: device> rawData:
2023-09-13 23:02:00.036 Status: dzVents: device> 1: 3879384
2023-09-13 23:02:00.036 Status: dzVents: device> 2: 3171962
2023-09-13 23:02:00.036 Status: dzVents: device> 3: 3169839
2023-09-13 23:02:00.036 Status: dzVents: device> 4: 141761
2023-09-13 23:02:00.036 Status: dzVents: device> 5: 2100
2023-09-13 23:02:00.036 Status: dzVents: device> 6: 100
2023-09-13 23:02:00.037 Status: dzVents: device> switchTypeValue: 0
2023-09-13 23:02:00.037 Status: dzVents: device> WhActual: 2100
2023-09-13 23:02:00.037 Status: dzVents: device> counterDelivered: 3311.6000976562
2023-09-13 23:02:00.037 Status: dzVents: device> inActive: true
2023-09-13 23:02:00.037 Status: dzVents: device> deviceSubType: Energy
2023-09-13 23:02:00.037 Status: dzVents: device> name: P1 Smart Meter
2023-09-13 23:02:00.037 Status: dzVents: device> signalLevel: 12
2023-09-13 23:02:00.037 Status: dzVents: device> switchType: On/Off
2023-09-13 23:02:00.037 Status: dzVents: device> isDevice: true
2023-09-13 23:02:00.037 Status: dzVents: device> counter: 7051.346
2023-09-13 23:02:00.037 Status: dzVents: device> counterToday: 11.315
2023-09-13 23:02:00.037 Status: dzVents: device> _state: 3879384;3171962;3169839;141761;2100;100
2023-09-13 23:02:00.037 Status: dzVents: device> baseType: device
2023-09-13 23:02:00.037 Status: dzVents: device> hardwareId: 4
2023-09-13 23:02:00.037 Status: dzVents: device> _nValue: 0
2023-09-13 23:02:00.037 Status: dzVents: device> lastUpdate: 2023-09-13 23:00:00
2023-09-13 23:02:00.037 Status: dzVents: device> isScene: false
2023-09-13 23:02:00.037 Status: dzVents: device> isVariable: false
2023-09-13 23:02:00.037 Status: dzVents: device> description:
2023-09-13 23:02:00.037 Status: dzVents: device> isHardware: false
2023-09-13 23:02:00.037 Status: dzVents: device> usage2: 3171962
2023-09-13 23:02:00.037 Status: dzVents: device> usage1: 3879384
2023-09-13 23:02:00.037 Status: dzVents: device> bState: false
2023-09-13 23:02:00.037 Status: dzVents: device> counterDeliveredToday: 5.479
2023-09-13 23:02:00.037 Status: dzVents: device> id: 67
2023-09-13 23:02:00.037 Status: dzVents: device> isSecurity: false
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
HvdW
Posts: 612
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: How can I dump data from a device

Post by HvdW »

I did this:
dz.log('Dumpdata : ' ..domoticz.devices(67).dump(), dz.LOG_INFO)

Dzvents does not like my way of calling the dump() function and press it into a LOG statement.

Lesson learned.

Thanks Walter.
Bugs bug me.
User avatar
waltervl
Posts: 5853
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: How can I dump data from a device

Post by waltervl »

off course as the dump function is doing that writing to the log for you (as described in the wiki)
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest