We have moved at community.getvera.com

Author Topic: What am I doing wrong here?  (Read 3752 times)

Offline resq93

  • Sr. Member
  • ****
  • Posts: 272
  • Karma: +0/-2
What am I doing wrong here?
« on: May 22, 2012, 07:43:43 pm »
Please see my code below, I can only get this scene to work when the conditions on the first line are true, what am I missing? I need this to work when either set of conditions are met.

Thanks,

local t = os.date('*t')
local dayOfWeek = t.wday
away = luup.variable_get("urn:upnp-org:serviceId:VSwitch1","Status",19)
avg = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 49)
outside = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 5)

local runScene = false

if (away=="0") and (t.hour > 7) and (t.hour < 18) and (dayofweek~=7) and (tonumber(avg) > 74) and (tonumber(outside) > 60) then

runScene = true
end

if (away=="0") and (t.hour < 7) and (t.hour > 18) and (dayofweek~=7) and (tonumber(avg) > 72) and (tonumber(outside) > 60) then


runScene = true
end


if (away=="0") and ((dayofweek==1) or (dayofweek==7)) and (tonumber(avg) > 72) and (tonumber(outside) > 60) then


runScene = true
end

return runScene

Offline cubs2b23

  • Full Member
  • ***
  • Posts: 102
  • Karma: +2/-0
Re: What am I doing wrong here?
« Reply #1 on: May 22, 2012, 08:06:34 pm »

if (away=="0") and (t.hour < 7) and (t.hour > 18) and (dayofweek~=7) and (tonumber(avg) > 72) and (tonumber(outside) > 60) then


runScene = true
end


If I'm reading this right I don't think that this section will ever return true. How can t.hour be less than 7 AND greater than 18 at the same time.  Were you intending it to be an OR so more like:

if (away=="0") and ((t.hour < 7) or (t.hour > 18)) and (dayofweek~=7) and (tonumber(avg) > 72) and (tonumber(outside) > 60) then
runScene = true
end

Offline capjay

  • Hero Member
  • *****
  • Posts: 675
  • Karma: +9/-3
Re: What am I doing wrong here?
« Reply #2 on: May 22, 2012, 08:23:01 pm »
cubs2b23 is right.

Also I think you should be using "ifelse" for the rest of the if statements. please explain what you have in mind so we can help.

Offline resq93

  • Sr. Member
  • ****
  • Posts: 272
  • Karma: +0/-2
Re: What am I doing wrong here?
« Reply #3 on: May 23, 2012, 12:32:10 am »
@cubs2b23

Thanks, that seems to do the trick

@capjay

This scene turns the A/C when all the conditions on either line are met and the "away" virtual switch is not engaged.

line 1: if its between 0700 and 1800 and the day is not Saturday and the room temp is >74 and the outside temp is >60

OR

line 2: if its between 1800 and 0700 and the day is not saturday and the room temp is >72 and the outside temp is >60

or line 3: if it IS saturday, and the room temp is >72 and outside temp is >60

then run the scene

Offline DeltaNu1142

  • Hero Member
  • *****
  • Posts: 1153
  • Karma: +40/-67
Re: What am I doing wrong here?
« Reply #4 on: May 23, 2012, 01:57:27 am »
Could the same not be accomplished with timers?  Seems simpler.
Vera 3 @ UI5 | HomeWave | PLEG

Offline capjay

  • Hero Member
  • *****
  • Posts: 675
  • Karma: +9/-3
Re: What am I doing wrong here?
« Reply #5 on: May 23, 2012, 03:17:33 am »
This scene turns the A/C ...

looks right now.

Offline resq93

  • Sr. Member
  • ****
  • Posts: 272
  • Karma: +0/-2
Re: What am I doing wrong here?
« Reply #6 on: May 23, 2012, 03:40:30 pm »
another one....

I need help with this line....


Quote
if (away=="0") and (t.hour > 7) and (t.hour < 18) and (dayofweek~=7) and (tonumber(outside) > 60) and

(

((tonumber(avg) <= 74) and (tonumber(DewPoint) < 64))


or

((tonumber(avg) <= 72) and (tonumber(DewPoint) > 64))

)
then


runScene = true
end

I'd like <= 72 to be the trigger when the dewpoint is > 64 but <=74 to be the trigger when the dewpoint is <64 (in other words, A/C runs longer when dewpoint is high)

can this be done?
« Last Edit: May 23, 2012, 03:56:00 pm by resq93 »

Offline capjay

  • Hero Member
  • *****
  • Posts: 675
  • Karma: +9/-3
Re: What am I doing wrong here?
« Reply #7 on: May 24, 2012, 05:01:11 am »
looks ok to me. did you try it out?

Offline resq93

  • Sr. Member
  • ****
  • Posts: 272
  • Karma: +0/-2
Re: What am I doing wrong here?
« Reply #8 on: May 24, 2012, 12:15:41 pm »
Yes I tried. Yesterday, the dew point was above 64 yet the AC kept shutting down when the temp hit 74. According to my arguments it should have only shut off at 72

m

Offline cubs2b23

  • Full Member
  • ***
  • Posts: 102
  • Karma: +2/-0
Re: What am I doing wrong here?
« Reply #9 on: May 24, 2012, 12:45:29 pm »
avg represents the indoor temp, correct?  Then wouldn't you want it to be (tonumber(avg) >= 74) and (tonumber(avg) >= 72) so that the scene runs until the indoor temp has come down to either 74 or 72?

Offline resq93

  • Sr. Member
  • ****
  • Posts: 272
  • Karma: +0/-2
Re: What am I doing wrong here?
« Reply #10 on: May 24, 2012, 12:49:24 pm »
Yes, avg is indoor. I want the temp to go below (or equal) to 74 or 72 before it shuts off. Remember, this is a scene that triggers an 'off' function. So I think <= is correct.

Should it make a difference whether its  ((tonumber(avg) <= 74) and (tonumber(DewPoint) < 64)) or  ((tonumber(DewPoint) < 64) and (tonumber(avg) <= 74))?
« Last Edit: May 24, 2012, 12:51:10 pm by resq93 »

Offline futzle

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3260
  • Karma: +192/-9
Re: What am I doing wrong here?
« Reply #11 on: May 24, 2012, 05:41:49 pm »
What behaviour do you want when the dew point is exactly 64? Your code sample only tests for less-than or greater-than.

Offline resq93

  • Sr. Member
  • ****
  • Posts: 272
  • Karma: +0/-2
Re: What am I doing wrong here?
« Reply #12 on: May 24, 2012, 06:08:52 pm »
Will that make a difference? When I was testing, the dew point was 66 yet the AC kept shutting off at 74 instead of running until 72. (If it does make a difference I would say that at 64 I would go with  the 74 setting)

Offline futzle

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3260
  • Karma: +192/-9
What am I doing wrong here?
« Reply #13 on: May 24, 2012, 06:47:54 pm »
I'm pointing out a bug in your code in post #7, not the reason for the behaviour that you report in #9. Sorry I wasn't clear about that.