hi can anyone explaine why the if statement if waarde == 280 then wind = "N" is not working
we get the value of the device but the update(wind) in idx 8 is always "W"
commandArray = {}
wind="W"
-- loop through all the changed devices
for deviceName,deviceValue in pairs(devicechanged) do
print ("Device based event fired on '"..deviceName.."', value '"..tostring(deviceValue).."'");
if (deviceName=='windmeter') then
waardes = tostring(deviceValue)
end
if (deviceName=='wind') then
waarde = tonumber(deviceValue)
if waarde == 280 then wind = "N"
else wind = "NW"
end
end
print(waardes)
print(waarde)
commandArray['UpdateDevice']='8|sValue|0;'..wind..';'..waardes..';0;0;0'
end
return commandArray
if statment not working lua
Moderator: leecollings
-
- Posts: 3
- Joined: Sunday 21 January 2018 12:22
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
- jvdz
- Posts: 2335
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: if statment not working lua
I see you test for 2 different devicenames and for both of those different devices set the same domotics device. I would think that the result will be that you update it 2 times and thus only contain the information of the last device. right?
Jos
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: if statment not working lua
This is because you set waarde to nil in your script. Have a look at this one.gertvanwijk1 wrote: ↑Wednesday 22 May 2019 22:11 hi can anyone explaine why the if statement if waarde == 280 then wind = "N" is not working
we get the value of the device but the update(wind) in idx 8 is always "W"
Code: Select all
commandArray = {}
wind="W"
-- loop through all the changed devices
for deviceName,deviceValue in pairs(devicechanged) do
if deviceName == 'DarkSky wind' then
print ("Device based event fired on '"..deviceName.."', value '"..tostring(deviceValue).."'");
if deviceName == 'DarkSky wind' then
waardes = tostring(deviceValue)
end
if deviceName == 'DarkSky wind' then
waarde = tonumber(deviceValue) -- this cannot work as deviceValue is something like '157.00;SSE;6;7;12.3;12.3'
print("waarde: " .. tostring(waarde) ) -- nil
waarde = tonumber(deviceValue:match("([^;]+)")) -- get the value before the first ;
print("waarde: " .. tostring(waarde) )
if waarde == 280 then
wind = "N"
else
wind = "NW"
end
end
print("waardes: " .. waardes )
print("waarde: " .. tostring(waarde) )
print("wind: " .. wind )
end
end
return commandArray
relevant loglines
- Spoiler: show
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 3
- Joined: Sunday 21 January 2018 12:22
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: if statment not working lua
hi Waaren
Thanks for the reply
The value we get from our selfmade windvaan is for example 300
It is always a 3 digit number
We have 2 sensors one for the wind direction and one for windspeed
we want to convert the digit to for example to NE
then we want the 2 values send to idx 8
Thanks for the reply
The value we get from our selfmade windvaan is for example 300
It is always a 3 digit number
We have 2 sensors one for the wind direction and one for windspeed
we want to convert the digit to for example to NE
then we want the 2 values send to idx 8
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: if statment not working lua
Can you you add this small Lua script and let it execute for a couple of minutes. It will give some information on what values are in your wind devices. It might help in creating the solution you look for.gertvanwijk1 wrote: ↑Thursday 23 May 2019 19:48 The value we get from our selfmade windvaan is for example 300
We have 2 sensors one for the wind direction and one for windspeed
Code: Select all
commandArray = {}
for deviceName,deviceValue in pairs(devicechanged) do
if deviceName:match('Wind') or deviceName:match('wind') then
print("waarde: " .. deviceName .. " " .. tostring(deviceValue) )
for key, value in pairs (devicechanged) do
print(key .. ": ==>> " .. value )
end
end
end
return commandArray
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 3
- Joined: Sunday 21 January 2018 12:22
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: if statment not working lua
Hi Waaren,
this is the result from the script you gave us
now we want to convert 280
so far so good
the next thing we want is the value form windmeter
this is now 0 there is no wind
stil so far so good
the next thing is to get it into domoticz idx 8
en then it fails
this is the complete script
so what is wrong?
this is the result from the script you gave us
Code: Select all
2019-06-05 19:46:09.846 Status: LUA: windmeter: ==>> -0
2019-06-05 19:46:10.801 Status: Warning: Expecting svalue with at least 5 elements separated by semicolon, 1 elements received ("280"), notification not sent (Hardware: 2 - Dummy, ID: 82001, Unit: 1, Type: 56 - Wind, SubType: 1 - WTGR800)
2019-06-05 19:46:10.809 Status: LUA: waarde: wind 280
2019-06-05 19:46:10.809 Status: LUA: wind: ==>> 280
2019-06-05 19:46:10.948 Status: Warning: Expecting svalue with at least 5 elements separated by semicolon, 1 elements received ("0"), notification not
Code: Select all
if (waarde and waarde > 304 and waarde and waarde < 308) then wind ="N"
elseif (waarde and waarde > 277 and waarde and waarde < 283) then wind ="NE"
elseif (waarde and waarde > 255 and waarde and waarde < 261) then wind ="E"
elseif (waarde and waarde > 236 and waarde and waarde < 242) then wind ="SE"
elseif (waarde and waarde > 220 and waarde and waarde < 226) then wind ="S"
elseif (waarde and waarde > 206 and waarde and waarde < 212) then wind ="SW"
elseif (waarde and waarde > 193 and waarde and waarde < 199) then wind ="W"
elseif (waarde and waarde > 182 and waarde and waarde < 188) then wind ="NW"
the next thing we want is the value form windmeter
Code: Select all
if (deviceName=='windmeter') then
waardes = tostring(deviceValue)
end
stil so far so good
the next thing is to get it into domoticz idx 8
Code: Select all
commandArray['UpdateDevice']='8|sValue|0;'..wind..';'..waardes..';0;0;0'
this is the complete script
Code: Select all
commandArray = {}
waardes = 100
-- loop through all the changed devices
for deviceName,deviceValue in pairs(devicechanged) do
print ("Device based event fired on '"..deviceName.."', value '"..tostring(deviceValue).."'");
if (deviceName=='wind') then
waarde = tonumber(deviceValue)
if (waarde and waarde > 304 and waarde and waarde < 308) then wind ="N"
elseif (waarde and waarde > 277 and waarde and waarde < 283) then wind ="NE"
elseif (waarde and waarde > 255 and waarde and waarde < 261) then wind ="E"
elseif (waarde and waarde > 236 and waarde and waarde < 242) then wind ="SE"
elseif (waarde and waarde > 220 and waarde and waarde < 226) then wind ="S"
elseif (waarde and waarde > 206 and waarde and waarde < 212) then wind ="SW"
elseif (waarde and waarde > 193 and waarde and waarde < 199) then wind ="W"
elseif (waarde and waarde > 182 and waarde and waarde < 188) then wind ="NW"
end
if (deviceName=='windmeter') then
waardes = tostring(deviceValue)
end
end
print(wind)
print(waarde)
print(waardes)
commandArray['UpdateDevice']='8|sValue|0;'..wind..';'..waardes..';0;0;0'
end
return commandArray
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: if statment not working lua
Sorry but I pass for the standard Lua stuff here. The script below is a possible solution using dzvents.
When not yet familiar with dzVents please start with reading Get started before implementing. It will only take a couple of minutes.
Special attention please for "In Domoticz go to Setup > Settings > Other and in the section EventSystem make sure the checkbox 'dzVents disabled' is not checked. Also make sure that in the Security section in the settings you allow 127.0.0.1 to not need a password. dzVents uses that port to send certain commands to Domoticz. Finally make sure you have set your current location in Setup > Settings > System > Location, otherwise there is no way to determine nighttime/daytime state."
Code: Select all
-- Transfer wind
return {
on = { devices = { 'wind' }},
logging = { level = domoticz.LOG_DEBUG,
marker = 'wind' },
execute = function(dz, item)
local waardes = 10
local windDirection = item.rawData[1] or -1 -- don't know what the devicetype of wind is so assume direction is rawData[1]
local targetDevice = dz.devices(8) -- Type wind
local function val2Wind(degrees)
if degrees > 304 then return 'N' end
if degrees > 277 then return 'NE' end
if degrees > 255 then return 'SE' end
if degrees > 236 then return 'S' end
if degrees > 220 then return 'SW' end
if degrees > 206 then return 'W' end
if degrees > 193 then return 'NW' end
return '-'
end
targetDevice.updateWind( windDirection, val2Wind(tonumber(windDirection)), waardes, waardes, 0 , 0 )
end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Who is online
Users browsing this forum: No registered users and 1 guest