Page 1 of 1
temp comparison
Posted: Monday 01 August 2016 0:39
by Nomader
Can anyone help me why the following is not working...The email part is working ok.. but the temperature is not..I am using a virtual sensor which is getting the temp from WU.. i am also using the script to split the values in WU data. wu_temp is my virtual temperature sensor which works fine.
I have also tried blocky but no luck aswell
Code: Select all
commandArray = {}
if (tonumber(devicechanged['wu_temp']) > 10.5 ) then
commandArray[1]={['SendEmail']='Subject# #[email protected]'}
end
return commandArray
this is my log:
Code: Select all
2016-08-01 01:38:49.304 EventSystem: Script event triggered: C:\Program Files (x86)\Domoticz\scripts\lua\script_device_sensorWU.lua
2016-08-01 01:38:49.307 Error: EventSystem: in script3: [string "commandArray = {}..."]:3: attempt to compare number with nil
2016-08-01 01:38:49.082 (Weather Underground) Temp + Humidity + Baro (TEMP_HUM_BARO)
2016-08-01 01:38:49.475 Error: EventSystem: in script3: [string "commandArray = {}..."]:3: attempt to compare number with nil
2016-08-01 01:38:49.392 (Weather Underground) Wind (WIND)
2016-08-01 01:38:49.653 Error: EventSystem: in script3: [string "commandArray = {}..."]:3: attempt to compare number with nil
2016-08-01 01:38:49.558 (Weather Underground) UV (UV)
2016-08-01 01:38:49.819 Error: EventSystem: in script3: [string "commandArray = {}..."]:3: attempt to compare number with nil
2016-08-01 01:38:49.736 (Weather Underground) Rain (RAIN)
2016-08-01 01:38:49.902 (Weather Underground) General/Visibility (Unknown)
Re: temp comparison
Posted: Monday 01 August 2016 0:52
by trixwood
Your script runs on
any device change. And it's possible your device has not changed. And thus is not in that array (hence the nil).
You probabaly want something like:
Code: Select all
commandArray = {}
if (devicechanged['wu_temp']) then
if (otherdevices_svalues['wu_temp'] > 10.5 ) then
commandArray[1]={['SendEmail']='Subject# #[email protected]'}
end
end
return commandArray
Re: temp comparison
Posted: Monday 01 August 2016 1:05
by Nomader
i tested that, (although i don't understand what (otherdevices_svalues['wu_temp'] does.. but still the event is not starting...
Re: temp comparison
Posted: Monday 01 August 2016 1:17
by trixwood
Sorry i think i forgot the tonumber
It's late, tired)
Code: Select all
commandArray = {}
if (devicechanged['wu_temp']) then
if (tonumber(otherdevices_svalues['wu_temp']) > 10.5 ) then
commandArray[1]={['SendEmail']='Subject# #[email protected]'}
end
end
return commandArray
Maybe it is... without s_values i always get confused between those two.
Code: Select all
commandArray = {}
if (devicechanged['wu_temp']) then
if (tonumber(otherdevices['wu_temp']) > 10.5 ) then
commandArray[1]={['SendEmail']='Subject# #[email protected]'}
end
end
return commandArray
Need to catch zome Zzzs... good luck!
Re: temp comparison
Posted: Monday 01 August 2016 1:24
by Nomader
thanks for answering... but i tried both, the event is not triggered... this is very frustrating
Re: temp comparison
Posted: Monday 01 August 2016 2:05
by trixwood
Then it's time to use the print statements to debug:
Code: Select all
commandArray = {}
print ('Device wu_temp changed:' .. devicechanged['wu_temp'])
if (devicechanged['wu_temp']) then
print ('Device value:' .. tonumber(otherdevices['wu_temp']))
if (tonumber(otherdevices['wu_temp']) > 10.5 ) then
commandArray[1]={['SendEmail']='Subject# #[email protected]'}
end
end
return commandArray
And a fresh restart of domoticz would be nice. Sometimes the event system does not reset itself properly.
Sleeeepp....
Re: temp comparison
Posted: Monday 01 August 2016 9:46
by Nomader
good morning
nothing again
Code: Select all
2016-08-01 10:43:52.259 EventSystem: reset all device statuses...
2016-08-01 10:43:52.260 EventSystem: Started
2016-08-01 10:44:02.859 LUA: WU Script Parsed Temp=32.2 Humidity=27 Pressure=1011
2016-08-01 10:44:02.955 EventSystem: Script event triggered: C:\Program Files (x86)\Domoticz\scripts\lua\script_device_sensorWU.lua
2016-08-01 10:44:02.958 Error: EventSystem: in script5: [string "commandArray = {}..."]:2: attempt to concatenate field 'wu_temp' (a nil value)
2016-08-01 10:44:02.726 (Weather Underground) Temp + Humidity + Baro (TEMP_HUM_BARO)
2016-08-01 10:44:03.200 Error: EventSystem: in script5: [string "commandArray = {}..."]:2: attempt to concatenate field 'wu_temp' (a nil value)
2016-08-01 10:44:03.044 (Weather Underground) Wind (WIND)
2016-08-01 10:44:03.370 Error: EventSystem: in script5: [string "commandArray = {}..."]:2: attempt to concatenate field 'wu_temp' (a nil value)
2016-08-01 10:44:03.277 (Weather Underground) Rain (RAIN)
2016-08-01 10:45:14.068 EventSystem: reset all events...
Re: temp comparison
Posted: Monday 01 August 2016 9:52
by trixwood
i'm incapacitated when no sleep, made the same mistake as you.
Code: Select all
commandArray = {}
--the following can not work.... can't print a nil value... sleepy me...
--print ('Device wu_temp changed:' .. devicechanged['wu_temp'])
if (devicechanged['wu_temp']) then
print ('Yeah, device changed')
print ('Device value:' .. tonumber(otherdevices['wu_temp']))
if (tonumber(otherdevices['wu_temp']) > 10.5 ) then
commandArray[1]={['SendEmail']='Subject# #[email protected]'}
end
end
return commandArray
Re: temp comparison
Posted: Monday 01 August 2016 10:14
by Nomader
i thought you slept enough yesterday
1still i get nothing.. the log has no trace of the script trigering at all.. i restart domoticz every time..
Re: temp comparison
Posted: Monday 01 August 2016 10:33
by Nomader
update:
i changed wu_temp with the mother device of WU
commandArray = {}
if (devicechanged['TEMP_HUM_BARO']) then
print ('Device value:' .. tonumber(otherdevices['wu_temp']))
if (tonumber(otherdevices['wu_temp']) > 10 ) then
commandArray[1]={['SendEmail']='Subject# #
[email protected]'}
end
end
return commandArray
that did send an email succesfully.. but it did not print any other thing... so your code seems corect.. but domoticz can not handle the virtual sensor somehow
2016-08-01 11:28:54.749 EventSystem: Started
2016-08-01 11:29:05.425 LUA: WU Script Parsed Temp=32.8 Humidity=25 Pressure=1011
2016-08-01 11:29:05.588 EventSystem: Script event triggered: C:\Program Files (x86)\Domoticz\scripts\lua\script_device_sensorWU.lua
2016-08-01 11:29:05.592 LUA: Device value:32.8
2016-08-01 11:29:05.592 EventSystem: Script event triggered: script5
2016-08-01 11:29:05.284 (Weather Underground) Temp + Humidity + Baro (TEMP_HUM_BARO)
2016-08-01 11:29:05.687 (Weather Underground) Wind (WIND)
2016-08-01 11:29:05.954 (Weather Underground) Rain (RAIN)
2016-08-01 11:29:10.105 Notification sent (Email
can you explain to me what does "otherdevices" mean in if (tonumber(otherdevices['wu_temp']) > 10 )
Re: temp comparison
Posted: Monday 01 August 2016 10:36
by trixwood
I'm still sleepy
Good it works.
print ('Device value:' .. tonumber(otherdevices['wu_temp']))
is
LUA: Device value:32.8
strange it does not get triggered...
still sleepy..... Zzzz....
Re: temp comparison
Posted: Monday 01 August 2016 10:41
by Nomader
so it prints ok and it does the comparison of the temperature ok... the only thing is I can not trigger it correctly
print ('Device value:' .. tonumber(otherdevices['wu_temp']) what does the "otherdevices" mean?
Re: temp comparison
Posted: Monday 01 August 2016 10:47
by trixwood
devicechanged is an array of devices which have changed value since the last loop.
otherdevices is an array with all main values of all the devices.
otherdevices _svaluesis an array with all the values of all the devices with all there values (if then have more then one).
if (tonumber(otherdevices['wu_temp']) > 10 ) then
means if the value of the device 'wu_temp' (convert to number first) is bigger then 10 then ...
not sure why the virtual switch is not working...
Nap time.
Re: temp comparison
Posted: Monday 01 August 2016 12:04
by Nomader
thank you very much, you 've been more than helpfull