How to create a rule for a temp sensor

Hi All

i have the following item which is a sonoff TH16 (Temp sensor and relay switch)

Number TempSensorCabin "Cabin  [%.1f °C]" <temperature> { mqtt=">[broker:cmnd/sonoff-30/POWER:command:OFF:0],>[broker:cmnd/sonoff-30/POWER:command:ON:1],<[broker:tele/sonoff-30/SENSOR:state:JSONPATH($.AM2301.Temperature)]" }
Number HumiditySensorCabin "Cabin [%.1f ]" <humidity> { mqtt=">[broker:cmnd/sonoff-30/POWER:command:OFF:0],>[broker:cmnd/sonoff-30/POWER:command:ON:1],<[broker:tele/sonoff-30/SENSOR:state:JSONPATH($.AM2301.Humidity)]" }

I would like to turn the relay on if the temp is <10 and turn off when greater than 15, does anyone have a simple rule to do this.

Thanks in advance

What you have to do:

  1. add the Switch for your TH16 as itemtype Switch
  2. add a proxy item for “relay ON/OFF”
  3. add a rule to turn the proxy item ON if temp <10 and to turn it OFF if temp >15
  4. add another rule to set your new TH16-switch item accordingly to that proxy item

why?
presently you’re using “TempSensorCabin” for two purposes “Switch” and “Temperature” (and “HumiditySensorCabin” also) - this won’t work - you have to split the items for their purpose: Switch for ON/OFF, Number for Temperature or Humidity.

Thanks for the explanation, it sounds good but over my head, is there any documentation that to things like “proxy items”, or even better is there a tutorial for anything similar to what i want to do. Thanks Steve

A proxy item is an item without direct connection to hardware, just used to trigger a rule. This rule then sends the necessary commands to perform the operation to the hardware bound items.

first of all, did you read the introduction of openHAB:
https://docs.openhab.org/concepts/index.html

There’s an explanation on all the stuff you can configure within openHAB - please read especially the part on items. In short:

Items represent capabilities that can be used by applications, either in user interfaces or in automation logic. Items have a State and they may receive commands.

So, that means, for every aspect (even if there are multiple ones in one device) you should address that aspect as an distinct item.
With that in mind, your TH16 has at least three items:

  • Switch on/off
  • temperature
  • humidity
    There are plenty more, as you flashed Tasmota.

So, as you have a Sonoff device running Tasmota, have a look on the Tasmota Wiki:

There’s a whole lot of examples for understanding how Tasmota devices integrate with openHAB.

After that, you can have a look on some rules and discussions on it on the forum, I recommend the Design Pattern tuturials:
https://community.openhab.org/search?q=design%20pattern

And now to your other question: a “Proxy item” is just a term for an item, which has no relation to a binding, but represents either some state or some action or whatever you like. It doesn’t “do” something directly, but you can use its state for telling others to do something.
So, please have a look - and if you need further help, we’re here to assist you.

1 Like

What I think your looking for is a working example. Here’s a simple rule I have in place.

rule "Getting Cold Outside"

when 
	Item Weather_Current_Temperature received update

then
	if(Time_Of_Day.state == "NIGHT" && Weather_Current_Temperature.state < 9.0) {
		sendCommand(Landing_HRT4_ZW_Setpoint,20.0)
	} else if(Time_Of_Day.state == "NIGHT" && Weather_Current_Temperature.state < 5.0) {
		sendCommand(Landing_HRT4_ZW_Setpoint,21.0)
	} else if(Time_Of_Day.state == "NIGHT" && Weather_Current_Temperature.state < 1.0) {
		sendCommand(Landing_HRT4_ZW_Setpoint,22.0)
	}
end

What my rule does is look at the temperature reported by WUnderground and changed the heating set point of my thermostat. Hopefully this gives you a pointer at least.

2 Likes

Thanks I will digest that when the kids have gone to bed lol

Garry
I am wondering what device you are controlling are they radiator valves ?

I guess, that’s the RTRs (Room Temperature Controllers). This is half way to your use case.
The (non-OH2) heating logic will take the setpoint and do its magic.

What you need is to take the temp and turn your relay on and off accordingly. As I know how it is with Kids running around:

Switch SwitchSensorCabin "Cabin Switch"   <switch>      { mqtt=">[broker:cmnd/sonoff-30/POWER:command:OFF:0],>[broker:cmnd/sonoff-30/POWER:command:ON:1]" }

Number TempSensorCabin "Cabin  [%.1f °C]" <temperature> { mqtt="<[broker:tele/sonoff-30/SENSOR:state:JSONPATH($.AM2301.Temperature)]" }
Number HumiditySensorCabin "Cabin [%.1f ]" <humidity> { mqtt="<[broker:tele/sonoff-30/SENSOR:state:JSONPATH($.AM2301.Humidity)]" }
rule "Cabin getting cold"
when 
	Item TempSensorCabin changed
then
	if (TempSensorCabin.state < 10) {
		SwitchSensorCabin.sendCommand(ON)
	} 
	if (TempSensorCabin.state > 15) {
		SwitchSensorCabin.sendCommand(OFF)
	} 
end

If your use case doesn’t require to do anything, if the temperature oscilates between 10 and 15, then you can forget the proxy item. If you need some action for continuing degrees in between both, you could then play around with that proxy item a bit.
What happens now: if temp <10 the Sonoff will turn ON and if temp >15 it will turn OFF.

2 Likes

You seem to be familiar with the SONOFF and Tasmota, I dont suppose you know why the humidity is always 99.9% (not just in Openhab but in the devices control panel as well)

I’m sorry, unfortunately I don’t have a TH16! :wink: I was about to buy one - but it only had 10A as I needed one for my 2000W heating. That was a bit too risky for me, so I used a POW again - and placed a onewire sensor instead! :wink:
My guess is either you have to calibrate or configure something - or the humidity sensor is broken…

I have a few (I sell them), I looks like the humidity side of the TH10 is dodgy as the sensor is OK

I’m using Danfoss LC13 TRV’s on each of my radiators. They seem to be working well. Having local controls means the WAF is very high.

Fantastic example rule. Was just wondering if you could implement a variable Setpoint value into this rule? I.e if the set point value for the heating system in my house was 21. the rule would turn on and off a trv valve on my radiator in a specific room depending on the temp sensor in said room and if the set point was changed to say 25 the rule would also adapt alongside the Setpoint?