Tempsensor Script, need Help

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

Moderator: leecollings

Post Reply
mastadook
Posts: 58
Joined: Wednesday 18 April 2018 13:03
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Deutschland
Contact:

Tempsensor Script, need Help

Post 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
________________________________________________________________________
global chief of permanent lightning and strike detonator
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Tempsensor Script, need Help

Post 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
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Kedi
Posts: 536
Joined: Monday 20 March 2023 14:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Somewhere in NL
Contact:

Re: Tempsensor Script, need Help

Post by Kedi »

And use a '*' in the on section:

Code: Select all

	 on = { devices = 'Tempsensor*' },
Logic will get you from A to B. Imagination will take you everywhere.
mastadook
Posts: 58
Joined: Wednesday 18 April 2018 13:03
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Deutschland
Contact:

Re: Tempsensor Script, need Help

Post 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?
________________________________________________________________________
global chief of permanent lightning and strike detonator
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Tempsensor Script, need Help

Post by waltervl »

It is
If device.temperature >= 60 then
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest