Temperature controlled ceiling fan speed control

I currently have 7 scenes for each of my ceiling fans triggered via the room temperature and adjusting the fan speed (scenes represent 100%, 90%, 80% 70%, 60%, 55% and OFF)
This has created a lot of scenes but works OK.

What I am trying to do now is wrap each fan control into one scene.
Get temperature from thermostat, if fan is On and temperature = “X” then set fan speed at “%”

Is it possible to use decimals (ie. 77.5 - 77.6 - 77.7 etc) for the temperature set points as this would create a more fluid speed control with a wider field of adjustments than 1 degree temperature swings and the 10% adjustments I’m currently using.

The below code returns an error, but I think I’m on the right track, but how would (once the first set point works) does additional temperature references / loadleveltargets get added in? Just continue with If/Thens and luup.call_actions?

local Switch1 = 162 (State Device to bypass the temperature/speed control)
local Switch2 = 16 (Fan Dimmer)
T-stat = 14

[code]
local Switch1 = 162
local Switch2 = 16

local Light1State= luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”,“Status”, Switch1)
local Light2State= luup.variable_get(“urn:upnp-org:serviceId:Dimming1”, “LoadLevelStatus”, Switch2)

if (Light1State == “0”) or (Light2State == “0”)
then
return false
else

local lul_temp = luup.variable_get(“urn:upnp-org:serviceId:TemperatureSensor1”,“CurrentTemperature”, 14)
if ((tonumber(lul_temp) < 74
and tonumber(lul_temp) > 72)
then
luup.call_action(“urn:upnp-org:serviceId:Dimming1”, “SetLoadLevelTarget”, {newLoadlevelTarget = “50”}, 16)
return true
end[/code]

Any help greatly appreciated.

JOD.

This part works:

local Switch1 = 162 local Switch2 = 16 local Light1State= luup.variable_get("urn:upnp-org:serviceId:SwitchPower1","Status", Switch1) local Light2State= luup.variable_get("urn:upnp-org:serviceId:Dimming1", "LoadLevelStatus", Switch2) if (Light1State == "0") or (Light2State == "0") then return false else luup.call_action( "urn:upnp-ap15e-com:serviceId:SND1", "SendMail", { subject = 'Living Room Temperature ~79 Fan On 70%', body = 'Scene 172' }, 158 ) return true end
And this part works:

local lul_temp = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature", 14) if (tonumber(lul_temp) < 80) and (tonumber(lul_temp) > 78) then luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", {newLoadlevelTarget = "70"}, 16) return true else return false end
But having a problem joining them together.

JOD.

If I’m reading your first example correctly, you’re missing an “[tt]end[/tt]”, at the end of the scene code… I’ll write it here, with the extra “end” in it (untested), and will indent the code blocks to illustrate it (hopefully)

[code]local Switch1 = 162
local Switch2 = 16

local Light1State = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”, “Status”, Switch1)
local Light2State = luup.variable_get(“urn:upnp-org:serviceId:Dimming1”, “LoadLevelStatus”, Switch2)

if (Light1State == “0”) or (Light2State == “0”) then
return false
else
local temp = luup.variable_get(“urn:upnp-org:serviceId:TemperatureSensor1”,“CurrentTemperature”, 14)
temp = tonumber(temp)
if ((temp < 74) and (temp > 72)) then
luup.call_action(“urn:upnp-org:serviceId:Dimming1”, “SetLoadLevelTarget”, {newLoadlevelTarget = “50”}, Switch2)
return true
end
end
[/code]

btw, you really should [tt]return true[/tt] (or [tt]return false[/tt]) at the end of every Scene block, right now there’s a case where you won’t return either, which has caused problems with Luup Scenes in Vera in some versions.

Thank you @guessed.

That worked…

When I get to this part:if ((temp < 74) and (temp > 72)) then luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", {newLoadlevelTarget = "50"}, Switch2)

Is it correct to continue with the code by adding (or) statements?

if ((temp < 75) and (temp > 73)) then luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", {newLoadlevelTarget = "60"}, Switch2) or if ((temp < 76) and (temp > 74)) then luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", {newLoadlevelTarget = "70"}, Switch2) or if ((temp < 77) and (temp > 75)) then luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", {newLoadlevelTarget = "80"}, Switch2)

JOD.

Slightly off topic, which controller do you use to control the fan speed? Are you using a standard dimmer switch?

Leviton is the only manufacturer currently manufacturing a 3-Speed Fan Control device - the VRF01-1LZ Vizia RF + 1.5A Scene Capable Quiet Fan Speed Control

@JOD,
Where you put
or if
Put instead
elseif

Thank you @guessed.

That works.
Apparantly only whole numbers can be used for the temperature (fractions are ignored) as far as being coupled with the Trane thermostat.
I’ll try it with a temperature/humidity sensor tonight that display’s decimals and see if I can get a wider response curve out of the fans.

@drag0n,

I’m using ACT ZDW120W’s

JOD.

You can use the Lua fn math.floor(…) to force all values to whole numbers. Then you could do == comparisons instead of the single-value ranges your currently using.

I wanted to use “When exact ambient temperature is reached” with the original scene setups but was forced to use < & > because “When exact ambient temperature is reached” is still broken and brings up a “comparison” box.

The Lua fn math.floor is WAY over my head and at least the code is working and I can now eliminate about 40 scenes.

JOD.