Page 1 of 1

Tempsensor Script, need Help

Posted: Saturday 29 April 2023 7:55
by mastadook
Hi Friends,

I have a small Script, that in the first Step, should send me a Mail, when one of the Temp Sensors reach a hight Temperature:

Code: Select all

return {
	active = true,
	
	 on = { devices = { 'Tempsensor1',
	                    'Tempsensor2,
	                    'Tempsensor3',
	                    'Tempsensor4',
	                    'Tempsensor5',
	                    'Tempsensor6',
	                    'Tempsensor7',
	                    'Tempsensor8',
	                    'Tempsensor9,
	                    'Tempsensor10'}},

	execute = function(domoticz, device, email)

if 
domoticz.devices('Tempsensor1').temperature >= 60
or
domoticz.devices('Tempsensor2').temperature >= 60
or
domoticz.devices('Tempsensor3').temperature >= 60 
or
domoticz.devices('Tempsensor4').temperature >= 60 
or
domoticz.devices('Tempsensor5').temperature >= 60 
or
domoticz.devices('Tempsensor6').temperature >= 60 
or
domoticz.devices('Tempsensor7').temperature >= 60
or
domoticz.devices('Tempsensor8').temperature >= 60
or
domoticz.devices('Tempsensor9').temperature >= 60 
or
domoticz.devices('Tempsensor10').temperature >= 45


then domoticz.devices('Feueralarm').updateAlertSensor(domoticz.ALERTLEVEL_RED, 'Feueralarm!!! prüfen und evakuieren!')
     domoticz.email('Feueralarm Temperatursensoren', 'Achtung stark erhöhte Temperaturwerte von '  .. device.name .. '  '  .. device.temperature .. ' °C , es könnte auch ein Feuer sein, prüfen und evakuieren!', '[email protected]')

else domoticz.devices('Feueralarm').updateAlertSensor(domoticz.ALERTLEVEL_GREEN, 'alle Temperatursensoren im grünen Bereich, alles OK')

end
end
    }
For Testing purposes I changed the Setting for one Sensor to 20°
Now all Sensors that are over 20° sends me a single Alarm Mail.
Why?
I just want to receive it only from the affected one.

Hope you understand what my Problem is and maybe you see my Error, I can't find it.
Please help

Re: Tempsensor Script, need Help

Posted: Saturday 29 April 2023 12:17
by waltervl
The email is showing device.name but that is in your case only the device that triggered the script because of it changed its temperature.

So if tempsensor9 is is triggered with temperature 15 but tempsensor10 > 20 the device.name will be tempsensor9

So you also have to store the device name if you would like to do it this way.

BUT much easier would be to change your long if statement with all devices in a simple device.temperature check:

Code: Select all

If device.temperature >= 60 then

Re: Tempsensor Script, need Help

Posted: Saturday 29 April 2023 12:34
by Kedi
And use a '*' in the on section:

Code: Select all

	 on = { devices = 'Tempsensor*' },

Re: Tempsensor Script, need Help

Posted: Saturday 29 April 2023 14:55
by mastadook

Code: Select all

return {
	active = true,
	
	 on = { devices = { 'Tempsensor*'}},

	execute = function(domoticz, device, email)
if 
devices.temperature >= 60

then domoticz.devices('Feueralarm').updateAlertSensor(domoticz.ALERTLEVEL_RED, 'Feueralarm!!! prüfen und evakuieren!')
     domoticz.email('Feueralarm Temperatursensoren', 'Achtung stark erhöhte Temperaturwerte von '  .. device.name .. '  '  .. device.temperature .. ' °C , es könnte auch ein Feuer sein, prüfen und evakuieren!', '[email protected]')

else domoticz.devices('Feueralarm').updateAlertSensor(domoticz.ALERTLEVEL_GREEN, 'alle Temperatursensoren im grünen Bereich, alles OK')

end
end
    }
So I now cleaned up the Code, this should be better?

Re: Tempsensor Script, need Help

Posted: Saturday 29 April 2023 15:27
by waltervl
It is
If device.temperature >= 60 then