Question on managing events outside OpenHab GUI

Dear community,
thanks for the continued support, I have gotten quite far with my OpenHAB2 installation. But here is one thing I cannot get my head around:

I have a heating system (controme) that provides access via an API.

  • I have set up a rule that updates values (current_temp, target_temp) every 10min.
  • In my sidemap I use target_temp with a setpoint
  • I have another rule that sends the new value to the heating device when there is a change
  • However, I don’t want to have this rule called when the heating system sends updates because it is creating unnecessary traffic on that API (and performance is low)

How could I do this that the second rule is only called if changes are made in the OpenHAB GUI via the setpoint?

Code below

Rules

rule "Get Temperature"
    when 
        Time cron "* /10 * * * ?"
    then    {   
        var String json = sendHttpGetRequest("http://192.168.188.57/get/json/v1/1/temps",60000)
        var Number current_temp = transform("JSONPATH", "$.[0].raeume[0].temperatur", json) 
        var Number target_temp = transform("JSONPATH", "$.[0].raeume[0].solltemperatur", json) 
        eg_kitchen_temp.sendCommand(DecimalType.valueOf(current_temp))
        eg_kitchen_target_temp.sendCommand(DecimalType.valueOf(target_temp))
end

rule "change kitchen temp"
    when
        Item eg_kitchen_target_temp received command 
    then
	    var Number x = (eg_kitchen_target_temp.state as DecimalType).floatValue 
	    executeCommandLine(String::format("sh /etc/openhab2/scripts/setRoomTemp.sh 1 %.1f", x))		
end

and in my sitemap

				Frame {
					Setpoint item=eg_kitchen_target_temp label="Solltemperatur [%.1f \u00B0C]" step=0.5 minValue=16 maxValue=26 
				}

Over all your approach won’t really fix your problem because your rule. Your first rule only runs once every ten minutes. If calling the API every ten minutes if causing performance problems you have bigger problems and making the changes you are asking about will not change the performance.

First, keep track of the state of your heater and only call the script when the current temp changes and the heater needs to change state. For example, if the current temp is below the target temp but the heater is already on, don’t call the script.

Secondly, trigger your second rule using changed, not received command. You don’t need to run the rule of the temp hasn’t changed.

Thirdly, only postUpdate or sendCommand to the temp items when the new value you got from the heater is different from the current value by a significant amount.

This would be the proper way to implement something like this.

If you use a slider instead of a setpoint you can configure how often the item here a new value while changing it on the sitemap.

Finally, you can use a proxy item to put on your sitemap and trigger the rule instead of your existing target temp item to tell the difference between a change from the sitemap versus the API. You could also use a timer and only call the script a second or two after the last change to the target temp.

Thanks Rich for the ideas. I will give it another try in thinking it through.

Issue is that the entire intelligence of the heating control is in the Controme box and I just want to use Openhab2 as the GUI for changing the settings of target temperature. The system itself does a lot of optimization in the background (e.g., based on weather) and value change often. I need to decouple this from the user input in some way.

Thanks,
Matthias

My best does the same.

I don’t understand what you mean by decouple it from the user input. When you change the target temp (i.e. change the target temp) you must send it to the device. There is no way around this.

Hello Matthias

I hope you got your question concerning setting temperatures through the Controme API is settled by now. I stumbled upon your Topic here, as I’m myself looking for answers on how to provide sensor values into the controme system via their API in this threat.

However concerning your question: - there is a nice tool by @BoBiene linked at the end of this threat https://community.openhab.org/t/controme-smart-heat/26797/5 , which almost automatically does what you want. (almost, as there is an easily fixable issue in the .item file which is created). Have a look

For setting the desired room temperature (Soll) the tool creates a rule file in which via commandline a Curl command is send to the RestAPI of the controme server.

The syntax is like this:

executeCommandLine("curl -X POST -F user=USERNAME -F password=PASSWORD -F soll="+receivedCommand.toString+" http://MINI-IP-ADRESS//set/json/v1/HAUSID/soll/ROOM-ID/")

The rules are connected to “Dummie_Items” (YOUR_SOLL_ITEM), which you can change e.g. with a slider in a sitemap.

the related rules read than e.g.:

rule "Set SOLL Temp" 
when Item YOUR_SOLL_ITEM received command 
then
executeCommandLine("curl -X POST -F user=USERNAME -F password=PASSWORD -F soll="+receivedCommand.toString+" http://192.168.10.233//set/json/v1/2/soll/3/")
end