Page 1 of 1

My stupid Owl script

Posted: Saturday 23 January 2016 10:24
by Aadr
I am not new to Domoticz, but I am a slow learner, I guess.
I am trying to make a script to control the public lights at the soccerclub. I have an Owl device watching the energy comsuption, and when it exceeds the limit of 15 kW the public lights should turn off.
But after searching the forums and trying lots of possibilities, my scripts will not work. And I cannot figure out why not.

Is the someone out there, who will help me with the script I made so far.

The print-command is execuded good, but the switch 'Multi' will not act.

Code: Select all

--script Veldverlichting aan dan straatverlichting uit


commandArray = {}
  c = 15000 --Watt treshold energy usage
  s = otherdevices_svalues['Veld/straatverlichting'] -- gets value from owl energy device monitoring veldverlichting
 

function five()   -- function to get only usage from string
   local f = (string.sub(s, 1, 5))
   return f 
   end


k = five(f)

   if (devicechanged['Veld/straatverlichting'] and tonumber(k) > c)  then -- triggers compare two numbers
       commandArray['Multi 1'] = 'off'  -- switches straatverlichting off 
              print("straatverlichting uit")  -- prints status
   end
   
return commandArray
many thanks in advance.

Re: My stupid Owl script

Posted: Saturday 23 January 2016 11:31
by bizziebis
If the print works, then so would your script. The only thing I can see is you set the Multi switch to 'off' instead of 'Off'. But I don't know if its case sensitive.

Re: My stupid Owl script

Posted: Saturday 23 January 2016 11:56
by jmleglise
hi,
Something's curious with your function. You have no parameters.
should be :
function five(s) -- function to get only usage from string
return f
end

try this :

Code: Select all

    --script Veldverlichting aan dan straatverlichting uit

    commandArray = {}
    c = 15000 --Watt treshold energy usage
    s = otherdevices_svalues['Veld/straatverlichting'] -- gets value from owl energy device monitoring veldverlichting

    k = string.sub(s, 1, 5)
    if (devicechanged['Veld/straatverlichting'] and tonumber(k) > c)  then -- triggers compare two numbers
           commandArray['Multi 1'] = 'Off'  -- switches straatverlichting off
           print("straatverlichting uit")  -- prints status
    end

-- and for debugging : 
print('K:'..k)
print('s:'..s)
print('C:'..c)
print(otherdevices_svalues['Multi 1'])
print(otherdevices['Multi 1'])

    return commandArray

Re: My stupid Owl script

Posted: Saturday 23 January 2016 12:33
by Aadr
Joepie!!!! :D :D :D

Thank you very much, Bizziebis, the command is indeed case sensitive.

jmleglise; thanks for your reply, I will try your improvements as well. I think I can learn from them.