Put data from counter/sensor into virtual device

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

Moderator: leecollings

Post Reply
Mirkoser
Posts: 32
Joined: Tuesday 28 August 2018 15:36
Target OS: Linux
Domoticz version: 2021/1
Location: Germany
Contact:

Put data from counter/sensor into virtual device

Post 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
Attachments
Bildschirmfoto vom 2022-02-06 10-14-22.png
Bildschirmfoto vom 2022-02-06 10-14-22.png (38.43 KiB) Viewed 984 times
Bildschirmfoto vom 2022-02-06 10-13-54.png
Bildschirmfoto vom 2022-02-06 10-13-54.png (36.52 KiB) Viewed 984 times
User avatar
waltervl
Posts: 5738
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Put data from counter/sensor into virtual device

Post 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
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