Virtual energy sensor script problem

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

Moderator: leecollings

Post Reply
tonymer
Posts: 16
Joined: Wednesday 15 June 2022 16:43
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Virtual energy sensor script problem

Post by tonymer »

Hello everyone, I have a virtual energy sensor created with the available energy that I have at all times. If I have excess it is in +, if I lack it is in -. Well, I want to do things when the available energy is less than 0 and it doesn't work for me. I don't know where I have the error. The virtual sensor is of type Dummy

Code: Select all

return {
	on = {
		timer = {
			'every minute','at 9:00-19:00','on mon,tue,wed,thu',	function(domoticz)
			    
			return true
			end,
		}
	},
	logging = {
		level = domoticz.LOG_INFO,
		marker = 'template',
	},
	execute = function(domoticz, timer)
	    
	    
	    
	   if(tonumber((domoticz.devices("Energia Disponible").actualWatt)<0)) then
	       
	       print("No hay energia suficiente: "..domoticz.devices("Energia Disponible").actualWatt)
	       domoticz.devices('Luz Buhardilla Dos').switchOn()
	       domoticz.variables('inversor_notificacion').set(true)
       end
       
	    if(tonumber(domoticz.devices("Energia Disponible").actualWatt)>2500) then
	       print("Se resetea inverosr_notificacion porque hay energia suficiente")
	       domoticz.variables('inversor_notificacion').set(false)
	   end
	    
	    
		domoticz.log('Timer event was triggered by ' .. timer.trigger, domoticz.LOG_INFO)
	end
}
User avatar
waltervl
Posts: 5721
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Virtual energy sensor script problem

Post by waltervl »

Why do you use tonumber() as these .actualWatt values are already numbers so evaluation for < 0 or > 2500 should be no issue.
Perhaps temporarely log the value so you can see what you are getting.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
tonymer
Posts: 16
Joined: Wednesday 15 June 2022 16:43
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Virtual energy sensor script problem

Post by tonymer »

Thanks for answering. I'm going to try without tonumber but the problem is with negative values. The sensor can have negative values ​​when it is importing from the network and it is there when the condition does not work. I'll try removing tonumber
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest