LUA - Virtual Counter device issues with crazy values

Moderator: leecollings

Post Reply
jake
Posts: 744
Joined: Saturday 30 May 2015 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

LUA - Virtual Counter device issues with crazy values

Post by jake »

I use a virtual counter device to count a calculated amount of energy.
The problem is that at 00:00 and at some more hours the log shows crazy high numbers
counter_log.jpg
counter_log.jpg (50.03 KiB) Viewed 586 times
I might have done something wrong (obviously) and I deleted and recreated this type of sensor a couple of times to get rid of those values, because there is no way to reset the counter.
I try to take all measures to prevent uploading the wrong data:
The energy is in Watthours so kWh's are avoided in my calculation
Counter can only increase: I have a check built in that only higher new data is accepted

Now I try to read the sensor by this script (which all works fine with use of a 'custom sensor')

Code: Select all

if tonumber(otherdevices["Solar battery usage"]) == nil then
			old_battery_energy_usage_value = 0
			print (otherdevices["Solar battery usage"])
			print ("old battery energy usage value was NIL. Either it is a first start of the script (new virtual sensor), or something is wrong")
		else
			--Download the previous value of the solar battery energy usage in Wh
			old_battery_energy_usage_value = tonumber(otherdevices_svalues["Solar battery usage"])
		end
		print ("Old value of the solar battery energy usage is " .. old_battery_energy_usage_value .. "Wh")
Problem is that I can't properly read back my data, because I have updated the counter data just before. My own 'shield' to prevent a NIL error is now against me, because the '0' value is of course lower than the stored value.

I write the data to the counter as follows:

Code: Select all

		if new_battery_energy_usage_value > old_battery_energy_usage_value then
			commandArray['UpdateDevice'] = battery_energy_usage_idx .. '|0|' .. new_battery_energy_usage_value
		else
			print ("Something went wrong, the new solar battery usage value of "..new_battery_energy_usage_value.." is smaller than the previous value of "..old_battery_energy_usage_value)
		end
What is causing these crazy numbers in the log and how can I avoid them?
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest