Difference between revisions of "Radio Thermostat"
Line 26: | Line 26: | ||
[http://forum.linuxmce.org/index.php/topic,11706.0.html] | [http://forum.linuxmce.org/index.php/topic,11706.0.html] | ||
+ | |||
+ | The template is in process but is #2235. The code below is under development: | ||
+ | |||
+ | [[User:Techstyle|Techstyle]] #193 off: | ||
+ | |||
+ | data = "{\"tmode\":" # Current mode of HVAC operation | ||
+ | data+="0}" # Off | ||
+ | log("tmode set data: " + data) | ||
+ | tstat_set(data) | ||
+ | |||
+ | [[User:Techstyle|Techstyle]] #192 on: | ||
+ | |||
+ | data+="3}" # Auto | ||
+ | log("tmode set data: " + data) | ||
+ | tstat_set(data) | ||
+ | |||
+ | [[User:Techstyle|Techstyle]] #279 set fan: | ||
+ | data = "{\"fmode\":" | ||
+ | if onoff == "1" | ||
+ | data+="2}" # Fan is always on | ||
+ | else | ||
+ | data+="0}" # Auto | ||
+ | end | ||
+ | |||
+ | log("fmode set data: " + data) | ||
+ | tstat_set(data) | ||
+ | |||
+ | [[User:Techstyle|Techstyle]] #280 set heat/cool: | ||
+ | |||
+ | data = "{\"tmode\":" | ||
+ | if onoff == "H" | ||
+ | data+="1" # Heat only | ||
+ | elsif onoff == "C" | ||
+ | data+="2" # Cool only | ||
+ | else | ||
+ | data+="3" # Auto | ||
+ | end | ||
+ | |||
+ | data+="}" | ||
+ | |||
+ | log("tmode set data: " + data) | ||
+ | |||
+ | tstat_set(data) | ||
+ | |||
+ | [[User:Techstyle|Techstyle]] # 278 set temperature: | ||
+ | |||
+ | if ((value_to_assign[0,1]=="+") || (value_to_assign[0,1]=="-")) | ||
+ | # The new setpoint is relative to the current setpoint | ||
+ | new_temp = celcius_to_farhenheit(Float(@setpoint)).round + value_to_assign.to_i | ||
+ | else | ||
+ | # The new setpoint is absolute | ||
+ | new_temp = celcius_to_farhenheit(Float(value_to_assign.to_i)).round | ||
+ | end | ||
+ | |||
+ | # to set the temp, we must know the mode | ||
+ | case $tstathash["tmode"].to_s | ||
+ | when "1" | ||
+ | data = "{\"t_heat\":" + new_temp.to_s + "}" | ||
+ | when "2" | ||
+ | data = "{\"t_cool\":" + new_temp.to_s + "}" | ||
+ | end | ||
+ | log("Set temp data: " + data) | ||
+ | tstat_set(data) | ||
+ | |||
+ | [[User:Techstyle|Techstyle]] #373 Private method listing: | ||
+ | |||
+ | # Helper function for logging | ||
+ | def log(word) | ||
+ | $logFile.print(word + "\n") | ||
+ | $logFile.flush() | ||
+ | end | ||
+ | |||
+ | def get() | ||
+ | |||
+ | # Reconnect to the device | ||
+ | conn_.Reconnect() | ||
+ | |||
+ | # Send the request | ||
+ | s = "GET /tstat HTTP/1.1\r\n" | ||
+ | s += "\r\n" | ||
+ | conn_.Send(s) | ||
+ | |||
+ | # Wait for a reply | ||
+ | recv = "" | ||
+ | while(true) | ||
+ | buff=conn_.Recv(256, 5000) | ||
+ | if(buff.length() == 0) | ||
+ | break | ||
+ | end | ||
+ | recv = recv + buff | ||
+ | end | ||
+ | |||
+ | # Check that we got a response and try to parse through it | ||
+ | if (recv=~ /^HTTP[^\r\n]+200\sOK.+?\r\n\r\n(.+)$/m) | ||
+ | #parse temp | ||
+ | $tstathash["temp"] = recv.to_s.scan(/\{\"temp\"Sad.*?),/) | ||
+ | |||
+ | #parse tmode | ||
+ | $tstathash["tmode"] = recv.to_s.scan(/\"tmode\"Sad.*?),/) | ||
+ | |||
+ | #parse fmode | ||
+ | $tstathash["fmode"] = recv.to_s.scan(/\"fmode\"Sad.*?),/) | ||
+ | |||
+ | #parse override | ||
+ | $tstathash["override"] = recv.to_s.scan(/\"override\"Sad.*?),/) | ||
+ | |||
+ | #parse hold | ||
+ | $tstathash["hold"] = recv.to_s.scan(/\"hold\"Sad.*?),/) | ||
+ | |||
+ | #parse t_heat | ||
+ | $tstathash["t_heat"] = recv.to_s.scan(/\"t_heat\"Sad.*?),/) | ||
+ | |||
+ | #parse t_cool | ||
+ | $tstathash["t_cool"] = recv.to_s.scan(/\"t_cool\"Sad.*?),/) | ||
+ | |||
+ | #parse time | ||
+ | $tstathash["day"] = recv.to_s.scan(/\"day\"Sad.*?),/) | ||
+ | $tstathash["hour"] = recv.to_s.scan(/\"hour\"Sad.*?),/) | ||
+ | $tstathash["minute"] = recv.to_s.scan(/\"minute\"Sad.*?)\}/) | ||
+ | |||
+ | case $tstathash["tmode"].to_s | ||
+ | when "1" | ||
+ | $tstathash["setpoint"] = recv.to_s.scan(/\"t_heat\"Sad.*?),/) | ||
+ | when "2" | ||
+ | $tstathash["setpoint"] = recv.to_s.scan(/\"t_cool\"Sad.*?),/) | ||
+ | when "3" | ||
+ | $tstathash["setpoint"] = 32.0 #no setpoint for auto ?? | ||
+ | else | ||
+ | log("Error getting setpoint! mode:" + $tstathash["tmode"].to_s + " 0 is OFF") | ||
+ | end | ||
+ | end | ||
+ | end | ||
+ | |||
+ | def tstat_set(data, update=true) | ||
+ | # Reconnect to the device | ||
+ | |||
+ | conn_.Reconnect() | ||
+ | |||
+ | s = "POST /tstat HTTP/1.1\r\n" | ||
+ | s += "Content-type: application/x-www-form-urlencoded\r\n" | ||
+ | s += "Content-Length: " + (data.length).to_s() + "\r\n" | ||
+ | s += "\r\n" | ||
+ | s += data | ||
+ | s += "\r\n" | ||
+ | |||
+ | conn_.Send(s) | ||
+ | log("Update: " + data) | ||
+ | # Wait for a reply | ||
+ | recv = "" | ||
+ | while(true) | ||
+ | buff=conn_.Recv(256, 5000) | ||
+ | if(buff.length() == 0) | ||
+ | break | ||
+ | end | ||
+ | recv = recv + buff | ||
+ | end | ||
+ | log(recv.to_s) | ||
+ | # Update the state to reflect the new situation | ||
+ | if (update) | ||
+ | update_state() | ||
+ | |||
+ | |||
+ | end | ||
+ | |||
+ | end | ||
+ | |||
+ | def update_state() | ||
+ | # This function queries the thermostat to get the most recent state | ||
+ | |||
+ | log("Polling thermostat for updates at: " + Time.now.to_s) | ||
+ | get() | ||
+ | |||
+ | # Get the new states | ||
+ | new_tmode = $tstathash["tmode"] # 0-Off, 1-Heat, 2-Cool, 3-Auto | ||
+ | #if ($tstathash["fmode"] == 2) | ||
+ | # Always on | ||
+ | #new_fmode = 2 # On | ||
+ | #else | ||
+ | # Auto/Schedule | ||
+ | #new_fmode = 1 # Auto | ||
+ | #end | ||
+ | new_fmode = $tstathash["fmode"] | ||
+ | new_setpoint = farhenheit_to_celcius(Float($tstathash["setpoint"].to_s)) | ||
+ | |||
+ | new_temp = farhenheit_to_celcius(Float($tstathash["temp"].to_s)) | ||
+ | #new_time = Time.at(results[4].to_i - Time.now.utc_offset) # Time.at creates a UTC time, wheras the thermostat reports the time in the local time zone | ||
+ | |||
+ | # Update the state and send events when necessary | ||
+ | if (new_tmode != @tmode) | ||
+ | log(" New mode detected : " + new_tmode.to_s) | ||
+ | if (@tmode == 0) | ||
+ | # The old mode was "Off", so now the thermostat is on | ||
+ | cmd = Command.new(device_.devid_, -1001, 1, 2, 28) # On | ||
+ | SendCommand(cmd) | ||
+ | end | ||
+ | if (new_tmode == 0) | ||
+ | # The new mode is "Off", so we send the Off event: | ||
+ | cmd = Command.new(device_.devid_, -1001, 1, 2, 29) # Off | ||
+ | SendCommand(cmd) | ||
+ | else | ||
+ | # We send the Thermostat mode changed event: | ||
+ | cmd = Command.new(device_.devid_, -1001, 1, 2, 78) | ||
+ | cmd.params_[30] = new_tmode.to_s #(new_tmode - 1).to_s | ||
+ | SendCommand(cmd) | ||
+ | end | ||
+ | @tmode = new_tmode | ||
+ | end | ||
+ | |||
+ | if (new_fmode != @fmode) | ||
+ | @fmode = new_fmode | ||
+ | log(" New fan mode detected : " + new_fmode.to_s) | ||
+ | cmd = Command.new(device_.devid_, -1001, 1, 2, 79) # Fan Mode Changed | ||
+ | cmd.params_[30] = new_fmode.to_s # Fan mode value | ||
+ | SendCommand(cmd) | ||
+ | end | ||
+ | |||
+ | if (new_setpoint != @setpoint) | ||
+ | @setpoint = new_setpoint | ||
+ | log(" New temperature setpoint detected : " + new_setpoint.to_s) | ||
+ | cmd = Command.new(device_.devid_, -1001, 1, 2, 27) # Thermostat Set Point Chan | ||
+ | cmd.params_[30] = new_setpoint.to_s # The new set point | ||
+ | SendCommand(cmd) | ||
+ | end | ||
+ | |||
+ | if (new_temp != @temp) | ||
+ | @temp = new_temp | ||
+ | log(" New temperature measurement detected : " + new_temp.to_s) | ||
+ | cmd = Command.new(device_.devid_, -1001, 1, 2, 25) # Temperature changed event | ||
+ | cmd.params_[30] = new_temp.to_s # The ambient temperature | ||
+ | SendCommand(cmd) | ||
+ | end | ||
+ | |||
+ | # Check the latest system time | ||
+ | #@time = new_time | ||
+ | #if ((@time-Time.now).abs > 600) | ||
+ | # Time is out of sync for more than 10 minutes | ||
+ | #log("Thermostat's time ("+@time.to_s+") is out of sync with system time ("+Time.now.to_s+"), resynchronizing") | ||
+ | #data="OID2.5.1=" # Current system time in seconds since Jan 1, 1970 | ||
+ | #data+=(Time.now + Time.now.utc_offset).to_i.to_s # Time.to_i returns seconds since epoch in UTC, wheras the thermostat expects the time in seconds since epoch in the local time zone | ||
+ | #pdp_set(data, false) | ||
+ | #end | ||
+ | |||
+ | # Record the last time the state was checked | ||
+ | @last_check = Time.now | ||
+ | end | ||
+ | |||
+ | def farhenheit_to_celcius(cf) | ||
+ | # Converts a temperatue in deci-Farhenheit into deci-degrees Celcius | ||
+ | power = 10.00 | ||
+ | return ((((cf - 32.0)*5.0)/9.0) * power).round / power | ||
+ | end | ||
+ | |||
+ | def celcius_to_farhenheit(c) | ||
+ | # Converts a temperatue in degrees Celcius into deci-Farhenheit | ||
+ | power = 10.00 | ||
+ | return ((((c*9.0)/5.0)+32.0) * power).round / power | ||
+ | end | ||
+ | |||
+ | [[User:Techstyle|Techstyle]] # 351 process idle: | ||
+ | |||
+ | # Check how long it has been since we queried the thermostat | ||
+ | now = Time.now | ||
+ | if ((@last_check + 300) < now) | ||
+ | # The last check was more than 5 minutes ago | ||
+ | update_state() | ||
+ | end | ||
+ | |||
+ | [[User:Techstyle|Techstyle]] # 350 process incoming data: | ||
+ | |||
+ | conn_.Close() | ||
+ | |||
+ | ~~ # 355 process init: | ||
+ | |||
+ | # Create Log File | ||
+ | $logFile = File.new("/var/log/pluto/RadioThermostatWiFi.log", "w") | ||
+ | log("Starting RadioThermostatWiFi" + "\n") | ||
+ | |||
+ | @tmode = 0 | ||
+ | @fmode = 0 | ||
+ | @temp = 0.0 | ||
+ | @setpoint = 0.0 | ||
+ | |||
+ | # Define Hashes to store our data | ||
+ | $tstathash = Hash.new | ||
+ | $tstathash["hour"] = 0 | ||
+ | $tstathash["minute"] = 0 | ||
+ | $tstathash["day"] = 0 | ||
+ | $tstathash["temp"] = 0.00 | ||
+ | $tstathash["setpoint"] = 0.00 | ||
+ | $tstathash["tmode"] = 0 | ||
+ | $tstathash["fmode"] = 0 | ||
+ | $tstathash["override"] = 0 | ||
+ | $tstathash["hold"] = 0 | ||
+ | $tstathash["t_heat"] = 0.00 | ||
+ | $tstathash["t_cool"] = 0.00 | ||
+ | $tstathash["tstate"] = 0 | ||
+ | $tstathash["fstate"] = 0 | ||
+ | $tstathash["t_type_post"] = 0 | ||
+ | |||
+ | |||
+ | # Update the state | ||
+ | get() | ||
+ | @tmode = $tstathash["tmode"] | ||
+ | @fmode = $tstathash["fmode"] | ||
+ | @temp = $tstathash["temp"] | ||
+ | @setpoint = $tstathash["setpoint"] | ||
+ | @last_check = Time.now | ||
+ | update_state() | ||
+ | |||
+ | [[User:Techstyle|Techstyle]] 356 process release: | ||
+ | |||
+ | # Close the Log File | ||
+ | if ($logFile != nil) then | ||
+ | $logFile.close | ||
+ | end |
Revision as of 04:16, 3 May 2013
Radio Thermostat makes several thermostats that can communicate via various wireless protocols using USNAP modules. This is an attempt to bring some of the information for these thermostats into one place.
Current Models are:
CT-22 (Beginning to be depreciated) CT-30 (Also known as Filtrete 3M-50 sold in Home Depot in the U.S. with a slightly different case) CT-80
The USNAP communication modules include Wi-Fi, Zigbee and Z-Wave. Store Front
There is a Windows program to control it via Wi-Fi
These thermostats will connect on their own via a Wi-Fi Access Point back to their hosted control service and allow you to control your thermostat from any browser.
The documentation for the Wi-Fi communication API was released.
I also found this unofficial Cloud API documentation.
Driver is complete and waiting for sqlCVS approval. -Aviator
The template is in process but is #2235. The code below is under development:
Techstyle #193 off:
data = "{\"tmode\":" # Current mode of HVAC operation data+="0}" # Off log("tmode set data: " + data) tstat_set(data)
Techstyle #192 on:
data+="3}" # Auto log("tmode set data: " + data) tstat_set(data)
Techstyle #279 set fan: data = "{\"fmode\":" if onoff == "1"
data+="2}" # Fan is always on
else
data+="0}" # Auto
end
log("fmode set data: " + data) tstat_set(data)
Techstyle #280 set heat/cool:
data = "{\"tmode\":" if onoff == "H"
data+="1" # Heat only
elsif onoff == "C"
data+="2" # Cool only
else
data+="3" # Auto
end
data+="}"
log("tmode set data: " + data)
tstat_set(data)
Techstyle # 278 set temperature:
if ((value_to_assign[0,1]=="+") || (value_to_assign[0,1]=="-"))
# The new setpoint is relative to the current setpoint new_temp = celcius_to_farhenheit(Float(@setpoint)).round + value_to_assign.to_i
else
# The new setpoint is absolute new_temp = celcius_to_farhenheit(Float(value_to_assign.to_i)).round
end
- to set the temp, we must know the mode
case $tstathash["tmode"].to_s
when "1" data = "{\"t_heat\":" + new_temp.to_s + "}" when "2" data = "{\"t_cool\":" + new_temp.to_s + "}"
end log("Set temp data: " + data) tstat_set(data)
Techstyle #373 Private method listing:
- Helper function for logging
def log(word)
$logFile.print(word + "\n") $logFile.flush()
end
def get()
# Reconnect to the device conn_.Reconnect() # Send the request s = "GET /tstat HTTP/1.1\r\n" s += "\r\n" conn_.Send(s)
# Wait for a reply recv = "" while(true) buff=conn_.Recv(256, 5000) if(buff.length() == 0) break end recv = recv + buff end
# Check that we got a response and try to parse through it if (recv=~ /^HTTP[^\r\n]+200\sOK.+?\r\n\r\n(.+)$/m) #parse temp $tstathash["temp"] = recv.to_s.scan(/\{\"temp\"Sad.*?),/) #parse tmode $tstathash["tmode"] = recv.to_s.scan(/\"tmode\"Sad.*?),/)
#parse fmode $tstathash["fmode"] = recv.to_s.scan(/\"fmode\"Sad.*?),/) #parse override $tstathash["override"] = recv.to_s.scan(/\"override\"Sad.*?),/) #parse hold $tstathash["hold"] = recv.to_s.scan(/\"hold\"Sad.*?),/) #parse t_heat $tstathash["t_heat"] = recv.to_s.scan(/\"t_heat\"Sad.*?),/)
#parse t_cool $tstathash["t_cool"] = recv.to_s.scan(/\"t_cool\"Sad.*?),/)
#parse time $tstathash["day"] = recv.to_s.scan(/\"day\"Sad.*?),/) $tstathash["hour"] = recv.to_s.scan(/\"hour\"Sad.*?),/) $tstathash["minute"] = recv.to_s.scan(/\"minute\"Sad.*?)\}/)
case $tstathash["tmode"].to_s when "1" $tstathash["setpoint"] = recv.to_s.scan(/\"t_heat\"Sad.*?),/) when "2" $tstathash["setpoint"] = recv.to_s.scan(/\"t_cool\"Sad.*?),/) when "3" $tstathash["setpoint"] = 32.0 #no setpoint for auto ?? else log("Error getting setpoint! mode:" + $tstathash["tmode"].to_s + " 0 is OFF") end end
end
def tstat_set(data, update=true)
# Reconnect to the device conn_.Reconnect()
s = "POST /tstat HTTP/1.1\r\n" s += "Content-type: application/x-www-form-urlencoded\r\n" s += "Content-Length: " + (data.length).to_s() + "\r\n" s += "\r\n" s += data s += "\r\n"
conn_.Send(s)
log("Update: " + data)
- Wait for a reply
recv = "" while(true) buff=conn_.Recv(256, 5000) if(buff.length() == 0) break end recv = recv + buff end
log(recv.to_s)
# Update the state to reflect the new situation if (update) update_state() end
end
def update_state()
# This function queries the thermostat to get the most recent state log("Polling thermostat for updates at: " + Time.now.to_s) get()
# Get the new states new_tmode = $tstathash["tmode"] # 0-Off, 1-Heat, 2-Cool, 3-Auto #if ($tstathash["fmode"] == 2) # Always on #new_fmode = 2 # On #else # Auto/Schedule #new_fmode = 1 # Auto #end new_fmode = $tstathash["fmode"] new_setpoint = farhenheit_to_celcius(Float($tstathash["setpoint"].to_s)) new_temp = farhenheit_to_celcius(Float($tstathash["temp"].to_s)) #new_time = Time.at(results[4].to_i - Time.now.utc_offset) # Time.at creates a UTC time, wheras the thermostat reports the time in the local time zone
# Update the state and send events when necessary if (new_tmode != @tmode) log(" New mode detected : " + new_tmode.to_s) if (@tmode == 0) # The old mode was "Off", so now the thermostat is on cmd = Command.new(device_.devid_, -1001, 1, 2, 28) # On SendCommand(cmd) end if (new_tmode == 0) # The new mode is "Off", so we send the Off event: cmd = Command.new(device_.devid_, -1001, 1, 2, 29) # Off SendCommand(cmd) else # We send the Thermostat mode changed event: cmd = Command.new(device_.devid_, -1001, 1, 2, 78) cmd.params_[30] = new_tmode.to_s #(new_tmode - 1).to_s SendCommand(cmd) end @tmode = new_tmode end
if (new_fmode != @fmode) @fmode = new_fmode log(" New fan mode detected : " + new_fmode.to_s) cmd = Command.new(device_.devid_, -1001, 1, 2, 79) # Fan Mode Changed cmd.params_[30] = new_fmode.to_s # Fan mode value SendCommand(cmd) end
if (new_setpoint != @setpoint) @setpoint = new_setpoint log(" New temperature setpoint detected : " + new_setpoint.to_s) cmd = Command.new(device_.devid_, -1001, 1, 2, 27) # Thermostat Set Point Chan cmd.params_[30] = new_setpoint.to_s # The new set point SendCommand(cmd) end
if (new_temp != @temp) @temp = new_temp log(" New temperature measurement detected : " + new_temp.to_s) cmd = Command.new(device_.devid_, -1001, 1, 2, 25) # Temperature changed event cmd.params_[30] = new_temp.to_s # The ambient temperature SendCommand(cmd) end
# Check the latest system time #@time = new_time #if ((@time-Time.now).abs > 600) # Time is out of sync for more than 10 minutes #log("Thermostat's time ("+@time.to_s+") is out of sync with system time ("+Time.now.to_s+"), resynchronizing") #data="OID2.5.1=" # Current system time in seconds since Jan 1, 1970 #data+=(Time.now + Time.now.utc_offset).to_i.to_s # Time.to_i returns seconds since epoch in UTC, wheras the thermostat expects the time in seconds since epoch in the local time zone #pdp_set(data, false) #end
# Record the last time the state was checked @last_check = Time.now
end
def farhenheit_to_celcius(cf)
# Converts a temperatue in deci-Farhenheit into deci-degrees Celcius power = 10.00 return ((((cf - 32.0)*5.0)/9.0) * power).round / power
end
def celcius_to_farhenheit(c)
# Converts a temperatue in degrees Celcius into deci-Farhenheit power = 10.00 return ((((c*9.0)/5.0)+32.0) * power).round / power
end
Techstyle # 351 process idle:
- Check how long it has been since we queried the thermostat
now = Time.now if ((@last_check + 300) < now)
# The last check was more than 5 minutes ago update_state()
end
Techstyle # 350 process incoming data:
conn_.Close()
~~ # 355 process init:
- Create Log File
$logFile = File.new("/var/log/pluto/RadioThermostatWiFi.log", "w") log("Starting RadioThermostatWiFi" + "\n")
@tmode = 0 @fmode = 0 @temp = 0.0 @setpoint = 0.0
- Define Hashes to store our data
$tstathash = Hash.new $tstathash["hour"] = 0 $tstathash["minute"] = 0 $tstathash["day"] = 0 $tstathash["temp"] = 0.00 $tstathash["setpoint"] = 0.00 $tstathash["tmode"] = 0 $tstathash["fmode"] = 0 $tstathash["override"] = 0 $tstathash["hold"] = 0 $tstathash["t_heat"] = 0.00 $tstathash["t_cool"] = 0.00 $tstathash["tstate"] = 0 $tstathash["fstate"] = 0 $tstathash["t_type_post"] = 0
- Update the state
get() @tmode = $tstathash["tmode"] @fmode = $tstathash["fmode"] @temp = $tstathash["temp"] @setpoint = $tstathash["setpoint"] @last_check = Time.now update_state()
Techstyle 356 process release:
- Close the Log File
if ($logFile != nil) then
$logFile.close
end