Page 1 of 1

Virtual energy sensor script problem

Posted: Tuesday 28 June 2022 18:47
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
}

Re: Virtual energy sensor script problem

Posted: Tuesday 28 June 2022 23:28
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.

Re: Virtual energy sensor script problem

Posted: Wednesday 29 June 2022 9:16
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