Page 1 of 1

Put data from counter/sensor into virtual device

Posted: Sunday 06 February 2022 10:24
by Mirkoser
Hi,

im a newbie in terms of dvents but i've already created some working srcipts for my energy counters. Now i need a small hint how to transfer data from "real devices" in domoticz into virtual devices in domoticz.
My idea is to modify/filter the data (due to negative values/bad counting) and send the corrected data to the virtual device

For this example i want to show the data of daily usage of my NIBE heatpump . The device 1029 was automatically created by the NIBE heatpump script, so that i cannot change the device anymore.
My script should check every hour the device 1029 and receive the value and transfer it into the new virtual device XXXX
But i have no idea how to do it. But it should be similar to my http request script, correct?

Code: Select all

return {
	on = {
		timer = {
			'every minute' -- just an example to trigger the request
		},
		httpResponses = { 'Wallbox' } -- must match with the callback passed to the openURL command
		
	},
	logging = {
		level = domoticz.LOG_INFO,
		marker = 'Wallbox_auto',
	},
	execute = function(domoticz, item)

		if (item.isTimer) then
			domoticz.openURL({
				url = 'http://admin:[email protected]//cnf?cmd=modbus&device=meter2&read=all',
				method = 'GET',
				callback = 'Wallbox', -- see httpResponses above.
			})
			
			
	end

	if (item.isHTTPResponse) then

			if (item.ok) then
				if (item.isJSON) then

					local Power = item.json['8062d']
					local Energie = item.json['8050q']
				
					  domoticz.log(item.json['8062d'] , domoticz.LOG_INFO)
					 domoticz.log(item.json['8050q'] , domoticz.LOG_INFO)
					
					 	domoticz.devices('Wallbox').updateElectricity(item.json['8062d'],item.json['8050q'])
					 
					end


	end
end
end
}
Image

Image

Re: Put data from counter/sensor into virtual device

Posted: Sunday 06 February 2022 10:50
by waltervl
In DzVents you can get values directly from a sensor. No need for a http command.
Get the device type of the original device in menu setup devices , get the correct value function from the DzVents wiki, get the value and update the new sensor.
So for example for a custom sensor the get value command is
local oldvalue = domoticz.devices('mysensorname').sensorValue