How to return current temp from my thermostat?

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

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.

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

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:

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

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

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

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:

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.

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!

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)]"

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

oops some ip are wrong… hold on

nope:
2015-12-20 00:42:18.454 [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*):(.*)’

sorry: you wrote: the refressh time!
going…

G R E A T!
I was fighting with the item since 4 hours…

Thanks.
Now that I got it I will finish a complete setup for Heatmiser Wifi and publish for the community.

cheers

1 Like

I am trying to get this to work properly in a more linear way…
currently I call an http and get back a json from the apache server.
All of this is sitting on the same pi.
The server to give back the json calls some perl scripts via cgi.
To get the status of all the n parameters of the thermostat I would do n calls to the server.
Not nice.

So, I am trying to do it more directly by calling the perl script just once from my rules but it does not seem to work.

Here is the piece of code:
rule “Initialization”
when
System started
then

var String status = executeCommandLine("/home/pi/heatmiser-wifi-read-only/openhabscripts/hw_status.sh")
var String result = transform(“JSONPATH”, “$.[‘192.168.2.251’].heating.target”, status)

where hw_status.sh is the perl script returning this Json
{
“192.168.2.251” : {
“comfort” : [
[
{
“target” : 22,
“time” : “06:30:00”
},
{
“target” : 22,
“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” : 0,
“target” : 23
},
“holiday” : {
“enabled” : 0,
“time” : “2015-12-23 20:07:00”
},
“keylock” : 0,
“product” : {
“model” : “PRT”,
“vendor” : “Heatmiser”,
“version” : 1.9
},
“rateofchange” : 20,
“runmode” : “heating”,
“temperature” : {
“floor” : null,
“internal” : 22.5,
“remote” : null
},
“time” : “2015-12-23 20:07:05”
}
}

the log:

01:46:29.978 [INFO ] [g.openhab.io.net.exec.ExecUtil:66 ] - executed commandLine ‘/home/pi/heatmiser-wifi-read-only/openhabscripts/hw_status.sh’
01:46:30.141 [ERROR] [o.o.c.t.actions.Transformation:47 ] - Error executing the transformation ‘JSONPATH’: the given parameters ‘JSonPath’ and ‘source’ must not be null
01:46:30.290 [INFO ] [rg.openhab.model.script.result:53 ] - null
01:46:30.352 [INFO ] [g.openhab.io.net.exec.ExecUtil:66 ] - executed commandLine ‘/home/pi/heatmiser-wifi-read-only/openhabscripts/hw_status.sh’
01:46:30.402 [ERROR] [m.r.internal.engine.RuleEngine:278 ] - Error during the execution of startup rule ‘Initialization’: Cannot create a duplicate value ‘result’.
01:46:31.222 [D

So it seems that executecommandline 's result (status) is null.
If I execute by hand on the CLI it returns the JSON

Furhermore there’s another error “Cannot create a duplicate value ‘result’.”

Any help is appreciated as usual.

Cheers.

  1. Are you sure it’s not transform("JSONPATH", "$['192.168.2.251'].heating.target", status)?

  2. Also, rename your result variable to something else, in case there is already one in the namespace.

  3. The last question is if the user running the openHAB server has the permission to execute the hw_status.sh script.

the JSONPATH was wrong (I am still learning…).
I changed the var names to something unique
However the result is not chamged

11:16:08.085 [INFO ] [g.openhab.io.net.exec.ExecUtil:66 ] - executed commandLine ‘/home/pi/heatmiser-wifi-read-only/openhabscripts/hw_status.sh’
11:16:08.215 [ERROR] [o.o.c.t.actions.Transformation:47 ] - Error executing the transformation ‘JSONPATH’: the given parameters ‘JSonPath’ and ‘source’ must not be null
11:16:08.297 [INFO ] [g.openhab.io.net.exec.ExecUtil:66 ] - executed commandLine ‘/home/pi/heatmiser-wifi-read-only/openhabscripts/hw_status.sh’
11:16:08.440 [ERROR] [o.o.c.t.actions.Transformation:47 ] - Error executing the transformation ‘JSONPATH’: the given parameters ‘JSonPath’ and ‘source’ must not be null
11:16:08.580 [ERROR] [o.o.c.t.actions.Transformation:47 ] - Error executing the transformation ‘JSONPATH’: the given parameters ‘JSonPath’ and ‘source’ must not be null
11:16:08.851 [WARN ] [.c.i.events.EventPublisherImpl:80 ] - given new state is NULL, couldn’t post update for ‘HW_RoomTemperature’

I am also trying to output it via
logInfo(“HM”,status)
logInfo(“HM”,result)

however in the log (I am starting in start_debug) I cannot see anything.

update:

Nothing to do…

this is my rule:
rule “Initialization”
when
System started
then
var String sta = executeCommandLine("/home/pi/heatmiser-wifi-read-only/openhabscripts/hw_status.sh")
logInfo(“Testing”, “executecommandline”)
logInfo(“Testing”, sta)
postUpdate(dummy , sta)
var String res = transform(“JSONPATH”, “$.[‘192.168.2.251’].heating.target”, sta)
logInfo(“Testing”, “json”)
logInfo(“Testing”, res)
postUpdate(dummy , sta)

this is the log:
pi@openhab /var/opt/openhab/logs $ tail openhab.log
2015-12-30 10:22:47.373 [INFO ] [c.internal.ModelRepositoryImpl] - Refreshing model ‘hm.rules’
2015-12-30 10:22:47.575 [INFO ] [g.openhab.io.net.exec.ExecUtil] - executed commandLine ‘/home/pi/heatmiser-wifi-read-only/openhabscripts/hw_status.sh’
2015-12-30 10:22:47.612 [INFO ] [g.openhab.model.script.Testing] - executecommandline
2015-12-30 10:22:47.658 [INFO ] [g.openhab.model.script.Testing] - null
2015-12-30 10:22:47.774 [ERROR] [o.o.c.t.actions.Transformation] - Error executing the transformation ‘JSONPATH’: the given parameters ‘JSonPath’ and ‘source’ must not be null
2015-12-30 10:22:47.810 [INFO ] [g.openhab.model.script.Testing] - json
2015-12-30 10:22:47.855 [INFO ] [g.openhab.model.script.Testing] - null
2015-12-30 10:22:47.942 [INFO ] [g.openhab.io.net.exec.ExecUtil] - executed commandLine ‘/home/pi/heatmiser-wifi-read-only/openhabscripts/hw_status.sh’
2015-12-30 10:22:48.015 [ERROR] [o.o.c.t.actions.Transformation] - Error executing the transformation ‘JSONPATH’: the given parameters ‘JSonPath’ and ‘source’ must not be null
2015-12-30 10:22:48.065 [ERROR] [o.o.c.t.actions.Transformation] - Error executing the transformation ‘JSONPATH’: the given parameters ‘JSonPath’ and ‘source’ must not be null

files are ownership of pi user and group.
openhab is run as root so…

I even changed the script to printout directly a JSON string:

more /home/pi/heatmiser-wifi-read-only/openhabscripts/t

where t is the output of the heatmiser_json_oh.pl script put on one line:

{ “192.168.2.251” : { “comfort” : [ [ { “target” : 22, “time” : “06:30:00” }, { “target” : 22, “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” : 0, “target” : 22 }, “holiday” : { “enabled” : 0, “time” : “2015-12-30 09:59:00” }, “keylock” : 0, “product” : { “model” : “PRT”, “vendor” : “Heatmiser”, “version” : 1.9 }, “rateofchange” : 20, “runmode” : “heating”, “temperature” : { “floor” : null, “internal” : 22, “remote” : null }, “time” : “2015-12-30 09:59:57” } }

it is clear to me that although the executecommandline is logged as executed either the output is not getting passed to the sta String variable or there is no output from the command as the sta variable is null.

but… why

Ok … Finally I found out.
I share for all : it was due to the executeCommandLine returing before getting the answer from the script.
Adding a timeout solved.