What am I doing wrong here?

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

[quote=“resq93, post:1, topic:171584”]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[/quote]

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

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.

@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

Could the same not be accomplished with timers? Seems simpler.

looks right now.

another one…

I need help with this line…

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?

looks ok to me. did you try it out?

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

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?

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))?

What behaviour do you want when the dew point is exactly 64? Your code sample only tests for less-than or greater-than.

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)

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.