Page 1 of 1

Virtual Thermostat

Posted: Tuesday 02 April 2019 19:21
by deve87
Trying to make this work. When I have otherdevices['Varmeovn WC 1.etg'] == 'On' / 'Off'. Script won't execute.

Code: Select all

Setpoint = tonumber(otherdevices_svalues ['WC 1.etg'])
Temp = tonumber(otherdevices_svalues ['WC 1 etg'])
Hysteresis = 0.5

commandArray = {}
if (devicechanged['WC 1.etg'] or devicechanged['WC 1 etg']) then
if (Temp + Hysteresis < Setpoint) and otherdevices['Varmeovn WC 1.etg'] == 'On' then
    commandArray['Varmeovn WC 1.etg'] = 'Off'
    print ("Varmeovn inaktiv")
elseif
(Temp - Hysteresis > Setpoint) and otherdevices['Varmeovn WC 1.etg'] == 'Off' then
    commandArray['Varmeovn WC 1.etg'] = 'On'
    print ("Varmeovn aktiv")
end
end
return commandArray
When I remove otherdevices['Varmeovn WC 1.etg'] == 'xx' Script works but updates every time temp or setpoint changes (of cours)

Code: Select all

Setpoint = tonumber(otherdevices_svalues ['WC 1.etg'])
Temp = tonumber(otherdevices_svalues ['WC 1 etg'])
Hysteresis = 0.5

commandArray = {}
if (devicechanged['WC 1.etg'] or devicechanged['WC 1 etg']) then
if (Temp + Hysteresis < Setpoint) then
    commandArray['Varmeovn WC 1.etg'] = 'Off'
    print ("Varmeovn inaktiv")
elseif
(Temp - Hysteresis > Setpoint) then
    commandArray['Varmeovn WC 1.etg'] = 'On'
    print ("Varmeovn aktiv")
end
end
return commandArray
Why won't script work when otherdevices['Varmeovn WC 1.etg'] == 'On' / 'Off'' is present? I tried change it with a variable. Same thing

Re: Virtual Thermostat

Posted: Tuesday 02 April 2019 20:17
by deve87
Found the problem. When I use otherdevices. I cant use . (dot)
So when I changed otherdevices['Varmeovn WC 1.etg'] to otherdevices['Varmeovn WC 1etg']
Script executes

Code: Select all

Setpoint = tonumber(otherdevices_svalues ['WC 1etg']) -- Dummy Setpoint device
Temp = tonumber(otherdevices_svalues ['WC 1.etg']) -- Temperature sensor
Switch = 'Varmeovn WC 1etg' -- Heater name (do not use symbol like . , - etc and start every word with a big letter like 'Test Switch')
Hysteresis = 0.5 -- Changes stop and start point on Setpoint

commandArray = {}
if Temp - Hysteresis >= Setpoint and otherdevices[Switch] == 'On' then
    commandArray[Switch] = 'Off'
   print('Varme AV')
elseif Temp + Hysteresis <= Setpoint and otherdevices[Switch] == 'Off' then
    commandArray[Switch] = 'On'
    print('Varme PÅ')
end
return commandArray