Difference between revisions of "Radio Thermostat"
m (Added category: GSD) |
|||
(6 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
[[Category: Hardware]] | [[Category: Hardware]] | ||
[[Category: Thermostats]] | [[Category: Thermostats]] | ||
− | [[Category: | + | [[Category: ZWave]] |
− | [[Category: Wi-Fi | + | [[Category: Wi-Fi]] |
− | [[Category: Zigbee | + | [[Category: Zigbee]] |
+ | [[Category: GSD]] | ||
Line 29: | Line 30: | ||
The template is in process but is #2235. The code below is under development: | The template is in process but is #2235. The code below is under development: | ||
− | + | <code>#193 off:<br /> | |
− | + | <br /> | |
− | data = "{\"tmode\":" # Current mode of HVAC operation | + | data = "{\"tmode\":" # Current mode of HVAC operation<br /> |
− | data+="0}" # Off | + | data+="0}" # Off<br /> |
− | log("tmode set data: " + data) | + | log("tmode set data: " + data)<br /> |
− | tstat_set(data) | + | tstat_set(data)<br /> |
− | + | <br /> | |
− | + | #192 on:<br /> | |
− | + | <br /> | |
− | data+="3}" # Auto | + | data+="3}" # Auto<br /> |
− | log("tmode set data: " + data) | + | log("tmode set data: " + data)<br /> |
− | tstat_set(data) | + | tstat_set(data)<br /> |
− | + | <br /> | |
− | + | #279 set fan:<br /> | |
− | data = "{\"fmode\":" | + | <br /> |
− | if onoff == "1" | + | data = "{\"fmode\":"<br /> |
− | data+="2}" # Fan is always on | + | if onoff == "1"<br /> |
− | else | + | data+="2}" # Fan is always on<br /> |
− | data+="0}" # Auto | + | else<br /> |
− | end | + | data+="0}" # Auto<br /> |
− | + | end<br /> | |
− | log("fmode set data: " + data) | + | <br /> |
− | tstat_set(data) | + | log("fmode set data: " + data)<br /> |
− | + | tstat_set(data)<br /> | |
− | + | <br /> | |
− | + | #280 set heat/cool:<br /> | |
− | data = "{\"tmode\":" | + | <br /> |
− | if onoff == "H" | + | data = "{\"tmode\":"<br /> |
− | data+="1" # Heat only | + | if onoff == "H"<br /> |
− | elsif onoff == "C" | + | data+="1" # Heat only<br /> |
− | data+="2" # Cool only | + | elsif onoff == "C"<br /> |
− | else | + | data+="2" # Cool only<br /> |
− | data+="3" # Auto | + | else<br /> |
− | end | + | data+="3" # Auto<br /> |
− | + | end<br /> | |
− | data+="}" | + | <br /> |
− | + | data+="}"<br /> | |
− | log("tmode set data: " + data) | + | <br /> |
− | + | log("tmode set data: " + data)<br /> | |
− | tstat_set(data) | + | <br /> |
− | + | tstat_set(data)<br /> | |
− | + | <br /> | |
− | + | # 278 set temperature:<br /> | |
− | if ((value_to_assign[0,1]=="+") || (value_to_assign[0,1]=="-")) | + | <br /> |
− | # The new setpoint is relative to the current setpoint | + | if ((value_to_assign[0,1]=="+") || (value_to_assign[0,1]=="-"))<br /> |
− | new_temp = celcius_to_farhenheit(Float(@setpoint)).round + value_to_assign.to_i | + | # The new setpoint is relative to the current setpoint<br /> |
− | else | + | new_temp = celcius_to_farhenheit(Float(@setpoint)).round + value_to_assign.to_i<br /> |
− | # The new setpoint is absolute | + | else<br /> |
− | new_temp = celcius_to_farhenheit(Float(value_to_assign.to_i)).round | + | # The new setpoint is absolute<br /> |
− | end | + | new_temp = celcius_to_farhenheit(Float(value_to_assign.to_i)).round<br /> |
− | + | end<br /> | |
− | # to set the temp, we must know the mode | + | <br /> |
− | case $tstathash["tmode"].to_s | + | # to set the temp, we must know the mode<br /> |
− | when "1" | + | case $tstathash["tmode"].to_s<br /> |
− | data = "{\"t_heat\":" + new_temp.to_s + "}" | + | when "1"<br /> |
− | when "2" | + | data = "{\"t_heat\":" + new_temp.to_s + "}"<br /> |
− | data = "{\"t_cool\":" + new_temp.to_s + "}" | + | when "2"<br /> |
− | end | + | data = "{\"t_cool\":" + new_temp.to_s + "}"<br /> |
− | log("Set temp data: " + data) | + | end<br /> |
− | tstat_set(data) | + | log("Set temp data: " + data)<br /> |
− | + | tstat_set(data)<br /> | |
− | + | <br /> | |
− | + | #373 Private method listing:<br /> | |
− | # Helper function for logging | + | <br /> |
− | def log(word) | + | # Helper function for logging<br /> |
− | $logFile.print(word + "\n") | + | def log(word)<br /> |
− | $logFile.flush() | + | $logFile.print(word + "\n")<br /> |
− | end | + | $logFile.flush()<br /> |
− | + | end<br /> | |
− | def get() | + | <br /> |
− | + | def get()<br /> | |
− | # Reconnect to the device | + | <br /> |
− | conn_.Reconnect() | + | # Reconnect to the device<br /> |
− | + | conn_.Reconnect()<br /> | |
− | # Send the request | + | <br /> |
− | s = "GET /tstat HTTP/1.1\r\n" | + | # Send the request<br /> |
− | s += "\r\n" | + | s = "GET /tstat HTTP/1.1\r\n"<br /> |
− | conn_.Send(s) | + | s += "\r\n"<br /> |
− | + | conn_.Send(s)<br /> | |
− | # Wait for a reply | + | <br /> |
− | recv = "" | + | # Wait for a reply<br /> |
− | while(true) | + | recv = ""<br /> |
− | buff=conn_.Recv(256, 5000) | + | while(true)<br /> |
− | if(buff.length() == 0) | + | buff=conn_.Recv(256, 5000)<br /> |
− | break | + | if(buff.length() == 0)<br /> |
− | end | + | break<br /> |
− | recv = recv + buff | + | end<br /> |
− | end | + | recv = recv + buff<br /> |
− | + | end<br /> | |
− | # Check that we got a response and try to parse through it | + | <br /> |
− | if (recv=~ /^HTTP[^\r\n]+200\sOK.+?\r\n\r\n(.+)$/m) | + | # Check that we got a response and try to parse through it<br /> |
− | #parse temp | + | if (recv=~ /^HTTP[^\r\n]+200\sOK.+?\r\n\r\n(.+)$/m)<br /> |
− | $tstathash["temp"] = recv.to_s.scan(/\{\"temp\"Sad.*?),/) | + | #parse temp<br /> |
− | + | $tstathash["temp"] = recv.to_s.scan(/\{\"temp\"Sad.*?),/)<br /> | |
− | #parse tmode | + | <br /> |
− | $tstathash["tmode"] = recv.to_s.scan(/\"tmode\"Sad.*?),/) | + | #parse tmode<br /> |
− | + | $tstathash["tmode"] = recv.to_s.scan(/\"tmode\"Sad.*?),/) <br /> | |
− | #parse fmode | + | <br /> |
− | $tstathash["fmode"] = recv.to_s.scan(/\"fmode\"Sad.*?),/) | + | #parse fmode<br /> |
− | + | $tstathash["fmode"] = recv.to_s.scan(/\"fmode\"Sad.*?),/)<br /> | |
− | #parse override | + | <br /> |
− | $tstathash["override"] = recv.to_s.scan(/\"override\"Sad.*?),/) | + | #parse override<br /> |
− | + | $tstathash["override"] = recv.to_s.scan(/\"override\"Sad.*?),/)<br /> | |
− | #parse hold | + | <br /> |
− | $tstathash["hold"] = recv.to_s.scan(/\"hold\"Sad.*?),/) | + | #parse hold<br /> |
− | + | $tstathash["hold"] = recv.to_s.scan(/\"hold\"Sad.*?),/)<br /> | |
− | #parse t_heat | + | <br /> |
− | $tstathash["t_heat"] = recv.to_s.scan(/\"t_heat\"Sad.*?),/) | + | #parse t_heat<br /> |
− | + | $tstathash["t_heat"] = recv.to_s.scan(/\"t_heat\"Sad.*?),/)<br /> | |
− | #parse t_cool | + | <br /> |
− | $tstathash["t_cool"] = recv.to_s.scan(/\"t_cool\"Sad.*?),/) | + | #parse t_cool<br /> |
− | + | $tstathash["t_cool"] = recv.to_s.scan(/\"t_cool\"Sad.*?),/)<br /> | |
− | #parse time | + | <br /> |
− | $tstathash["day"] = recv.to_s.scan(/\"day\"Sad.*?),/) | + | #parse time<br /> |
− | $tstathash["hour"] = recv.to_s.scan(/\"hour\"Sad.*?),/) | + | $tstathash["day"] = recv.to_s.scan(/\"day\"Sad.*?),/) <br /> |
− | $tstathash["minute"] = recv.to_s.scan(/\"minute\"Sad.*?)\}/) | + | $tstathash["hour"] = recv.to_s.scan(/\"hour\"Sad.*?),/) <br /> |
− | + | $tstathash["minute"] = recv.to_s.scan(/\"minute\"Sad.*?)\}/)<br /> | |
− | case $tstathash["tmode"].to_s | + | <br /> |
− | when "1" | + | case $tstathash["tmode"].to_s<br /> |
− | $tstathash["setpoint"] = recv.to_s.scan(/\"t_heat\"Sad.*?),/) | + | when "1"<br /> |
− | when "2" | + | $tstathash["setpoint"] = recv.to_s.scan(/\"t_heat\"Sad.*?),/)<br /> |
− | $tstathash["setpoint"] = recv.to_s.scan(/\"t_cool\"Sad.*?),/) | + | when "2"<br /> |
− | when "3" | + | $tstathash["setpoint"] = recv.to_s.scan(/\"t_cool\"Sad.*?),/)<br /> |
− | $tstathash["setpoint"] = 32.0 #no setpoint for auto ?? | + | when "3"<br /> |
− | else | + | $tstathash["setpoint"] = 32.0 #no setpoint for auto ??<br /> |
− | log("Error getting setpoint! mode:" + $tstathash["tmode"].to_s + " 0 is OFF") | + | else<br /> |
− | end | + | log("Error getting setpoint! mode:" + $tstathash["tmode"].to_s + " 0 is OFF")<br /> |
− | end | + | end<br /> |
− | end | + | end<br /> |
− | + | end<br /> | |
− | def tstat_set(data, update=true) | + | <br /> |
− | # Reconnect to the device | + | def tstat_set(data, update=true)<br /> |
− | + | # Reconnect to the device<br /> | |
− | conn_.Reconnect() | + | <br /> |
− | + | conn_.Reconnect()<br /> | |
− | s = "POST /tstat HTTP/1.1\r\n" | + | <br /> |
− | s += "Content-type: application/x-www-form-urlencoded\r\n" | + | s = "POST /tstat HTTP/1.1\r\n"<br /> |
− | s += "Content-Length: " + (data.length).to_s() + "\r\n" | + | s += "Content-type: application/x-www-form-urlencoded\r\n"<br /> |
− | s += "\r\n" | + | s += "Content-Length: " + (data.length).to_s() + "\r\n"<br /> |
− | s += data | + | s += "\r\n"<br /> |
− | s += "\r\n" | + | s += data<br /> |
− | + | s += "\r\n"<br /> | |
− | conn_.Send(s) | + | <br /> |
− | log("Update: " + data) | + | conn_.Send(s)<br /> |
− | # Wait for a reply | + | log("Update: " + data)<br /> |
− | recv = "" | + | # Wait for a reply<br /> |
− | while(true) | + | recv = ""<br /> |
− | buff=conn_.Recv(256, 5000) | + | while(true)<br /> |
− | if(buff.length() == 0) | + | buff=conn_.Recv(256, 5000)<br /> |
− | break | + | if(buff.length() == 0)<br /> |
− | end | + | break<br /> |
− | recv = recv + buff | + | end<br /> |
− | end | + | recv = recv + buff<br /> |
− | log(recv.to_s) | + | end<br /> |
− | # Update the state to reflect the new situation | + | log(recv.to_s)<br /> |
− | if (update) | + | # Update the state to reflect the new situation<br /> |
− | update_state() | + | if (update)<br /> |
− | + | update_state()<br /> | |
− | + | <br /> | |
− | end | + | <br /> |
− | + | end<br /> | |
− | end | + | <br /> |
− | + | end<br /> | |
− | def update_state() | + | <br /> |
− | # This function queries the thermostat to get the most recent state | + | def update_state()<br /> |
− | + | # This function queries the thermostat to get the most recent state<br /> | |
− | log("Polling thermostat for updates at: " + Time.now.to_s) | + | <br /> |
− | get() | + | log("Polling thermostat for updates at: " + Time.now.to_s)<br /> |
− | + | get()<br /> | |
− | # Get the new states | + | <br /> |
− | new_tmode = $tstathash["tmode"] # 0-Off, 1-Heat, 2-Cool, 3-Auto | + | # Get the new states<br /> |
− | #if ($tstathash["fmode"] == 2) | + | new_tmode = $tstathash["tmode"] # 0-Off, 1-Heat, 2-Cool, 3-Auto<br /> |
− | # Always on | + | #if ($tstathash["fmode"] == 2)<br /> |
− | #new_fmode = 2 # On | + | # Always on<br /> |
− | #else | + | #new_fmode = 2 # On<br /> |
− | # Auto/Schedule | + | #else<br /> |
− | #new_fmode = 1 # Auto | + | # Auto/Schedule<br /> |
− | #end | + | #new_fmode = 1 # Auto<br /> |
− | new_fmode = $tstathash["fmode"] | + | #end<br /> |
− | new_setpoint = farhenheit_to_celcius(Float($tstathash["setpoint"].to_s)) | + | new_fmode = $tstathash["fmode"]<br /> |
− | + | new_setpoint = farhenheit_to_celcius(Float($tstathash["setpoint"].to_s))<br /> | |
− | new_temp = farhenheit_to_celcius(Float($tstathash["temp"].to_s)) | + | <br /> |
− | #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 | + | new_temp = farhenheit_to_celcius(Float($tstathash["temp"].to_s))<br /> |
− | + | #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<br /> | |
− | # Update the state and send events when necessary | + | <br /> |
− | if (new_tmode != @tmode) | + | # Update the state and send events when necessary<br /> |
− | log(" New mode detected : " + new_tmode.to_s) | + | if (new_tmode != @tmode)<br /> |
− | if (@tmode == 0) | + | log(" New mode detected : " + new_tmode.to_s)<br /> |
− | # The old mode was "Off", so now the thermostat is on | + | if (@tmode == 0)<br /> |
− | cmd = Command.new(device_.devid_, -1001, 1, 2, 28) # On | + | # The old mode was "Off", so now the thermostat is on<br /> |
− | SendCommand(cmd) | + | cmd = Command.new(device_.devid_, -1001, 1, 2, 28) # On<br /> |
− | end | + | SendCommand(cmd)<br /> |
− | if (new_tmode == 0) | + | end<br /> |
− | # The new mode is "Off", so we send the Off event: | + | if (new_tmode == 0)<br /> |
− | cmd = Command.new(device_.devid_, -1001, 1, 2, 29) # Off | + | # The new mode is "Off", so we send the Off event:<br /> |
− | SendCommand(cmd) | + | cmd = Command.new(device_.devid_, -1001, 1, 2, 29) # Off<br /> |
− | else | + | SendCommand(cmd)<br /> |
− | # We send the Thermostat mode changed event: | + | else<br /> |
− | cmd = Command.new(device_.devid_, -1001, 1, 2, 78) | + | # We send the Thermostat mode changed event:<br /> |
− | cmd.params_[30] = new_tmode.to_s #(new_tmode - 1).to_s | + | cmd = Command.new(device_.devid_, -1001, 1, 2, 78)<br /> |
− | SendCommand(cmd) | + | cmd.params_[30] = new_tmode.to_s #(new_tmode - 1).to_s<br /> |
− | end | + | SendCommand(cmd)<br /> |
− | @tmode = new_tmode | + | end<br /> |
− | end | + | @tmode = new_tmode<br /> |
− | + | end<br /> | |
− | if (new_fmode != @fmode) | + | <br /> |
− | @fmode = new_fmode | + | if (new_fmode != @fmode)<br /> |
− | log(" New fan mode detected : " + new_fmode.to_s) | + | @fmode = new_fmode<br /> |
− | cmd = Command.new(device_.devid_, -1001, 1, 2, 79) # Fan Mode Changed | + | log(" New fan mode detected : " + new_fmode.to_s)<br /> |
− | cmd.params_[30] = new_fmode.to_s # Fan mode value | + | cmd = Command.new(device_.devid_, -1001, 1, 2, 79) # Fan Mode Changed<br /> |
− | SendCommand(cmd) | + | cmd.params_[30] = new_fmode.to_s # Fan mode value<br /> |
− | end | + | SendCommand(cmd)<br /> |
− | + | end<br /> | |
− | if (new_setpoint != @setpoint) | + | <br /> |
− | @setpoint = new_setpoint | + | if (new_setpoint != @setpoint)<br /> |
− | log(" New temperature setpoint detected : " + new_setpoint.to_s) | + | @setpoint = new_setpoint<br /> |
− | cmd = Command.new(device_.devid_, -1001, 1, 2, 27) # Thermostat Set Point Chan | + | log(" New temperature setpoint detected : " + new_setpoint.to_s)<br /> |
− | cmd.params_[30] = new_setpoint.to_s # The new set point | + | cmd = Command.new(device_.devid_, -1001, 1, 2, 27) # Thermostat Set Point Chan<br /> |
− | SendCommand(cmd) | + | cmd.params_[30] = new_setpoint.to_s # The new set point<br /> |
− | end | + | SendCommand(cmd)<br /> |
− | + | end<br /> | |
− | if (new_temp != @temp) | + | <br /> |
− | @temp = new_temp | + | if (new_temp != @temp)<br /> |
− | log(" New temperature measurement detected : " + new_temp.to_s) | + | @temp = new_temp<br /> |
− | cmd = Command.new(device_.devid_, -1001, 1, 2, 25) # Temperature changed event | + | log(" New temperature measurement detected : " + new_temp.to_s)<br /> |
− | cmd.params_[30] = new_temp.to_s # The ambient temperature | + | cmd = Command.new(device_.devid_, -1001, 1, 2, 25) # Temperature changed event<br /> |
− | SendCommand(cmd) | + | cmd.params_[30] = new_temp.to_s # The ambient temperature<br /> |
− | end | + | SendCommand(cmd)<br /> |
− | + | end<br /> | |
− | # Check the latest system time | + | <br /> |
− | #@time = new_time | + | # Check the latest system time<br /> |
− | #if ((@time-Time.now).abs > 600) | + | #@time = new_time<br /> |
− | # Time is out of sync for more than 10 minutes | + | #if ((@time-Time.now).abs > 600)<br /> |
− | #log("Thermostat's time ("+@time.to_s+") is out of sync with system time ("+Time.now.to_s+"), resynchronizing") | + | # Time is out of sync for more than 10 minutes<br /> |
− | #data="OID2.5.1=" # Current system time in seconds since Jan 1, 1970 | + | #log("Thermostat's time ("+@time.to_s+") is out of sync with system time ("+Time.now.to_s+"), resynchronizing")<br /> |
− | #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 | + | #data="OID2.5.1=" # Current system time in seconds since Jan 1, 1970<br /> |
− | #pdp_set(data, false) | + | #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<br /> |
− | #end | + | #pdp_set(data, false)<br /> |
− | + | #end<br /> | |
− | # Record the last time the state was checked | + | <br /> |
− | @last_check = Time.now | + | # Record the last time the state was checked<br /> |
− | end | + | @last_check = Time.now<br /> |
− | + | end<br /> | |
− | def farhenheit_to_celcius(cf) | + | <br /> |
− | # Converts a temperatue in deci-Farhenheit into deci-degrees Celcius | + | def farhenheit_to_celcius(cf)<br /> |
− | power = 10.00 | + | # Converts a temperatue in deci-Farhenheit into deci-degrees Celcius<br /> |
− | return ((((cf - 32.0)*5.0)/9.0) * power).round / power | + | power = 10.00<br /> |
− | end | + | return ((((cf - 32.0)*5.0)/9.0) * power).round / power<br /> |
− | + | end<br /> | |
− | def celcius_to_farhenheit(c) | + | <br /> |
− | # Converts a temperatue in degrees Celcius into deci-Farhenheit | + | def celcius_to_farhenheit(c)<br /> |
− | power = 10.00 | + | # Converts a temperatue in degrees Celcius into deci-Farhenheit<br /> |
− | return ((((c*9.0)/5.0)+32.0) * power).round / power | + | power = 10.00<br /> |
− | end | + | return ((((c*9.0)/5.0)+32.0) * power).round / power<br /> |
− | + | end<br /> | |
− | + | <br /> | |
− | + | # 351 process idle:<br /> | |
− | # Check how long it has been since we queried the thermostat | + | <br /> |
− | now = Time.now | + | # Check how long it has been since we queried the thermostat<br /> |
− | if ((@last_check + 300) < now) | + | now = Time.now<br /> |
− | # The last check was more than 5 minutes ago | + | if ((@last_check + 300) < now)<br /> |
− | update_state() | + | # The last check was more than 5 minutes ago<br /> |
− | end | + | update_state()<br /> |
− | + | end<br /> | |
− | + | <br /> | |
− | + | # 350 process incoming data:<br /> | |
− | conn_.Close() | + | <br /> |
− | + | conn_.Close()<br /> | |
− | + | <br /> | |
− | + | # 355 process init:<br /> | |
− | # Create Log File | + | <br /> |
− | $logFile = File.new("/var/log/pluto/RadioThermostatWiFi.log", "w") | + | # Create Log File<br /> |
− | log("Starting RadioThermostatWiFi" + "\n") | + | $logFile = File.new("/var/log/pluto/RadioThermostatWiFi.log", "w")<br /> |
− | + | log("Starting RadioThermostatWiFi" + "\n")<br /> | |
− | @tmode = 0 | + | <br /> |
− | @fmode = 0 | + | @tmode = 0<br /> |
− | @temp = 0.0 | + | @fmode = 0<br /> |
− | @setpoint = 0.0 | + | @temp = 0.0<br /> |
− | + | @setpoint = 0.0<br /> | |
− | # Define Hashes to store our data | + | <br /> |
− | $tstathash = Hash.new | + | # Define Hashes to store our data<br /> |
− | $tstathash["hour"] = 0 | + | $tstathash = Hash.new<br /> |
− | $tstathash["minute"] = 0 | + | $tstathash["hour"] = 0<br /> |
− | $tstathash["day"] = 0 | + | $tstathash["minute"] = 0<br /> |
− | $tstathash["temp"] = 0.00 | + | $tstathash["day"] = 0<br /> |
− | $tstathash["setpoint"] = 0.00 | + | $tstathash["temp"] = 0.00<br /> |
− | $tstathash["tmode"] = 0 | + | $tstathash["setpoint"] = 0.00<br /> |
− | $tstathash["fmode"] = 0 | + | $tstathash["tmode"] = 0<br /> |
− | $tstathash["override"] = 0 | + | $tstathash["fmode"] = 0<br /> |
− | $tstathash["hold"] = 0 | + | $tstathash["override"] = 0<br /> |
− | $tstathash["t_heat"] = 0.00 | + | $tstathash["hold"] = 0<br /> |
− | $tstathash["t_cool"] = 0.00 | + | $tstathash["t_heat"] = 0.00<br /> |
− | $tstathash["tstate"] = 0 | + | $tstathash["t_cool"] = 0.00<br /> |
− | $tstathash["fstate"] = 0 | + | $tstathash["tstate"] = 0<br /> |
− | $tstathash["t_type_post"] = 0 | + | $tstathash["fstate"] = 0<br /> |
− | + | $tstathash["t_type_post"] = 0<br /> | |
− | + | <br /> | |
− | # Update the state | + | <br /> |
− | get() | + | # Update the state<br /> |
− | @tmode = $tstathash["tmode"] | + | get()<br /> |
− | @fmode = $tstathash["fmode"] | + | @tmode = $tstathash["tmode"]<br /> |
− | @temp = $tstathash["temp"] | + | @fmode = $tstathash["fmode"]<br /> |
− | @setpoint = $tstathash["setpoint"] | + | @temp = $tstathash["temp"]<br /> |
− | @last_check = Time.now | + | @setpoint = $tstathash["setpoint"]<br /> |
− | update_state() | + | @last_check = Time.now<br /> |
− | + | update_state()<br /> | |
− | + | <br /> | |
− | + | #356 process release:<br /> | |
− | # Close the Log File | + | <br /> |
− | if ($logFile != nil) then | + | # Close the Log File<br /> |
− | $logFile.close | + | if ($logFile != nil) then<br /> |
− | end | + | $logFile.close<br /> |
+ | end<br /> | ||
+ | <code> |
Latest revision as of 14:58, 7 July 2016
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:
#193 off:
data = "{\"tmode\":" # Current mode of HVAC operation
data+="0}" # Off
log("tmode set data: " + data)
tstat_set(data)
- 192 on:
data+="3}" # Auto
log("tmode set data: " + data)
tstat_set(data)
- 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)
- 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)
- 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)
- 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
- 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
- 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()
- 356 process release:
# Close the Log File
if ($logFile != nil) then
$logFile.close
end
<code>