what is wrong with this script?

Moderator: leecollings

Post Reply
tiga
Posts: 159
Joined: Friday 27 May 2016 20:15
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: nederland
Contact:

what is wrong with this script?

Post by tiga »

i combined some scripts together to make this function:

when i measure a windgust >6m/s(cpnj wind) it puts on a dummyswitch ('windvlaag >6m/s 15 min').
when it is not updated to on for more than 15 minutes....then it should go to off.

Code: Select all

t1 = os.time()
s = otherdevices_lastupdate['windvlaag >6m/s 15 min']
 
year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)
t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference = (os.difftime (t1, t2))


commandArray = {}


if devicechanged['cpnj wind'] then
--Windmeter data:
sWindDirectionDegrees, sWindDirection, sWindSpeed, sWindGust, sWindTemperature, sWindFeel = otherdevices_svalues['cpnj wind']:match("([^;]+);([^;]+);([^;]+);([^;]+);([^;]+);([^;]+)")

sWindDirectionDegrees = tonumber(sWindDirectionDegrees);
sWindDirection = (sWindDirection);
sWindSpeed = tonumber(sWindSpeed);
sWindGust = tonumber(sWindGust);
sWindTemperature = tonumber(sWindTemperature);
sWindFeel = tonumber(sWindFeel);

print("Windmeter: Winddirection (in degrees) is: " .. sWindDirectionDegrees .. " ");
print("Windmeter: Winddirection is: " .. sWindDirection .. " ");
print("Windmeter: Windspeed is: " .. sWindSpeed .. " ");
print("Windmeter: Windgust is: " .. sWindGust .. " ");
print("Windmeter: Windtemperature is: " .. sWindTemperature .. " ");
print("Windmeter: Windfeel is: " .. sWindFeel .. " ");

end

if sWindGust > 60 then
    commandArray['windvlaag >6m/s 15 min']='On'
end

if (otherdevices['windvlaag >6m/s 15 min'] == 'On' and difference > 900) then
    commandArray['windvlaag >6m/s 15 min']='Off'
end

return commandArray
but this is what i see in my log:

Code: Select all

2017-10-25 22:01:46.949 Error: EventSystem: in >15m/s_test: [string "t1 = os.time()..."]:38: attempt to compare number with nil
what is wrong with this code?

i run this script in the 'all' mode
Wolfgang
Posts: 22
Joined: Saturday 28 October 2017 21:37
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: what is wrong with this script?

Post by Wolfgang »

Hi ,

are you sure that the variable sWindGust has really content in it ?

'nil' is an empty content.
tiga
Posts: 159
Joined: Friday 27 May 2016 20:15
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: nederland
Contact:

Re: what is wrong with this script?

Post by tiga »

i think i have fixed the problem...
this is how it looks now:

Code: Select all

t1 = os.time()
s = otherdevices_lastupdate['windvlaag >6m/s 15 min']
-- returns a date time like 2013-07-11 17:23:12
 
year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)
t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference = (os.difftime (t1, t2))


commandArray = {}


if devicechanged['cpnj wind'] then

    
--Windmeter data:
sWindDirectionDegrees, sWindDirection, sWindSpeed, sWindGust, sWindTemperature, sWindFeel = otherdevices_svalues['cpnj wind']:match("([^;]+);([^;]+);([^;]+);([^;]+);([^;]+);([^;]+)")

sWindDirectionDegrees = tonumber(sWindDirectionDegrees);
sWindDirection = (sWindDirection);
sWindSpeed = tonumber(sWindSpeed);
sWindGust = tonumber(sWindGust);
sWindTemperature = tonumber(sWindTemperature);
sWindFeel = tonumber(sWindFeel);

--print("Windmeter: Winddirection (in degrees) is: " .. sWindDirectionDegrees .. " ");
--print("Windmeter: Winddirection is: " .. sWindDirection .. " ");
--print("Windmeter: Windspeed is: " .. sWindSpeed .. " ");
--print("Windmeter: Windgust is: " .. sWindGust .. " ");
--print("Windmeter: Windtemperature is: " .. sWindTemperature .. " ");
--print("Windmeter: Windfeel is: " .. sWindFeel .. " ");

    if sWindGust > 60 then
    commandArray['windvlaag >6m/s 15 min']='On'
    print("Windmeter:windvlaag > dan 6m/s, timer in werking voor 15 minuten")
end
end

if (otherdevices['windvlaag >6m/s 15 min'] == 'On' and difference > 900) then
    commandArray['windvlaag >6m/s 15 min']='Off'
end

return commandArray

i have moved the "end" a little bit and run it on "device"
tiga
Posts: 159
Joined: Friday 27 May 2016 20:15
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: nederland
Contact:

Re: what is wrong with this script?

Post by tiga »

now i am ficing an other problem.if the last time 'windvlaag >6m/s 15 min' was triggert...lets say yesterday...
if the script gets triggert today, the condition "difference > 900" is immediately true so 'windvlaag >6m/s 15 min' is turnd off directly.

is it possible to get the last "On" update time from a device???that would fix the problem.

i attempted: s = otherdevices_lastupdate['windvlaag >6m/s 15 min']=='On' but that doesn't work
DutchHans
Posts: 230
Joined: Friday 03 April 2015 20:44
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Germany (near dutch border)
Contact:

Re: what is wrong with this script?

Post by DutchHans »

Instead of >900 make it >900 and <930 than it only fires once.
Cheers, Hans
tiga
Posts: 159
Joined: Friday 27 May 2016 20:15
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: nederland
Contact:

Re: what is wrong with this script?

Post by tiga »

thanks hans that could do the trick.

i have changed the script a little bit and i think i have got it.

Code: Select all

commandArray = {}

if devicechanged['cpnj wind'] then

--Windmeter data:
sWindDirectionDegrees, sWindDirection, sWindSpeed, sWindGust, sWindTemperature, sWindFeel = otherdevices_svalues['cpnj wind']:match("([^;]+);([^;]+);([^;]+);([^;]+);([^;]+);([^;]+)")

sWindDirectionDegrees = tonumber(sWindDirectionDegrees);
sWindDirection = (sWindDirection);
sWindSpeed = tonumber(sWindSpeed);
sWindGust = tonumber(sWindGust);
sWindTemperature = tonumber(sWindTemperature);
sWindFeel = tonumber(sWindFeel);

--print("Windmeter: Winddirection (in degrees) is: " .. sWindDirectionDegrees .. " ");
--print("Windmeter: Winddirection is: " .. sWindDirection .. " ");
--print("Windmeter: Windspeed is: " .. sWindSpeed .. " ");
--print("Windmeter: Windgust is: " .. sWindGust .. " ");
--print("Windmeter: Windtemperature is: " .. sWindTemperature .. " ");
--print("Windmeter: Windfeel is: " .. sWindFeel .. " ");

    if sWindGust > 60 then
    commandArray['windvlaag >6m/s 15 min']='On'
    print("Windmeter:windvlaag > dan 6m/s, timer in werking voor 15 minuten")
end
end

if (otherdevices['windvlaag >6m/s 15 min']=='On') then
    t1 = os.time()
    s = otherdevices_lastupdate['windvlaag >6m/s 15 min']
    -- returns a date time like 2013-07-11 17:23:12
    year = string.sub(s, 1, 4)
    month = string.sub(s, 6, 7)
    day = string.sub(s, 9, 10)
    hour = string.sub(s, 12, 13)
    minutes = string.sub(s, 15, 16)
    seconds = string.sub(s, 18, 19)
    t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
    difference = (os.difftime (t1, t2))
    --print ("last update:"..tostring(s))
end

if (otherdevices['windvlaag >6m/s 15 min']=='On' and difference > 900) then
    commandArray['windvlaag >6m/s 15 min']='Off'
end

return commandArray

i need to test it a little bit but i thinks this works
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest