Page 1 of 1

[SOLVED] updating virtual powermeter in LUA

Posted: Wednesday 07 August 2024 13:59
by sebitop
Hi everybody

since a couple of hours I'm struggling on a very simple thing wich consist in updating a virtual powermeter device with a value in LUA so if someone would have a second pairs of eyes and spot what I'm missing it would be fantastic

here is the code :

Code: Select all

	local linky = otherdevices[getdevicename(linky)]
        print(linky)
	local linky = string.match(linky, "^(%d+)")
	print(linky)
	commandArray['UpdateDevice'] = 1639 .. "|0|" .. linky

in a nutshell

1) I retrieve a value from another counter called LINKY so it gets a value like : 500;682591.8871 (first print linky)

2) as I just want the first value I do a string.match to get only the first part so the second print shows 510

3) I try to update the power meter just to get 500 KWH in it (the cumulative will be done using computed mode in the power meter) so I tried the command array update device but nothing comes up into the device

1639 is the correct number of the device and if I modify the the nvalue number in the formula it apparently changes in the devices values
but the concern is that I don't get a single proper KWH value in this device

thanks for your precious help !

cheers
seb

Re: updating virtual powermeter in LUA

Posted: Wednesday 07 August 2024 15:32
by sebitop
Finaly found my problem

the code is correct but when you create the virtual device using domoticz, if you don't select ACCEPT DEVICES FOR 5 MINUTES you will see the device but it won't work correctly

I deleted the device, activated the acceptance, recreated the virtual device and it works !

damn got it !

hope it will help !