How to return current temp from my thermostat?

(Scot) #1

Hello!

I’ve been using a 3M50 Filtrete thermostat for a few years now and it works great. This past weekend I set up a Rasberry Pi and installed OpenHAB. I’ve modified the sitemap & items and have it getting my local temp/date/time.

And I’ve read thru the API for the thermostat and have tested several curl commands to make sure they work from the command prompt; and they do!

My problem is I have no idea how to implement the curl commands in to OpenHAB. For instance the following command returns the temp and current settings.

$ curl http://192.168.1.101/tstat
{“temp”:76.50,“tmode”:2,“fmode”:0,“override”:0,“hold”:0,“t_cool”:85.00,“time”:{"d
ay":6,“hour”:12,“minute”:54}}

Questions are:

  1. Where do I enter the command?
  2. How do I parse the temp out of what’s returned?
  3. How do I display the indoor temp?

I’ve been searching the web and the forums and just haven’t found anything that’s plain enough for me to understand how to accomplish this.

Any help greatly appreciated.

Thanks

Scot

0 Likes

HTTP + JSON - Sensor readings
Binding Radio Thermostat?
Having problem retrieving values from thermostat
Adjusting Temperature
Having problem retrieving values from thermostat
Need Help to Adjust Temperature thru HTTP Binding
(Rich Koshak) #2

There are two approaches.

  1. You can put your curl commands into a script and use the Exec binding to execute them and put the result into an Item. See the link above for how to do that. Your script should probably parse out the temp and only return that instead of the full JSON data to make it easier on yourself. Otherwise you will need to add a Transform to extract the data and since you already have the script I find it easier to do the parsing and transformation there.

  2. You can use the HTTP binding instead of the curl command to call the URL directly from within openHAB. You will need to pay particular attention to the Handling JSON section to parse the information you want out of the data you are getting back.

In either case you will need to make sure the appropriate binding is installed in your addons folder.

See above. There are also lots of examples on the wiki and in this forum.

Once you have the temp going into an Item (presumably a Number item), you need to add a line to the sitemap to display it. See the demo sitemap and the wiki for details.

1 Like

(Scot) #3

Thanks for the reply!

I’ll work thru that tonight and see how far I get.

0 Likes

(Scot) #4

Started looking at this when I got home and after a couple of hours I’m no farther than I was… The one link you provided I had seen and unfortunately the others just don’t make any sense to me either.

In the one example it talked about how to enter in the sitemap and that makes sense based on the other things in my sitemap and examples I’ve seen. And the entry for items sorta makes sense to me. But when I try to enter something there I get errors about missing/wrong rules. And any rule I’ve tried to create has numerous errors.

The overview you gave of commands in a script, make sure I have the proper addon installed and then an entry in items and the sitemap. That’s a great outline, but with my lack of knowledge about OpenHAB, Linux etc, I just can’t put two and two together.

FYI my background is in Windows desktop programming so this is all new to me. Apparently I need a fair bit more hand holding to get there…

Thanks

Scot

0 Likes

(John Cocula) #5

If you install the HTTP binding JAR, define this item in a .items file:

Number Temp "temp [%.1f °F]" { http="<[http://192.168.1.101/tstat:60000:JSONPATH($.temp)]" }

every minute, your Temp item will be updated with the current temperature.

0 Likes

(Scot) #6

THANK YOU!

That was most helpful, and now I see how I can extract the heat/ac, fan, etc modes.

As stated above I’m just getting started with OpenHAB; my plan is to eventually control HVAC, lights, monitor doors and windows and control the sprinkling system.

Thanks again!

0 Likes

(John Cocula) #7

A further expansion is to retrieve the JSON once every few minutes or so, and have your items retrieve their values from the cached copy:

openhab.cfg:

http:tstat.url=http://192.168.1.101/tstat
http:tstat.updateInterval=60000

your.items:

Number Temp "temp [%.1f °F]" { http="<[tstat:60000:JSONPATH($.temp)]" }
Number TCool "t_cool [%.1f °F]" { http="<[tstat:60000:JSONPATH($.t_cool)]" }
etc.
0 Likes

(david) #8

I have been working on the same setup with the CT-80 thermostat which is pretty much the same as yours, here are some of my configs.

items:

   Group   gSF_HVAC        ""      <temperature>   (gSF)
Number  SF_HVAC_Temp    "Temperature [%.1f °F]"        <temperature>   (gSF_HVAC)              { http="<[upstairs_thermostat:60000:JS(getHVACTemperature.js)]" }
Number  SF_HVAC_Humidity        "Humidity [%.2f %%]"    <temperature>   (gSF_HVAC)              { http="<[http://192.168.1.11:80/tstat/humidity:60000:JS(getHVACHumidity.js)]" }
Number  SF_HVAC_Cool_SP "Cool Setpoint [%.1f °F]"      <temperature>   (gSF_HVAC)              { http="<[upstairs_thermostat:60000:JS(getHVACCoolSetPoint.js)]" }
Number  SF_HVAC_Mode    ""      (gSF_HVAC)              { http="<[upstairs_thermostat:60000:JS(getHVACMode.js)]" }
Number  SF_HVAC_Fan     "The Fan is [MAP(hvacFanState.map):%s]" <temperature>   (gSF_HVAC)              { http="<[upstairs_thermostat:60000:JS(getHVACFanState.js)]" }
Number  SF_HVAC_FanMode "The Fan is [MAP(hvacFAnMode.map):]"    <temperature>   (gSF_HVAC)              { http="<[upstairs_thermostat:60000:JS(getHVACFanMode.js)]" }
Number  SF_HVAC_State   "The system is [MAP(hvac.map):%s]"      (gSF_HVAC)              { http="<[upstairs_thermostat:60000:JS(getHVACState.js)]" }
Number  SF_HVAC_Status  "The system is [MAP(hvac.map):%s]"      (gSF_HVAC)              { http="<[upstairs_thermostat:60000:JS(getHVACStatus.js)]" }

Sitemap:

 Frame item=SF_HVAC_Temp label="Thermostats" {
         Text item=SF_HVAC_Temp label="Upstairs [%.1f F]" {
                 Text item=SF_HVAC_State                 
                 Text item=SF_HVAC_Humidity                      
                 Setpoint item=SF_HVAC_Cool_SP label="Cool Set Point [%d F]" icon="temperature" step=1                   
                 Switch item=SF_HVAC_Mode mappings=[0="Off", 1="Heat", 2="Cool", 3="Auto"]  
                 Text label="More Settings" icon="settings" {
                         Text item=SF_HVAC_Fan                           
                         Switch item=SF_HVAC_FanMode label="Fan" icon="settings" mappings=[0="Auto", 1="Circulate", 2="On"] 
                 }                       
         }               
 }    

Transform Javascript :
I decided to put these outside the items so I could resue them. There are more, but you get the idea.

getHVACFanState.js

JSON.parse(input).fstate;

getHVACTemperature.js

JSON.parse(input).temp;

getHVACHumidity.js

JSON.parse(input).humidity;

getHVACState.js

JSON.parse(input).tstate;

Map File to translate heating and cooling and others
hvac.map

CLOSED=closed
OPEN=open
undefined=unknown
0=Off
1=Heating
2=Cooling

End Result

Next steps for me are to have OpenHab figure whether we are heating and cooling and show the correct set points.

2 Likes

(david) #9

I had better luck caching the status for the thermostat rather than continuously polling the thermostat. Without caching about half the requests timed out or got an error.

0 Likes

(Scot) #10

Great info guys; very much appreciated!

watou - if I understand correctly? The http binding runs every minute in this example and stores the data. And the item runs every minute and reads the cache. Yes?

david - your controls are a lot like what I was envisioning. Does the line ‘Cool Set Point’ change to ‘Heat Set Point’ when you change to heat?

Thanks for all of the examples, a lot to take in!

Scot

0 Likes

(david) #11

Yes Correct.

Does the line ‘Cool Set Point’ change to ‘Heat Set Point’ when you change to heat?

Not Currently. Because of the way the thermostat sets heat and cool set points, I created separate items and HTTP calls/posts. So, I am thinking I can make the appropriate item visible based on the current cooling/heating mode and a rule. I’m still learning here… (this was my first real attempt at configuring something in OpenHab)

I’m in Texas and so haven’t needed heat yet this year. I figure I have a couple months left to figure it out :smile:

0 Likes

(Scot) #12

Worked thru the examples provided and am able to retrieve/display the needed information.

Next is to activate the switches and the ability to adjust the temperature.

Also shown here is the “Target Temperature” which I don’t have working yet. That will replace the separate heating/cooling temperatures. I’ve created a rule based on current mode and am trying to load the current value into a string to be displayed, but that’s a question for another day…

Thanks for your help!!!

1 Like

(Scot) #13

david - can you please share how you’re setting the temp or changing the system mode from heat to cool? I have an open question Rule executes but doesn’t work where my rules look like they are executing properly, but the thermostat isn’t updating.

Thanks

Scot

0 Likes

(david) #14

Here are my rules. I am using HTTP POST and not curt.

var String output

rule "Set Upstairs Mode"
when
        Item SF_HVAC_Mode received command
then
        output = sendHttpPostRequest("http://192.168.1.11:80/tstat", "application/json", '{"tmode":' + receivedCommand + '}')
        logInfo("HVAC","HVAC Command sent - output: "+output)

end

rule "Set Coool SetPoint"
when
        Item SF_HVAC_Cool_SP received command
then
        output = sendHttpPostRequest("http://192.168.1.11:80/tstat", "application/json", '{"it_cool":' + receivedCommand + '}')
        logInfo("HVAC","HVAC Command sent - output: "+output)

end

rule "Set FAn Mode"
when
        Item SF_HVAC_FanMode received command
then
        output = sendHttpPostRequest("http://192.168.1.11:80/tstat/fmode", "application/json", '{"fmode":' + receivedCommand + '}')
        logInfo("HVAC","HVAC Command sent - output: "+output)

end
0 Likes

Rule executes but doesn't work
(Scot) #15

Thanks for the info on how you’re sending the Post commands.

fyi - I did work thru yesterday on how to combine the heat/cool targets and make a common setpoint.

There are 3 items:

Number Tstat_SetpointH “Set Heat Temperature [%.1f °F]” { http="<[tstat:60000:JSONPATH($.t_heat)]" }
Number Tstat_SetpointC “Set A/C Temperature [%.1f °F]” { http="<[tstat:60000:JSONPATH($.t_cool)]" }
Number Tstat_Setpoint “Set Temperature [%.1f °F]”

And then a rule that populates the control you see with either the heat or cool target based on the current mode.

// Get Current Heat/AC Target Temperature - load Setpoint
rule “New Target Temperature”
when
Item Tstat_mode received update
then
if (Tstat_mode.state == 1) {
Tstat_Setpoint.state = Tstat_SetpointH.state
}
if (Tstat_mode.state == 2) {
Tstat_Setpoint.state = Tstat_SetpointC.state
}
end

And then a rule that updates the thermostat:

// Set Temperature
rule “Set Temperature Target”
when
Item Tstat_Setpoint received command
then
if (Tstat_mode.state == 1) {
// command line: curl -d ‘{“a_heat”:66}’ http://192.168.224.50/tstat
executeCommandLine(“curl@@-d@@{“a_heat”:” + Tstat_Setpoint.state + “}@@http://192.168.224.50/tstat”)
}
if (Tstat_mode.state == 2) {
// command line: curl -d ‘{“a_cool”:66}’ http://192.168.224.50/tstat
executeCommandLine(“curl@@-d@@{“a_cool”:” + Tstat_Setpoint.state + “}@@http://192.168.224.50/tstat”)
}
end

And it looks like this:

0 Likes

(John Cocula) #16

Have a look at this example ecobee.rules for how I thought to have a single setpoint that dispatches its command to the proper heat or cool setpoint, depending on the current HVAC mode.

0 Likes

(Nicola Reina) #17

Hello
I have been reading this post because it does someting very similar to what I need.
I have an heatmiser wifi thermostat and can monitor and control it via a perl script.
I get status in json format and should be able to read it.
Unfortunately I can’t
I suspect this is due to the format of the first key of the json that is an ip adess and so I am not able to use it in the item definiition:

my item:
Number HeatmiserTemperatura “Temperatura [%f]” (PianoTerra,PianoTerra_Salone,Riscaldamento) { http="<[heatmiser:JSONPATH($.192.168.2.251.heating.target)]"

from openhab.log:
2015-12-19 23:48:54.401 [WARN ] [h.i.HttpGenericBindingProvider] - bindingConfig is NULL (item=HeatmiserTemperatura (Type=NumberItem, State=Uninitialized)) -> process bindingConfig aborted!

removing the \ in the item as in:
Number HeatmiserTemperatura “Temperatura [%f]” (PianoTerra,PianoTerra_Salone,Riscaldamento) { http="<[heatmiser:JSONPATH($.192.168.2.251.heating.target)]"

I get:
2015-12-20 00:17:25.216 [ERROR] [i.internal.GenericItemProvider] - Binding configuration of type ‘http’ of item ‘HeatmiserTemperatura‘ could not be parsed correctly.
org.openhab.model.item.binding.BindingConfigParseException: bindingConfig ‘heatmiser:JSONPATH($.192.168.2.251.heating.target)’ doesn’t represent a valid in-binding-configuration. A valid configuration is matched by the RegExp ‘(.?)({.})?:(?!//)(\d*):(.*)’

my http binding config:

configuration of the first cache item

http:heatmiser.url=http://192.168.2.239/cgi-bin/heatmiser/heatmiser_json.pl
http:heatmiser.updateInterval=60000

the json:
{
“192.168.2.251” : {
“comfort” : [
[
{
“target” : 22,
“time” : “06:30:00”
},
{
“target” : 19,
“time” : “08:30:00”
},
{
“target” : 23,
“time” : “12:30:00”
},
{
“target” : 22,
“time” : “23:00:00”
}
],
[
{
“target” : 22,
“time” : “07:30:00”
},
{
“target” : 20,
“time” : “23:30:00”
}
]
],
“config” : {
“caloffset” : 0,
“locklimit” : 0,
“optimumstart” : 0,
“outputdelay” : 0,
“progmode” : “5/2”,
“sensor” : “internal”,
“switchdiff” : 1,
“units” : “C”
},
“dcblength” : 72,
“enabled” : 1,
“errorcode” : null,
“frostprotect” : {
“enabled” : 1,
“target” : 12
},
“heating” : {
“hold” : 0,
“on” : 1,
“target” : 23
},
“holiday” : {
“enabled” : 0,
“time” : “2015-12-19 23:19:00”
},
“keylock” : 0,
“product” : {
“model” : “PRT”,
“vendor” : “Heatmiser”,
“version” : 1.9
},
“rateofchange” : 20,
“runmode” : “heating”,
“temperature” : {
“floor” : null,
“internal” : 22.1,
“remote” : null
},
“time” : “2015-12-19 23:19:02”
}
}

tx for your help!

0 Likes

(John Cocula) #18

Your item is missing the refresh time. It should be more like

Number  HeatmiserTemperatura    "Temperatura [%f]"         (PianoTerra,PianoTerra_Salone,Riscaldamento)            { http="<[heatmiser:60000:JSONPATH($['192.168.2.251'].heating.target)]"
0 Likes

(Nicola Reina) #19

TX.
Great stuff the community and osgi.
I edited the item file
as in
Number HeatmiserTemperatura “Temperatura [%f]” (PianoTerra,PianoTerra_Salone,Riscaldamento) { http="<[heatmiser:JSONPATH($.[‘192.168.2.239’].heating.target)]" }

but have:

2015-12-20 00:33:57.289 [ERROR] [i.internal.GenericItemProvider] - Binding configuration of type ‘http’ of item ‘HeatmiserTemperatura‘ could not be parsed correctly.
org.openhab.model.item.binding.BindingConfigParseException: bindingConfig ‘heatmiser:JSONPATH($.[‘192.168.2.239’].heating.target)’ doesn’t represent a valid in-binding-configuration. A valid configuration is matched by the RegExp ‘(.?)({.})?:(?!//)(\d*):(.*)’

tx for your help

0 Likes

(Nicola Reina) #20

oops some ip are wrong… hold on

0 Likes